]> Cypherpunks repositories - gostls13.git/commitdiff
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>
Fri, 7 Mar 2025 18:54:49 +0000 (10:54 -0800)
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.

Fixes #72122

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>
src/cmd/compile/internal/types2/check.go
src/go/types/check.go

index 68cfdb5d1e3c16fff9a5558e840f85072f401a67..43ad4ee67f95c0c19490b58c237bf5bf3124d0c5 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 {