go/types, types2: move posVers field into group of package-specific fields (cleanup)

posVers exists once for an entire package. Move it into the group
of fields related to the entire package (and out from the group
of fields that are specific to each batch of files).

Change-Id: I40ea722578408bdf2b85db91b65680e720c0c502
Reviewed-on: https://go-review.googlesource.com/c/go/+/514998
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2023-08-01 15:48:17 -07:00 committed by Gopher Robot
parent a915b999c9
commit ce5e37ec21
2 changed files with 22 additions and 14 deletions

View File

@ -97,11 +97,12 @@ type Checker struct {
ctxt *Context // context for de-duplicating instances ctxt *Context // context for de-duplicating instances
pkg *Package pkg *Package
*Info *Info
version version // accepted language version version version // accepted language version
nextID uint64 // unique Id for type parameters (first valid Id is 1) posVers map[*syntax.PosBase]version // maps file PosBases to versions (may be nil)
objMap map[Object]*declInfo // maps package-level objects and (non-interface) methods to declaration info nextID uint64 // unique Id for type parameters (first valid Id is 1)
impMap map[importKey]*Package // maps (import path, source directory) to (complete or fake) package objMap map[Object]*declInfo // maps package-level objects and (non-interface) methods to declaration info
valids instanceLookup // valid *Named (incl. instantiated) types per the validType check impMap map[importKey]*Package // maps (import path, source directory) to (complete or fake) package
valids instanceLookup // valid *Named (incl. instantiated) types per the validType check
// pkgPathMap maps package names to the set of distinct import paths we've // pkgPathMap maps package names to the set of distinct import paths we've
// seen for that name, anywhere in the import graph. It is used for // seen for that name, anywhere in the import graph. It is used for
@ -117,7 +118,6 @@ type Checker struct {
// (initialized by Files, valid only for the duration of check.Files; // (initialized by Files, valid only for the duration of check.Files;
// maps and lists are allocated on demand) // maps and lists are allocated on demand)
files []*syntax.File // list of package files files []*syntax.File // list of package files
posVers map[*syntax.PosBase]version // Pos -> Go version mapping
imports []*PkgName // list of imported packages imports []*PkgName // list of imported packages
dotImportMap map[dotImportKey]*PkgName // maps dot-imported objects to the package they were dot-imported through dotImportMap map[dotImportKey]*PkgName // maps dot-imported objects to the package they were dot-imported through
recvTParamMap map[*syntax.Name]*TypeParam // maps blank receiver type parameters to their type recvTParamMap map[*syntax.Name]*TypeParam // maps blank receiver type parameters to their type
@ -303,7 +303,7 @@ func (check *Checker) initFiles(files []*syntax.File) {
// If there is no check.version, then we don't really know what Go version to apply. // If there is no check.version, then we don't really know what Go version to apply.
// Legacy tools may do this, and they historically have accepted everything. // Legacy tools may do this, and they historically have accepted everything.
// Preserve that behavior by ignoring //go:build constraints entirely in that case. // Preserve that behavior by ignoring //go:build constraints entirely in that case.
if (v.before(check.version) && check.version.before(version{1, 21})) || check.version.equal(version{0, 0}) { if (v.before(check.version) && check.version.before(go1_21)) || check.version.equal(go0_0) {
continue continue
} }
if check.posVers == nil { if check.posVers == nil {
@ -341,6 +341,10 @@ func (check *Checker) checkFiles(files []*syntax.File) (err error) {
return nil return nil
} }
// Note: parseGoVersion and the subsequent checks should happen once,
// when we create a new Checker, not for each batch of files.
// We can't change it at this point because NewChecker doesn't
// return an error.
check.version, err = parseGoVersion(check.conf.GoVersion) check.version, err = parseGoVersion(check.conf.GoVersion)
if err != nil { if err != nil {
return err return err

View File

@ -99,11 +99,12 @@ type Checker struct {
fset *token.FileSet fset *token.FileSet
pkg *Package pkg *Package
*Info *Info
version version // accepted language version version version // accepted language version
nextID uint64 // unique Id for type parameters (first valid Id is 1) posVers map[*token.File]version // maps files to versions (may be nil)
objMap map[Object]*declInfo // maps package-level objects and (non-interface) methods to declaration info nextID uint64 // unique Id for type parameters (first valid Id is 1)
impMap map[importKey]*Package // maps (import path, source directory) to (complete or fake) package objMap map[Object]*declInfo // maps package-level objects and (non-interface) methods to declaration info
valids instanceLookup // valid *Named (incl. instantiated) types per the validType check impMap map[importKey]*Package // maps (import path, source directory) to (complete or fake) package
valids instanceLookup // valid *Named (incl. instantiated) types per the validType check
// pkgPathMap maps package names to the set of distinct import paths we've // pkgPathMap maps package names to the set of distinct import paths we've
// seen for that name, anywhere in the import graph. It is used for // seen for that name, anywhere in the import graph. It is used for
@ -119,7 +120,6 @@ type Checker struct {
// (initialized by Files, valid only for the duration of check.Files; // (initialized by Files, valid only for the duration of check.Files;
// maps and lists are allocated on demand) // maps and lists are allocated on demand)
files []*ast.File // package files files []*ast.File // package files
posVers map[*token.File]version // Pos -> Go version mapping
imports []*PkgName // list of imported packages imports []*PkgName // list of imported packages
dotImportMap map[dotImportKey]*PkgName // maps dot-imported objects to the package they were dot-imported through dotImportMap map[dotImportKey]*PkgName // maps dot-imported objects to the package they were dot-imported through
recvTParamMap map[*ast.Ident]*TypeParam // maps blank receiver type parameters to their type recvTParamMap map[*ast.Ident]*TypeParam // maps blank receiver type parameters to their type
@ -306,7 +306,7 @@ func (check *Checker) initFiles(files []*ast.File) {
// If there is no check.version, then we don't really know what Go version to apply. // If there is no check.version, then we don't really know what Go version to apply.
// Legacy tools may do this, and they historically have accepted everything. // Legacy tools may do this, and they historically have accepted everything.
// Preserve that behavior by ignoring //go:build constraints entirely in that case. // Preserve that behavior by ignoring //go:build constraints entirely in that case.
if (v.before(check.version) && check.version.before(version{1, 21})) || check.version.equal(version{0, 0}) { if (v.before(check.version) && check.version.before(go1_21)) || check.version.equal(go0_0) {
continue continue
} }
if check.posVers == nil { if check.posVers == nil {
@ -350,6 +350,10 @@ func (check *Checker) checkFiles(files []*ast.File) (err error) {
return nil return nil
} }
// Note: parseGoVersion and the subsequent checks should happen once,
// when we create a new Checker, not for each batch of files.
// We can't change it at this point because NewChecker doesn't
// return an error.
check.version, err = parseGoVersion(check.conf.GoVersion) check.version, err = parseGoVersion(check.conf.GoVersion)
if err != nil { if err != nil {
return err return err