]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: move posVers field into group of package-specific fields (cleanup)
authorRobert Griesemer <gri@golang.org>
Tue, 1 Aug 2023 22:48:17 +0000 (15:48 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 2 Aug 2023 17:32:07 +0000 (17:32 +0000)
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>
src/cmd/compile/internal/types2/check.go
src/go/types/check.go

index 0a2a49062b5ec001e6e8a7fa853e84e73f3256c5..5412e876bd9b5ded4feb428a88cc822d985c3668 100644 (file)
@@ -97,11 +97,12 @@ type Checker struct {
        ctxt *Context // context for de-duplicating instances
        pkg  *Package
        *Info
-       version version                // accepted language version
-       nextID  uint64                 // unique Id for type parameters (first valid Id is 1)
-       objMap  map[Object]*declInfo   // maps package-level objects and (non-interface) methods to declaration info
-       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
+       version version                     // accepted language version
+       posVers map[*syntax.PosBase]version // maps file PosBases to versions (may be nil)
+       nextID  uint64                      // unique Id for type parameters (first valid Id is 1)
+       objMap  map[Object]*declInfo        // maps package-level objects and (non-interface) methods to declaration info
+       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
        // 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;
        // maps and lists are allocated on demand)
        files         []*syntax.File              // list of package files
-       posVers       map[*syntax.PosBase]version // Pos -> Go version mapping
        imports       []*PkgName                  // list of imported packages
        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
@@ -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.
                        // Legacy tools may do this, and they historically have accepted everything.
                        // 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
                        }
                        if check.posVers == nil {
@@ -341,6 +341,10 @@ func (check *Checker) checkFiles(files []*syntax.File) (err error) {
                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)
        if err != nil {
                return err
index 3b0f5e4fdffbdc7dad16023bd8d8494697f6f043..6301323c2a8bdb320f3269a8b80b8ebe18d5e4d4 100644 (file)
@@ -99,11 +99,12 @@ type Checker struct {
        fset *token.FileSet
        pkg  *Package
        *Info
-       version version                // accepted language version
-       nextID  uint64                 // unique Id for type parameters (first valid Id is 1)
-       objMap  map[Object]*declInfo   // maps package-level objects and (non-interface) methods to declaration info
-       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
+       version version                 // accepted language version
+       posVers map[*token.File]version // maps files to versions (may be nil)
+       nextID  uint64                  // unique Id for type parameters (first valid Id is 1)
+       objMap  map[Object]*declInfo    // maps package-level objects and (non-interface) methods to declaration info
+       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
        // 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;
        // maps and lists are allocated on demand)
        files         []*ast.File               // package files
-       posVers       map[*token.File]version   // Pos -> Go version mapping
        imports       []*PkgName                // list of imported packages
        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
@@ -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.
                        // Legacy tools may do this, and they historically have accepted everything.
                        // 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
                        }
                        if check.posVers == nil {
@@ -350,6 +350,10 @@ func (check *Checker) checkFiles(files []*ast.File) (err error) {
                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)
        if err != nil {
                return err