diff --git a/go/analysis/unitchecker/unitchecker.go b/go/analysis/unitchecker/unitchecker.go index 71ebbfaef15..2301ccfc0e4 100644 --- a/go/analysis/unitchecker/unitchecker.go +++ b/go/analysis/unitchecker/unitchecker.go @@ -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. @@ -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 { diff --git a/go/loader/loader.go b/go/loader/loader.go index 013c0f505bb..5a260e0d880 100644 --- a/go/loader/loader.go +++ b/go/loader/loader.go @@ -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 @@ -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 diff --git a/go/packages/packages.go b/go/packages/packages.go index f227f1bab10..fc6ac1e0671 100644 --- a/go/packages/packages.go +++ b/go/packages/packages.go @@ -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. @@ -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) { diff --git a/go/ssa/ssautil/load.go b/go/ssa/ssautil/load.go index 51fba054541..c64b03f177f 100644 --- a/go/ssa/ssautil/load.go +++ b/go/ssa/ssautil/load.go @@ -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. @@ -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 } diff --git a/go/types/typeutil/callee_test.go b/go/types/typeutil/callee_test.go index faee0f88721..1d48bc743a9 100644 --- a/go/types/typeutil/callee_test.go +++ b/go/types/typeutil/callee_test.go @@ -14,7 +14,6 @@ import ( "testing" "golang.org/x/tools/go/types/typeutil" - "golang.org/x/tools/internal/versions" ) func TestStaticCallee(t *testing.T) { @@ -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 { diff --git a/gopls/internal/analysis/infertypeargs/infertypeargs.go b/gopls/internal/analysis/infertypeargs/infertypeargs.go index 9a514ad620c..0ce43e67079 100644 --- a/gopls/internal/analysis/infertypeargs/infertypeargs.go +++ b/gopls/internal/analysis/infertypeargs/infertypeargs.go @@ -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 @@ -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 diff --git a/gopls/internal/cache/analysis.go b/gopls/internal/cache/analysis.go index 9debc609048..b18c30fd7ee 100644 --- a/gopls/internal/cache/analysis.go +++ b/gopls/internal/cache/analysis.go @@ -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" ) /* @@ -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" { diff --git a/gopls/internal/cache/check.go b/gopls/internal/cache/check.go index 08d57f4e657..f93a8ab42ad 100644 --- a/gopls/internal/cache/check.go +++ b/gopls/internal/cache/check.go @@ -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. diff --git a/gopls/internal/golang/change_signature.go b/gopls/internal/golang/change_signature.go index 72cbe4c2d90..41c56ba6c2c 100644 --- a/gopls/internal/golang/change_signature.go +++ b/gopls/internal/golang/change_signature.go @@ -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 @@ -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() { diff --git a/gopls/internal/golang/identifier_test.go b/gopls/internal/golang/identifier_test.go index d78d8fe99f5..8206d8731ae 100644 --- a/gopls/internal/golang/identifier_test.go +++ b/gopls/internal/golang/identifier_test.go @@ -11,8 +11,6 @@ import ( "go/token" "go/types" "testing" - - "golang.org/x/tools/internal/versions" ) func TestSearchForEnclosing(t *testing.T) { @@ -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 } diff --git a/internal/versions/types.go b/internal/versions/types.go index f0bb0d15f03..0fc10ce4eb5 100644 --- a/internal/versions/types.go +++ b/internal/versions/types.go @@ -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) -} diff --git a/internal/versions/types_test.go b/internal/versions/types_test.go index 2cd145d2f20..bf459a5829c 100644 --- a/internal/versions/types_test.go +++ b/internal/versions/types_test.go @@ -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 } diff --git a/internal/versions/versions_test.go b/internal/versions/versions_test.go index 0886f8c80be..2599b8f26e5 100644 --- a/internal/versions/versions_test.go +++ b/internal/versions/versions_test.go @@ -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 { diff --git a/refactor/satisfy/find_test.go b/refactor/satisfy/find_test.go index daa8b219ef2..cb755601c78 100644 --- a/refactor/satisfy/find_test.go +++ b/refactor/satisfy/find_test.go @@ -15,7 +15,6 @@ import ( "sort" "testing" - "golang.org/x/tools/internal/versions" "golang.org/x/tools/refactor/satisfy" ) @@ -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(), }