Skip to content

Commit

Permalink
internal/versions: remove InitFileVersions
Browse files Browse the repository at this point in the history
InitFileVersions is not longer conditionally needed at x/tools
supports Go >= 1.22.

Change-Id: I5df1b46463d23acda569e1378027d542ac749f93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/617637
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
Commit-Queue: Tim King <[email protected]>
  • Loading branch information
timothy-king authored and Go LUCI committed Oct 7, 2024
1 parent de11c55 commit a30b207
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 98 deletions.
17 changes: 8 additions & 9 deletions go/analysis/unitchecker/unitchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import (
"golang.org/x/tools/go/analysis/internal/analysisflags"
"golang.org/x/tools/internal/analysisinternal"
"golang.org/x/tools/internal/facts"
"golang.org/x/tools/internal/versions"
)

// A Config describes a compilation unit to be analyzed.
Expand Down Expand Up @@ -257,15 +256,15 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
GoVersion: cfg.GoVersion,
}
info := &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
FileVersions: make(map[*ast.File]string),
}
versions.InitFileVersions(info)

pkg, err := tc.Check(cfg.ImportPath, fset, files, info)
if err != nil {
Expand Down
17 changes: 8 additions & 9 deletions go/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/internal/cgo"
"golang.org/x/tools/internal/versions"
)

var ignoreVendor build.ImportMode
Expand Down Expand Up @@ -1029,18 +1028,18 @@ func (imp *importer) newPackageInfo(path, dir string) *PackageInfo {
info := &PackageInfo{
Pkg: pkg,
Info: types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
FileVersions: make(map[*ast.File]string),
},
errorFunc: imp.conf.TypeChecker.Error,
dir: dir,
}
versions.InitFileVersions(&info.Info)

// Copy the types.Config so we can vary it across PackageInfos.
tc := imp.conf.TypeChecker
Expand Down
19 changes: 9 additions & 10 deletions go/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"golang.org/x/tools/internal/gocommand"
"golang.org/x/tools/internal/packagesinternal"
"golang.org/x/tools/internal/typesinternal"
"golang.org/x/tools/internal/versions"
)

// A LoadMode controls the amount of detail to return when loading.
Expand Down Expand Up @@ -1171,15 +1170,15 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
}

lpkg.TypesInfo = &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
}
versions.InitFileVersions(lpkg.TypesInfo)
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
FileVersions: make(map[*ast.File]string),
}
lpkg.TypesSizes = ld.sizes

importer := importerFunc(func(path string) (*types.Package, error) {
Expand Down
17 changes: 8 additions & 9 deletions go/ssa/ssautil/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/internal/versions"
)

// Packages creates an SSA program for a set of packages.
Expand Down Expand Up @@ -134,15 +133,15 @@ func BuildPackage(tc *types.Config, fset *token.FileSet, pkg *types.Package, fil
}

info := &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
FileVersions: make(map[*ast.File]string),
}
versions.InitFileVersions(info)
if err := types.NewChecker(tc, fset, pkg, info).Files(files); err != nil {
return nil, nil, err
}
Expand Down
9 changes: 4 additions & 5 deletions go/types/typeutil/callee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"testing"

"golang.org/x/tools/go/types/typeutil"
"golang.org/x/tools/internal/versions"
)

