Update Go and vendor dependencies
This commit is contained in:
+24
-12
@@ -155,7 +155,6 @@ func main() {
|
||||
// Create SSA-form program representation
|
||||
// and find main packages.
|
||||
prog, pkgs := ssautil.AllPackages(initial, ssa.InstantiateGenerics)
|
||||
prog.Build()
|
||||
|
||||
mains := ssautil.MainPackages(pkgs)
|
||||
if len(mains) == 0 {
|
||||
@@ -206,6 +205,18 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
// Build function bodies only now: nothing below uses the
|
||||
// syntax or type information of initial, so it can be
|
||||
// freed as each package is built. Everything after this
|
||||
// point works from the SSA program and its file set alone.
|
||||
initial, pkgs = nil, nil // aid GC
|
||||
prog.Build()
|
||||
|
||||
// -- types.Info is now unused and may be reclaimed by GC --
|
||||
|
||||
fset := prog.Fset
|
||||
prog = nil
|
||||
|
||||
// Compute the reachabilty from main.
|
||||
// (Build a call graph only for -whylive.)
|
||||
res := rta.Analyze(roots, *whyLiveFlag != "")
|
||||
@@ -224,7 +235,7 @@ func main() {
|
||||
reachablePosn := make(map[token.Position]bool)
|
||||
for fn := range res.Reachable {
|
||||
if fn.Pos().IsValid() || fn.Name() == "init" {
|
||||
reachablePosn[prog.Fset.Position(fn.Pos())] = true
|
||||
reachablePosn[fset.Position(fn.Pos())] = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +267,7 @@ func main() {
|
||||
|
||||
// Opt: remove the unreachable ones.
|
||||
for fn := range targets {
|
||||
if !reachablePosn[prog.Fset.Position(fn.Pos())] {
|
||||
if !reachablePosn[fset.Position(fn.Pos())] {
|
||||
delete(targets, fn)
|
||||
}
|
||||
}
|
||||
@@ -283,7 +294,7 @@ func main() {
|
||||
edges = append(edges, jsonEdge{
|
||||
Initial: cond(len(edges) == 0, prettyName(edge.Caller.Func, true), ""),
|
||||
Kind: cond(isStaticCall(edge), "static", "dynamic"),
|
||||
Position: toJSONPosition(prog.Fset.Position(edge.Pos())),
|
||||
Position: toJSONPosition(fset.Position(edge.Pos())),
|
||||
Callee: prettyName(edge.Callee.Func, true),
|
||||
})
|
||||
}
|
||||
@@ -298,7 +309,7 @@ func main() {
|
||||
// Group unreachable functions by package path.
|
||||
byPkgPath := make(map[string]map[*ssa.Function]bool)
|
||||
for _, fn := range sourceFuncs {
|
||||
posn := prog.Fset.Position(fn.Pos())
|
||||
posn := fset.Position(fn.Pos())
|
||||
|
||||
if !reachablePosn[posn] {
|
||||
reachablePosn[posn] = true // suppress dups with same pos
|
||||
@@ -328,8 +339,8 @@ func main() {
|
||||
// together better than sorting.
|
||||
fns := slices.Collect(maps.Keys(m))
|
||||
sort.Slice(fns, func(i, j int) bool {
|
||||
xposn := prog.Fset.Position(fns[i].Pos())
|
||||
yposn := prog.Fset.Position(fns[j].Pos())
|
||||
xposn := fset.Position(fns[i].Pos())
|
||||
yposn := fset.Position(fns[j].Pos())
|
||||
if xposn.Filename != yposn.Filename {
|
||||
return xposn.Filename < yposn.Filename
|
||||
}
|
||||
@@ -338,7 +349,7 @@ func main() {
|
||||
|
||||
var functions []jsonFunction
|
||||
for _, fn := range fns {
|
||||
posn := prog.Fset.Position(fn.Pos())
|
||||
posn := fset.Position(fn.Pos())
|
||||
|
||||
// Without -generated, skip functions declared in
|
||||
// generated Go files.
|
||||
@@ -404,10 +415,11 @@ func prettyName(fn *ssa.Function, qualified bool) string {
|
||||
}
|
||||
|
||||
// method receiver?
|
||||
if recv := fn.Signature.Recv(); recv != nil {
|
||||
_, named := typesinternal.ReceiverNamed(recv)
|
||||
buf.WriteString(named.Obj().Name())
|
||||
buf.WriteByte('.')
|
||||
if obj, ok := fn.Object().(*types.Func); ok {
|
||||
if _, named := typesinternal.RecvBase(obj); named != nil {
|
||||
buf.WriteString(named.Obj().Name())
|
||||
buf.WriteByte('.')
|
||||
}
|
||||
}
|
||||
|
||||
// function/method name
|
||||
|
||||
+13
-8
@@ -12,6 +12,7 @@ import (
|
||||
"fmt"
|
||||
"go/scanner"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -19,6 +20,7 @@ import (
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/telemetry/counter"
|
||||
"golang.org/x/tools/internal/gocommand"
|
||||
@@ -67,10 +69,10 @@ func usage() {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func isGoFile(f os.FileInfo) bool {
|
||||
func isGoFile(d fs.DirEntry) bool {
|
||||
// ignore non-Go files
|
||||
name := f.Name()
|
||||
return !f.IsDir() && !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go")
|
||||
name := d.Name()
|
||||
return !d.IsDir() && !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go")
|
||||
}
|
||||
|
||||
// argumentType is which mode goimports was invoked as.
|
||||
@@ -184,8 +186,8 @@ func processFile(filename string, in io.Reader, out io.Writer, argType argumentT
|
||||
return err
|
||||
}
|
||||
|
||||
func visitFile(path string, f os.FileInfo, err error) error {
|
||||
if err == nil && isGoFile(f) {
|
||||
func visitFile(path string, d fs.DirEntry, err error) error {
|
||||
if err == nil && isGoFile(d) {
|
||||
err = processFile(path, nil, os.Stdout, multipleArg)
|
||||
}
|
||||
if err != nil {
|
||||
@@ -195,11 +197,12 @@ func visitFile(path string, f os.FileInfo, err error) error {
|
||||
}
|
||||
|
||||
func walkDir(path string) {
|
||||
filepath.Walk(path, visitFile)
|
||||
filepath.WalkDir(path, visitFile)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// is anyone using this command?
|
||||
// Measure how many people still use goimports.
|
||||
// (See https://go.dev/issue/78671 for one.)
|
||||
counter.Open()
|
||||
counter.Inc("tools/cmd:goimports")
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
@@ -208,7 +211,9 @@ func main() {
|
||||
// so that it can use defer and have them
|
||||
// run before the exit.
|
||||
gofmtMain()
|
||||
os.Exit(exitCode)
|
||||
if !testing.Testing() {
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
// parseFlags parses command line flags and returns the paths to process.
|
||||
|
||||
Reference in New Issue
Block a user