]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.24] go/types,types2: allocate the used* maps in initFiles
authorRob Findley <rfindley@google.com>
Fri, 7 Mar 2025 18:13:51 +0000 (18:13 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 25 Mar 2025 16:47:46 +0000 (09:47 -0700)
As described in the associated comment, we need to reallocate usedVars
and usedPkgNames in initFiles, as they are nilled out at the end of
Checker.Files, which may be called multiple times.

For #72122
For #72826

Change-Id: I9f6eb86e072d9d43a8720f6a5e86d827de6006a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/655437
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
(cherry picked from commit fe9b292b11355af6b5f6e1d9247b88fa134657ed)
Reviewed-on: https://go-review.googlesource.com/c/go/+/657695
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@google.com>

src/cmd/compile/internal/types2/check.go
src/go/types/check.go

index 43dbca7448a6327241847994016ffaaaa28048cb..6cc9d9c489aa5a38b002af963368dd361299a43c 100644 (file)
@@ -315,6 +315,13 @@ func (check *Checker) initFiles(files []*syntax.File) {
        check.objPath = nil
        check.cleaners = nil
 
+       // We must initialize usedVars and usedPkgNames both here and in NewChecker,
+       // because initFiles is not called in the CheckExpr or Eval codepaths, yet we
+       // want to free this memory at the end of Files ('used' predicates are
+       // only needed in the context of a given file).
+       check.usedVars = make(map[*Var]bool)
+       check.usedPkgNames = make(map[*PkgName]bool)
+
        // determine package name and collect valid files
        pkg := check.pkg
        for _, file := range files {
index eda0a58ad0fdf3aa22f1a33c2bee1a8c0dd1adda..a60a1adfd9b608d0b67e8a344d02b2d71f2590d6 100644 (file)
@@ -339,6 +339,13 @@ func (check *Checker) initFiles(files []*ast.File) {
        check.objPath = nil
        check.cleaners = nil
 
+       // We must initialize usedVars and usedPkgNames both here and in NewChecker,
+       // because initFiles is not called in the CheckExpr or Eval codepaths, yet we
+       // want to free this memory at the end of Files ('used' predicates are
+       // only needed in the context of a given file).
+       check.usedVars = make(map[*Var]bool)
+       check.usedPkgNames = make(map[*PkgName]bool)
+
        // determine package name and collect valid files
        pkg := check.pkg
        for _, file := range files {