func TestStaticCallee(t *testing.T) {
Expand Down Expand Up @@ -122,11 +121,11 @@ func testStaticCallee(t *testing.T, contents []string) {
packages := make(map[string]*types.Package)
cfg := &types.Config{Importer: closure(packages)}
info := &types.Info{
Instances: make(map[*ast.Ident]types.Instance),
Uses: make(map[*ast.Ident]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Instances: make(map[*ast.Ident]types.Instance),
Uses: make(map[*ast.Ident]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
FileVersions: make(map[*ast.File]string),
}
versions.InitFileVersions(info)

var files []*ast.File
for i, content := range contents {
Expand Down
5 changes: 2 additions & 3 deletions gopls/internal/analysis/infertypeargs/infertypeargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/typeparams"
"golang.org/x/tools/internal/versions"
)

const Doc = `check for unnecessary type arguments in call expressions
Expand Down Expand Up @@ -91,9 +90,9 @@ func diagnose(fset *token.FileSet, inspect *inspector.Inspector, start, end toke
Rparen: call.Rparen,
}
info := &types.Info{
Instances: make(map[*ast.Ident]types.Instance),
Instances: make(map[*ast.Ident]types.Instance),
FileVersions: make(map[*ast.File]string),
}
versions.InitFileVersions(info)
if err := types.CheckExpr(fset, pkg, call.Pos(), newCall, info); err != nil {
// Most likely inference failed.
break
Expand Down
17 changes: 8 additions & 9 deletions gopls/internal/cache/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
"golang.org/x/tools/internal/facts"
"golang.org/x/tools/internal/gcimporter"
"golang.org/x/tools/internal/typesinternal"
"golang.org/x/tools/internal/versions"
)

/*
Expand Down Expand Up @@ -965,17 +964,17 @@ func (an *analysisNode) typeCheck(parsed []*parsego.File) *analysisPackage {
compiles: len(mp.Errors) == 0, // false => list error
types: types.NewPackage(string(mp.PkgPath), string(mp.Name)),
typesInfo: &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Implicits: make(map[ast.Node]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Scopes: make(map[ast.Node]*types.Scope),
Uses: make(map[*ast.Ident]types.Object),
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Implicits: make(map[ast.Node]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Scopes: make(map[ast.Node]*types.Scope),
Uses: make(map[*ast.Ident]types.Object),
FileVersions: make(map[*ast.File]string),
},
typesSizes: mp.TypesSizes,
}
versions.InitFileVersions(pkg.typesInfo)

// Unsafe has no syntax.
if mp.PkgPath == "unsafe" {
Expand Down
16 changes: 8 additions & 8 deletions gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -1544,16 +1544,16 @@ func (b *typeCheckBatch) checkPackage(ctx context.Context, ph *packageHandle) (*
types: types.NewPackage(string(inputs.pkgPath), string(inputs.name)),
typesSizes: inputs.sizes,
typesInfo: &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Scopes: make(map[ast.Node]*types.Scope),
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Scopes: make(map[ast.Node]*types.Scope),
FileVersions: make(map[*ast.File]string),
},
}
versions.InitFileVersions(pkg.typesInfo)

// Collect parsed files from the type check pass, capturing parse errors from
// compiled files.
Expand Down
17 changes: 8 additions & 9 deletions gopls/internal/golang/change_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"golang.org/x/tools/internal/refactor/inline"
"golang.org/x/tools/internal/tokeninternal"
"golang.org/x/tools/internal/typesinternal"
"golang.org/x/tools/internal/versions"
)

// RemoveUnusedParameter computes a refactoring to remove the parameter
Expand Down Expand Up @@ -482,15 +481,15 @@ func rewriteCalls(ctx context.Context, rw signatureRewrite) (map[protocol.Docume
func reTypeCheck(logf func(string, ...any), orig *cache.Package, fileMask map[protocol.DocumentURI]*ast.File, expectErrors bool) (*types.Package, *types.Info, error) {
pkg := types.NewPackage(string(orig.Metadata().PkgPath), string(orig.Metadata().Name))
info := &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Scopes: make(map[ast.Node]*types.Scope),
Instances: make(map[*ast.Ident]types.Instance),
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Scopes: make(map[ast.Node]*types.Scope),
Instances: make(map[*ast.Ident]types.Instance),
FileVersions: make(map[*ast.File]string),
}
versions.InitFileVersions(info)
{
var files []*ast.File
for _, pgf := range orig.CompiledGoFiles() {
Expand Down
16 changes: 7 additions & 9 deletions gopls/internal/golang/identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"go/token"
"go/types"
"testing"

"golang.org/x/tools/internal/versions"
)

func TestSearchForEnclosing(t *testing.T) {
Expand Down Expand Up @@ -95,13 +93,13 @@ func posAt(line, column int, fset *token.FileSet, fname string) token.Pos {
// newInfo returns a types.Info with all maps populated.
func newInfo() *types.Info {
info := &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Scopes: make(map[ast.Node]*types.Scope),
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Scopes: make(map[ast.Node]*types.Scope),
FileVersions: make(map[*ast.File]string),
}
versions.InitFileVersions(info)
return info
}
5 changes: 0 additions & 5 deletions internal/versions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,3 @@ func FileVersion(info *types.Info, file *ast.File) string {
// This would act as a max version on what a tool can support.
return Future
}

// InitFileVersions initializes info to record Go versions for Go files.
func InitFileVersions(info *types.Info) {
info.FileVersions = make(map[*ast.File]string)
}
5 changes: 3 additions & 2 deletions internal/versions/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ func typeCheck(fset *token.FileSet, files []*ast.File, goversion string) (*types
Importer: importer.Default(),
GoVersion: goversion,
}
info := types.Info{}
versions.InitFileVersions(&info)
info := types.Info{
FileVersions: make(map[*ast.File]string),
}
pkg, err := conf.Check("", fset, files, &info)
return pkg, &info, err
}
5 changes: 3 additions & 2 deletions internal/versions/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ func TestFileVersions(t *testing.T) {
{GoVersion: versions.Go1_22},
{}, // GoVersion is unset.
} {
info := &types.Info{}
versions.InitFileVersions(info)
info := &types.Info{
FileVersions: make(map[*ast.File]string),
}

_, err = conf.Check("P", fset, []*ast.File{f}, info)
if err != nil {
Expand Down
17 changes: 8 additions & 9 deletions refactor/satisfy/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"sort"
"testing"

"golang.org/x/tools/internal/versions"
"golang.org/x/tools/refactor/satisfy"
)

Expand Down Expand Up @@ -216,15 +215,15 @@ func constraints(t *testing.T, src string) []string {

// type-check
info := &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Implicits: make(map[ast.Node]types.Object),
Instances: make(map[*ast.Ident]types.Instance),
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
FileVersions: make(map[*ast.File]string),
}
versions.InitFileVersions(info)
conf := types.Config{
Importer: importer.Default(),
}
Expand Down

0 comments on commit a30b207

Please sign in to comment.