[go] cmd/compile: avoid closure for captured dynamic constants

17 views
Skip to first unread message

Cuong Manh Le (Gerrit)

unread,
May 27, 2026, 6:18:16 AMMay 27
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Cuong Manh Le has uploaded the change for review

Commit message

cmd/compile: avoid closure for captured dynamic constants

Fixes #5370
Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8

Change diff

diff --git a/src/cmd/compile/internal/escape/escape.go b/src/cmd/compile/internal/escape/escape.go
index 1c8e382..5dda0e4 100644
--- a/src/cmd/compile/internal/escape/escape.go
+++ b/src/cmd/compile/internal/escape/escape.go
@@ -89,9 +89,10 @@
// A batch holds escape analysis state that's shared across an entire
// batch of functions being analyzed at once.
type batch struct {
- allLocs []*location
- closures []closure
- reassignOracles map[*ir.Func]*ir.ReassignOracle
+ allLocs []*location
+ closures []closure
+ reassignOracles map[*ir.Func]*ir.ReassignOracle
+ constClosureTemps map[*ir.Name]*location // temp -> original closure variable location

heapLoc location
mutatorLoc location
@@ -163,7 +164,6 @@
for _, closure := range b.closures {
b.flowClosure(closure.k, closure.clo)
}
- b.closures = nil

for _, loc := range b.allLocs {
// Try to replace some non-constant expressions with literals.
@@ -176,6 +176,12 @@
}
}

+ // Rewrite constant-capturing closures only after rewriteWithLiterals,
+ // so existing literal/interface rewrites still see the original closure
+ // variables and preserve their diagnostics.
+ b.rewriteConstClosures()
+ b.closures = nil
+
b.walkAll()
b.finish(fns)
}
@@ -371,6 +377,14 @@
}
}

+ for tmp, loc := range b.constClosureTemps {
+ if loc.hasAttr(attrEscapes) {
+ tmp.SetEsc(ir.EscHeap)
+ } else {
+ tmp.SetEsc(ir.EscNone)
+ }
+ }
+
if goexperiment.RuntimeFreegc {
// Look for specific patterns of usage, such as appends
// to slices that we can prove are not aliased.
@@ -409,6 +423,97 @@
escFuncTagged
)

+type constClosureCapturedVar struct {
+ cv *ir.Name
+ lit *ir.BasicLit
+}
+
+// rewriteConstClosures rewrites closures that capture only by-value
+// dynamic constants into ordinary functions.
+//
+// For example:
+//
+// s := ""
+// f := func() { println(s) }
+//
+// can be compiled as a plain function literal with s replaced by an
+// ordinary local initialized from "", avoiding construction of a closure
+// object even if f itself escapes.
+func (b *batch) rewriteConstClosures() {
+ for _, closure := range b.closures {
+ clo := closure.clo
+ fn := clo.Func
+ if !fn.IsClosure() {
+ continue
+ }
+
+ ro := b.reassignOracle(fn)
+ if ro == nil {
+ base.Fatalf("no ReassignOracle for closure %v with parent %v", fn, fn.ClosureParent)
+ }
+
+ var captures []constClosureCapturedVar
+ ok := true
+ for _, cv := range fn.ClosureVars {
+ if !cv.Byval() {
+ ok = false
+ break
+ }
+
+ v := ro.StaticValue(cv.Outer)
+ lit, isLit := v.(*ir.BasicLit)
+ if !isLit || lit.Op() != ir.OLITERAL || !ir.ValidTypeForConst(cv.Type(), lit.Val()) {
+ ok = false
+ break
+ }
+
+ captures = append(captures, constClosureCapturedVar{cv: cv, lit: lit})
+ }
+ if !ok {
+ continue
+ }
+
+ repl := make(map[*ir.Name]*ir.Name)
+ var prefix []ir.Node
+ for _, capture := range captures {
+ cv := capture.cv
+ lit := capture.lit
+ pos := cv.Pos()
+
+ tmp := typecheck.TempAt(pos, fn, cv.Type())
+ repl[cv] = tmp
+ if b.constClosureTemps == nil {
+ b.constClosureTemps = make(map[*ir.Name]*location)
+ }
+ b.constClosureTemps[tmp] = b.oldLoc(cv)
+
+ prefix = append(prefix, typecheck.Stmt(ir.NewDecl(pos, ir.ODCL, tmp)))
+ litVal := ir.NewBasicLit(pos, cv.Type(), lit.Val())
+ prefix = append(prefix, typecheck.Stmt(ir.NewAssignStmt(pos, tmp, litVal)))
+ }
+
+ var edit func(ir.Node) ir.Node
+ edit = func(n ir.Node) ir.Node {
+ if name, ok := n.(*ir.Name); ok && name.Op() == ir.ONAME {
+ if tmp := repl[name]; tmp != nil {
+ return tmp
+ }
+ }
+ ir.EditChildren(n, edit)
+ return n
+ }
+ ir.EditChildren(fn, edit)
+
+ fn.Body.Prepend(prefix...)
+
+ // With all captured variables rewritten to ordinary locals, this is
+ // no longer a closure. walkClosure will lower the OCLOSURE to the
+ // function's ONAME.
+ fn.ClosureVars = nil
+ fn.SetNeedctxt(false)
+ }
+}
+
// Mark labels that have no backjumps to them as not increasing e.loopdepth.
type labelState int

diff --git a/test/escape_dynconst_closure.go b/test/escape_dynconst_closure.go
new file mode 100644
index 0000000..ec684e7
--- /dev/null
+++ b/test/escape_dynconst_closure.go
@@ -0,0 +1,17 @@
+// errorcheck -0 -m -d=closure
+
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func main() {
+ s := ""
+ f := func() { println(s) } // ERROR "can inline main.func1" "func literal does not escape" "closure converted to global"
+ g(f)
+}
+
+//go:noinline
+func g(func()) {
+}

Change information

Files:
  • M src/cmd/compile/internal/escape/escape.go
  • A test/escape_dynconst_closure.go
Change size: M
Delta: 2 files changed, 126 insertions(+), 4 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
Gerrit-Change-Number: 783641
Gerrit-PatchSet: 1
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
May 27, 2026, 6:18:36 AMMay 27
to goph...@pubsubhelper.golang.org, Keith Randall, t hepudds, golang-co...@googlegroups.com
Attention needed from Keith Randall and t hepudds

Cuong Manh Le voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
  • t hepudds
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
Gerrit-Change-Number: 783641
Gerrit-PatchSet: 1
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: t hepudds <thepud...@gmail.com>
Gerrit-Comment-Date: Wed, 27 May 2026 10:18:29 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
May 27, 2026, 7:59:57 AMMay 27
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le, Keith Randall and t hepudds

Cuong Manh Le uploaded new patchset

Cuong Manh Le uploaded patch set #2 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Cuong Manh Le
  • Keith Randall
  • t hepudds
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
Gerrit-Change-Number: 783641
Gerrit-PatchSet: 2
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
May 28, 2026, 2:54:22 AM (14 days ago) May 28
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le, Keith Randall and t hepudds

Message from Cuong Manh Le

Set Ready For Review

Open in Gerrit

Related details

Attention is currently required from:
  • Cuong Manh Le
  • Keith Randall
  • t hepudds
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
Gerrit-Change-Number: 783641
Gerrit-PatchSet: 3
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Comment-Date: Thu, 28 May 2026 06:54:15 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
May 28, 2026, 2:54:29 AM (14 days ago) May 28
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
Attention needed from Keith Randall and t hepudds

Cuong Manh Le voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
  • t hepudds
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
Gerrit-Change-Number: 783641
Gerrit-PatchSet: 3
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: t hepudds <thepud...@gmail.com>
Gerrit-Comment-Date: Thu, 28 May 2026 06:54:22 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
May 28, 2026, 4:25:35 AM (14 days ago) May 28
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
Attention needed from Keith Randall and t hepudds

Cuong Manh Le voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
  • t hepudds
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
Gerrit-Change-Number: 783641
Gerrit-PatchSet: 4
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: t hepudds <thepud...@gmail.com>
Gerrit-Comment-Date: Thu, 28 May 2026 08:25:29 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Keith Randall (Gerrit)

unread,
May 29, 2026, 12:50:25 PM (13 days ago) May 29
to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le and t hepudds

Keith Randall added 4 comments

File src/cmd/compile/internal/walk/closure.go
Line 97, Patchset 4 (Parent): // If not a closure, don't bother wrapping.
Keith Randall . unresolved

This does feel very all-or-nothing. I think it would be better to constant-propagate any constants into closures, even if it isn't all the closure captured variables.

Line 111, Patchset 4 (Latest): ro.Init(clofn.ClosureParent)
Keith Randall . unresolved

I worry this is going to re-analyze the parent lots of times if the parent has lots of closures in it. Any better way to organize it?

Line 131, Patchset 4 (Latest): if lit.Val().Kind() == constant.Int && !constant.Compare(lit.Val(), token.GEQ, constant.MakeInt64(0)) {
Keith Randall . unresolved

Why does this matter? Negative constants should be fine.

Line 139, Patchset 4 (Latest): // Substitute variable references inside the body with literal constants
Keith Randall . unresolved

Instead of replacing the name at every location, maybe we could add a `name := const` assignment at the start of the body instead?

Open in Gerrit

Related details

Attention is currently required from:
  • Cuong Manh Le
  • t hepudds
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedNo-Wait-Release
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
    Gerrit-Change-Number: 783641
    Gerrit-PatchSet: 4
    Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
    Gerrit-Attention: t hepudds <thepud...@gmail.com>
    Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Comment-Date: Fri, 29 May 2026 16:50:19 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    t hepudds (Gerrit)

    unread,
    May 29, 2026, 1:13:36 PM (13 days ago) May 29
    to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com
    Attention needed from Cuong Manh Le

    t hepudds added 1 comment

    File src/cmd/compile/internal/walk/closure.go
    Line 111, Patchset 4 (Latest): ro.Init(clofn.ClosureParent)
    Keith Randall . unresolved

    I worry this is going to re-analyze the parent lots of times if the parent has lots of closures in it. Any better way to organize it?

    t hepudds

    I need to read through this a bit more to understand better, but I'll note that I introduced `(*batch).reassignOracle` in escape analysis which tries to avoid repeated work for closure parents:

    https://github.com/golang/go/blob/d96f55fe49dda34ad4aa7af7cbf04321fc86cd27/src/cmd/compile/internal/escape/escape.go#L639-L644

    Maybe that approach is not useful here, but when working on that, I had wondered if the `ir` package should maybe take on making it more convenient to efficiently create ir.ReassignOracles including handling closures well (e.g., maybe a function taking a package and returning a struct that then returns ir.ReassignOracles efficiently for that package, or something like that, though TBH I would need to look at the details again to remember what an actual API might look like).

    Something like that might allow deleting `(*batch).reassignOracle`, and maybe could then be used here and elsewhere.

    There's also `analyzePreWalk` in `internal/walk.go` which creates ir.ReassignOracles.

    While reviewing that, I think Keith might have floated maybe a new field on `ir.Func` or similar if most funcs are going to end up needing an ir.ReassignOracle in practice, though I think some small care would need to be used if so to stop using an ir.ReassignOracle when its no longer valid after many modifications to the IR.

    Sorry, probably too off topic for this particular CL, but maybe some food for thought.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Cuong Manh Le
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedNo-Wait-Release
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
    Gerrit-Change-Number: 783641
    Gerrit-PatchSet: 4
    Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
    Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Comment-Date: Fri, 29 May 2026 17:13:32 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Keith Randall <k...@golang.org>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Cuong Manh Le (Gerrit)

    unread,
    May 29, 2026, 7:18:23 PM (12 days ago) May 29
    to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
    Attention needed from Keith Randall

    Cuong Manh Le added 1 comment

    File src/cmd/compile/internal/walk/closure.go
    Line 131, Patchset 4 (Latest): if lit.Val().Kind() == constant.Int && !constant.Compare(lit.Val(), token.GEQ, constant.MakeInt64(0)) {
    Keith Randall . unresolved

    Why does this matter? Negative constants should be fine.

    Cuong Manh Le

    If we replaced a negative constant to make bultin for example, it will cause compile time panic instead of runtime panic:

    ```
    n := -1
    _ = func() { _ = make([]byte, n)}
    ```


    It’s the same reason that escape.(*batch).rewriteWithLiteral also excludes negative ones.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedNo-Wait-Release
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
    Gerrit-Change-Number: 783641
    Gerrit-PatchSet: 4
    Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Fri, 29 May 2026 23:18:13 +0000
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Cuong Manh Le (Gerrit)

    unread,
    May 29, 2026, 7:31:48 PM (12 days ago) May 29
    to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
    Attention needed from Keith Randall

    Cuong Manh Le added 1 comment

    File src/cmd/compile/internal/walk/closure.go
    Line 139, Patchset 4 (Latest): // Substitute variable references inside the body with literal constants
    Keith Randall . unresolved

    Instead of replacing the name at every location, maybe we could add a `name := const` assignment at the start of the body instead?

    Cuong Manh Le

    This is indeed my initial implementation, but that causes some liveness issue (IRRC) because I did this transformation during escape analysis. It's probably ok now since this is being done during walk pass.

    Further, doing this will also prevent specical case for negative constant above.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedNo-Wait-Release
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
    Gerrit-Change-Number: 783641
    Gerrit-PatchSet: 4
    Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Fri, 29 May 2026 23:31:39 +0000
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Cuong Manh Le (Gerrit)

    unread,
    Jun 2, 2026, 5:04:11 AM (9 days ago) Jun 2
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Keith Randall

    Cuong Manh Le uploaded new patchset

    Cuong Manh Le uploaded patch set #6 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
      Gerrit-Change-Number: 783641
      Gerrit-PatchSet: 6
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      Jun 2, 2026, 5:05:36 AM (9 days ago) Jun 2
      to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
      Attention needed from Keith Randall and t hepudds

      Cuong Manh Le voted and added 2 comments

      Votes added by Cuong Manh Le

      Commit-Queue+1

      2 comments

      File src/cmd/compile/internal/walk/closure.go
      Line 111, Patchset 4: ro.Init(clofn.ClosureParent)
      Keith Randall . unresolved

      I worry this is going to re-analyze the parent lots of times if the parent has lots of closures in it. Any better way to organize it?

      t hepudds

      I need to read through this a bit more to understand better, but I'll note that I introduced `(*batch).reassignOracle` in escape analysis which tries to avoid repeated work for closure parents:

      https://github.com/golang/go/blob/d96f55fe49dda34ad4aa7af7cbf04321fc86cd27/src/cmd/compile/internal/escape/escape.go#L639-L644

      Maybe that approach is not useful here, but when working on that, I had wondered if the `ir` package should maybe take on making it more convenient to efficiently create ir.ReassignOracles including handling closures well (e.g., maybe a function taking a package and returning a struct that then returns ir.ReassignOracles efficiently for that package, or something like that, though TBH I would need to look at the details again to remember what an actual API might look like).

      Something like that might allow deleting `(*batch).reassignOracle`, and maybe could then be used here and elsewhere.

      There's also `analyzePreWalk` in `internal/walk.go` which creates ir.ReassignOracles.

      While reviewing that, I think Keith might have floated maybe a new field on `ir.Func` or similar if most funcs are going to end up needing an ir.ReassignOracle in practice, though I think some small care would need to be used if so to stop using an ir.ReassignOracle when its no longer valid after many modifications to the IR.

      Sorry, probably too off topic for this particular CL, but maybe some food for thought.

      Cuong Manh Le

      I worry this is going to re-analyze the parent lots of times if the parent has lots of closures in it. Any better way to organize it?

      Latest patch adds a cache so we only analyze the parent once. Note that we must walk the parent after it was walked, otherwise, reassignment oracle may not work properly.

      Line 139, Patchset 4: // Substitute variable references inside the body with literal constants
      Keith Randall . unresolved

      Instead of replacing the name at every location, maybe we could add a `name := const` assignment at the start of the body instead?

      Cuong Manh Le

      This is indeed my initial implementation, but that causes some liveness issue (IRRC) because I did this transformation during escape analysis. It's probably ok now since this is being done during walk pass.

      Further, doing this will also prevent specical case for negative constant above.

      Cuong Manh Le

      Yay, still seeing liveness issue:

      ```
      $ go test -run=Test/unsafe -v cmd/internal/testdir
      ./regexp/regexp.go:566:43: internal compiler error: '(*Regexp).ReplaceAllLiteralString.func1#0o3auQubr5g=#': value .autotmp_3 (nil) incorrectly live at entry

      goroutine 14 [running]:
      runtime/debug.Stack()
      ./runtime/debug/stack.go:26 +0x5e
      cmd/compile/internal/base.FatalfAt({0x44155d58?, 0x23e2?}, {0x23e245bc0120, 0x2d}, {0x23e245bb72f0, 0x3, 0x3})
      cmd/compile/internal/base/print.go:232 +0x18b
      cmd/compile/internal/base.Fatalf(...)
      cmd/compile/internal/base/print.go:197
      cmd/compile/internal/ssagen.(*ssafn).Fatalf(0x427da9?, {0x44156378?, 0x23e2?}, {0x1095116, 0x27}, {0x23e245bc4020, 0x2, 0xa?})
      cmd/compile/internal/ssagen/ssa.go:8017 +0x171
      cmd/compile/internal/ssa.(*Func).Fatalf(0x23e245ba8700, {0x1095116, 0x27}, {0x23e245bc4020, 0x2, 0x2})
      cmd/compile/internal/ssa/func.go:762 +0x243
      cmd/compile/internal/ssagen.(*state).variable(...)
      cmd/compile/internal/ssagen/ssa.go:6659
      cmd/compile/internal/ssagen.(*state).exprCheckPtr(0x23e245b9aa00, {0x1a820e0, 0x23e243caa820}, 0x1)
      cmd/compile/internal/ssagen/ssa.go:3076 +0x6c94
      cmd/compile/internal/ssagen.(*state).expr(...)
      cmd/compile/internal/ssagen/ssa.go:3026
      cmd/compile/internal/ssagen.(*state).exprCheckPtr(0x23e245b9aa00, {0x1a82590, 0x23e243dba0c0}, 0x1)
      cmd/compile/internal/ssagen/ssa.go:3579 +0x32eb
      cmd/compile/internal/ssagen.(*state).expr(...)
      cmd/compile/internal/ssagen/ssa.go:3026
      cmd/compile/internal/ssagen.(*state).exprCheckPtr(0x23e245b9aa00, {0x1a82c98, 0x23e243db6600}, 0x1)
      cmd/compile/internal/ssagen/ssa.go:3369 +0xfe7
      cmd/compile/internal/ssagen.(*state).expr(...)
      cmd/compile/internal/ssagen/ssa.go:3026
      cmd/compile/internal/ssagen.(*state).stmt(0x23e245b9aa00, {0x1a836c0, 0x23e243db4c80})
      cmd/compile/internal/ssagen/ssa.go:1914 +0x69ac
      cmd/compile/internal/ssagen.(*state).stmtList(...)
      cmd/compile/internal/ssagen/ssa.go:1649
      cmd/compile/internal/ssagen.(*state).stmt(0x23e245b9aa00, {0x1a836c0, 0x23e243db4be0})
      cmd/compile/internal/ssagen/ssa.go:1674 +0x2a5
      cmd/compile/internal/ssagen.(*state).stmtList(...)
      cmd/compile/internal/ssagen/ssa.go:1649
      cmd/compile/internal/ssagen.buildssa(0x23e243419540, 0x4, 0x0)
      cmd/compile/internal/ssagen/ssa.go:574 +0x2bb4
      cmd/compile/internal/ssagen.Compile(0x23e243419540, 0x4, 0x0?)
      cmd/compile/internal/ssagen/pgen.go:304 +0x88
      cmd/compile/internal/gc.compileFunctions.func2()
      cmd/compile/internal/gc/compile.go:177 +0x85
      created by cmd/compile/internal/gc.compileFunctions in goroutine 1
      cmd/compile/internal/gc/compile.go:163 +0xe6

      FAIL cmd/internal/testdir [build failed]
      FAIL
      ```

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Keith Randall
      • t hepudds
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
      Gerrit-Change-Number: 783641
      Gerrit-PatchSet: 6
      Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: t hepudds <thepud...@gmail.com>
      Gerrit-Comment-Date: Tue, 02 Jun 2026 09:05:32 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Keith Randall <k...@golang.org>
      Comment-In-Reply-To: t hepudds <thepud...@gmail.com>
      Comment-In-Reply-To: Cuong Manh Le <cuong.m...@gmail.com>
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      Jun 2, 2026, 5:06:26 AM (9 days ago) Jun 2
      to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
      Attention needed from Keith Randall and t hepudds

      Cuong Manh Le voted Commit-Queue+1

      Commit-Queue+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Keith Randall
      • t hepudds
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
      Gerrit-Change-Number: 783641
      Gerrit-PatchSet: 7
      Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: t hepudds <thepud...@gmail.com>
      Gerrit-Comment-Date: Tue, 02 Jun 2026 09:06:21 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      Jun 2, 2026, 5:23:35 AM (9 days ago) Jun 2
      to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
      Attention needed from Keith Randall and t hepudds

      Cuong Manh Le added 1 comment

      File src/cmd/compile/internal/walk/closure.go
      Line 111, Patchset 4: ro.Init(clofn.ClosureParent)
      Keith Randall . unresolved

      I worry this is going to re-analyze the parent lots of times if the parent has lots of closures in it. Any better way to organize it?

      t hepudds

      I need to read through this a bit more to understand better, but I'll note that I introduced `(*batch).reassignOracle` in escape analysis which tries to avoid repeated work for closure parents:

      https://github.com/golang/go/blob/d96f55fe49dda34ad4aa7af7cbf04321fc86cd27/src/cmd/compile/internal/escape/escape.go#L639-L644

      Maybe that approach is not useful here, but when working on that, I had wondered if the `ir` package should maybe take on making it more convenient to efficiently create ir.ReassignOracles including handling closures well (e.g., maybe a function taking a package and returning a struct that then returns ir.ReassignOracles efficiently for that package, or something like that, though TBH I would need to look at the details again to remember what an actual API might look like).

      Something like that might allow deleting `(*batch).reassignOracle`, and maybe could then be used here and elsewhere.

      There's also `analyzePreWalk` in `internal/walk.go` which creates ir.ReassignOracles.

      While reviewing that, I think Keith might have floated maybe a new field on `ir.Func` or similar if most funcs are going to end up needing an ir.ReassignOracle in practice, though I think some small care would need to be used if so to stop using an ir.ReassignOracle when its no longer valid after many modifications to the IR.

      Sorry, probably too off topic for this particular CL, but maybe some food for thought.

      Cuong Manh Le

      I worry this is going to re-analyze the parent lots of times if the parent has lots of closures in it. Any better way to organize it?

      Latest patch adds a cache so we only analyze the parent once. Note that we must walk the parent after it was walked, otherwise, reassignment oracle may not work properly.

      Cuong Manh Le

      Hmm, it seems to me that we have to re-analyze the parent, otherwise nested closure may cause trouble after the immediate enclosing function walked.

      Gerrit-Comment-Date: Tue, 02 Jun 2026 09:23:27 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      Jun 2, 2026, 11:02:53 AM (9 days ago) Jun 2
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Keith Randall and t hepudds

      Cuong Manh Le uploaded new patchset

      Cuong Manh Le uploaded patch set #8 to this change.
      Following approvals got outdated and were removed:
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Keith Randall
      • t hepudds
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
      Gerrit-Change-Number: 783641
      Gerrit-PatchSet: 8
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      Jun 2, 2026, 11:03:03 AM (9 days ago) Jun 2
      to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
      Attention needed from Keith Randall and t hepudds

      Cuong Manh Le voted Commit-Queue+1

      Commit-Queue+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Keith Randall
      • t hepudds
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
      Gerrit-Change-Number: 783641
      Gerrit-PatchSet: 8
      Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: t hepudds <thepud...@gmail.com>
      Gerrit-Comment-Date: Tue, 02 Jun 2026 15:02:54 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      open
      diffy

      Keith Randall (Gerrit)

      unread,
      Jun 2, 2026, 5:49:12 PM (8 days ago) Jun 2
      to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
      Attention needed from Cuong Manh Le, Keith Randall and t hepudds

      Keith Randall added 1 comment

      File src/cmd/compile/internal/walk/closure.go
      Keith Randall

      Maybe you need a vardef?

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cuong Manh Le
      • Keith Randall
      • t hepudds
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedNo-Wait-Release
        • requirement is not satisfiedReview-Enforcement
        • requirement satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
        Gerrit-Change-Number: 783641
        Gerrit-PatchSet: 8
        Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
        Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
        Gerrit-CC: Keith Randall <k...@google.com>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: t hepudds <thepud...@gmail.com>
        Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
        Gerrit-Comment-Date: Tue, 02 Jun 2026 21:49:08 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Keith Randall <k...@golang.org>
        Comment-In-Reply-To: Cuong Manh Le <cuong.m...@gmail.com>
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Cuong Manh Le (Gerrit)

        unread,
        Jun 3, 2026, 5:10:19 AM (8 days ago) Jun 3
        to goph...@pubsubhelper.golang.org, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
        Attention needed from Keith Randall, Keith Randall and t hepudds

        Cuong Manh Le voted and added 1 comment

        Votes added by Cuong Manh Le

        Commit-Queue+1

        1 comment

        File src/cmd/compile/internal/walk/closure.go
        Line 139, Patchset 4: // Substitute variable references inside the body with literal constants
        Keith Randall . resolved
        Cuong Manh Le

        Ops, my bad, I missed the code to prepend the tmp declaration into the closure body.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Keith Randall
        • Keith Randall
        • t hepudds
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedNo-Wait-Release
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
          Gerrit-Change-Number: 783641
          Gerrit-PatchSet: 9
          Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
          Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
          Gerrit-Reviewer: Keith Randall <k...@golang.org>
          Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
          Gerrit-CC: Keith Randall <k...@google.com>
          Gerrit-Attention: Keith Randall <k...@golang.org>
          Gerrit-Attention: t hepudds <thepud...@gmail.com>
          Gerrit-Attention: Keith Randall <k...@google.com>
          Gerrit-Comment-Date: Wed, 03 Jun 2026 09:10:14 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: Yes
          Comment-In-Reply-To: Keith Randall <k...@golang.org>
          Comment-In-Reply-To: Cuong Manh Le <cuong.m...@gmail.com>
          Comment-In-Reply-To: Keith Randall <k...@google.com>
          unsatisfied_requirement
          open
          diffy

          Cuong Manh Le (Gerrit)

          unread,
          Jun 3, 2026, 5:20:01 AM (8 days ago) Jun 3
          to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
          Attention needed from Cuong Manh Le, Keith Randall, Keith Randall and t hepudds

          Cuong Manh Le uploaded new patchset

          Cuong Manh Le uploaded patch set #10 to this change.
          Open in Gerrit

          Related details

          Attention is currently required from:
          • Cuong Manh Le
          • Keith Randall
          • Keith Randall
          • t hepudds
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedNo-Wait-Release
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: newpatchset
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
          Gerrit-Change-Number: 783641
          Gerrit-PatchSet: 10
          Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
          Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
          Gerrit-Reviewer: Keith Randall <k...@golang.org>
          Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
          Gerrit-CC: Keith Randall <k...@google.com>
          Gerrit-Attention: Keith Randall <k...@golang.org>
          Gerrit-Attention: t hepudds <thepud...@gmail.com>
          Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
          Gerrit-Attention: Keith Randall <k...@google.com>
          unsatisfied_requirement
          open
          diffy

          Cuong Manh Le (Gerrit)

          unread,
          Jun 3, 2026, 5:21:09 AM (8 days ago) Jun 3
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
          Attention needed from Keith Randall, Keith Randall and t hepudds

          Cuong Manh Le voted and added 1 comment

          Votes added by Cuong Manh Le

          Commit-Queue+1

          1 comment

          File src/cmd/compile/internal/walk/closure.go
          Line 131, Patchset 4: if lit.Val().Kind() == constant.Int && !constant.Compare(lit.Val(), token.GEQ, constant.MakeInt64(0)) {
          Keith Randall . resolved

          Why does this matter? Negative constants should be fine.

          Cuong Manh Le

          If we replaced a negative constant to make bultin for example, it will cause compile time panic instead of runtime panic:

          ```
          n := -1
          _ = func() { _ = make([]byte, n)}
          ```


          It’s the same reason that escape.(*batch).rewriteWithLiteral also excludes negative ones.

          Cuong Manh Le

          Latest patch use the temp var injection instead of replacing with literals, so this condition could be removed.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Keith Randall
          • Keith Randall
          • t hepudds
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedNo-Wait-Release
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
          Gerrit-Change-Number: 783641
          Gerrit-PatchSet: 10
          Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
          Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
          Gerrit-Reviewer: Keith Randall <k...@golang.org>
          Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
          Gerrit-CC: Keith Randall <k...@google.com>
          Gerrit-Attention: Keith Randall <k...@golang.org>
          Gerrit-Attention: t hepudds <thepud...@gmail.com>
          Gerrit-Attention: Keith Randall <k...@google.com>
          Gerrit-Comment-Date: Wed, 03 Jun 2026 09:21:00 +0000
          unsatisfied_requirement
          open
          diffy

          Cuong Manh Le (Gerrit)

          unread,
          Jun 3, 2026, 6:05:46 AM (8 days ago) Jun 3
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
          Attention needed from Keith Randall, Keith Randall and t hepudds

          Cuong Manh Le added 1 comment

          File src/cmd/compile/internal/walk/closure.go
          Line 97, Patchset 4 (Parent): // If not a closure, don't bother wrapping.
          Keith Randall . unresolved

          This does feel very all-or-nothing. I think it would be better to constant-propagate any constants into closures, even if it isn't all the closure captured variables.

          Cuong Manh Le

          If something is present in a closure body, it must be either a local variable, a constant, or a captured variable. I don't there's a case other than captured variables that we need to address.

          Since the main motivation here is converting closures into global functions (to avoid the overhead of preparing the closure context), I'm not sure we get a big win if we only partially eliminate the captured variables.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Keith Randall
          • Keith Randall
          • t hepudds
          Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedNo-Wait-Release
            • requirement is not satisfiedReview-Enforcement
            • requirement satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
            Gerrit-Change-Number: 783641
            Gerrit-PatchSet: 10
            Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Reviewer: Keith Randall <k...@golang.org>
            Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
            Gerrit-CC: Keith Randall <k...@google.com>
            Gerrit-Attention: Keith Randall <k...@golang.org>
            Gerrit-Attention: t hepudds <thepud...@gmail.com>
            Gerrit-Attention: Keith Randall <k...@google.com>
            Gerrit-Comment-Date: Wed, 03 Jun 2026 10:05:37 +0000
            unsatisfied_requirement
            satisfied_requirement
            open
            diffy

            Keith Randall (Gerrit)

            unread,
            Jun 8, 2026, 6:48:54 PM (2 days ago) Jun 8
            to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
            Attention needed from Cuong Manh Le, Keith Randall and t hepudds

            Keith Randall added 1 comment

            File src/cmd/compile/internal/walk/closure.go
            Line 97, Patchset 4 (Parent): // If not a closure, don't bother wrapping.
            Keith Randall . unresolved

            This does feel very all-or-nothing. I think it would be better to constant-propagate any constants into closures, even if it isn't all the closure captured variables.

            Cuong Manh Le

            If something is present in a closure body, it must be either a local variable, a constant, or a captured variable. I don't there's a case other than captured variables that we need to address.

            Since the main motivation here is converting closures into global functions (to avoid the overhead of preparing the closure context), I'm not sure we get a big win if we only partially eliminate the captured variables.

            Keith Randall

            It would be nice, if we knew that a captured variable was constant, to not put it in the closure and the copy it back out. Just use that constant in the body.
            Makes closures smaller, and code constructing them shorter. And might get some followon constant propagation.

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Cuong Manh Le
            • Keith Randall
            • t hepudds
            Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedNo-Wait-Release
            • requirement is not satisfiedReview-Enforcement
            • requirement satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
            Gerrit-Change-Number: 783641
            Gerrit-PatchSet: 10
            Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Reviewer: Keith Randall <k...@golang.org>
            Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
            Gerrit-CC: Keith Randall <k...@google.com>
            Gerrit-Attention: t hepudds <thepud...@gmail.com>
            Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Attention: Keith Randall <k...@google.com>
            Gerrit-Comment-Date: Mon, 08 Jun 2026 22:48:50 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: No
            Comment-In-Reply-To: Keith Randall <k...@golang.org>
            unsatisfied_requirement
            satisfied_requirement
            open
            diffy

            Cuong Manh Le (Gerrit)

            unread,
            Jun 9, 2026, 4:06:40 AM (2 days ago) Jun 9
            to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
            Attention needed from Keith Randall, Keith Randall and t hepudds

            Cuong Manh Le added 1 comment

            File src/cmd/compile/internal/walk/closure.go
            Line 97, Patchset 4 (Parent): // If not a closure, don't bother wrapping.
            Keith Randall . unresolved

            This does feel very all-or-nothing. I think it would be better to constant-propagate any constants into closures, even if it isn't all the closure captured variables.

            Cuong Manh Le

            If something is present in a closure body, it must be either a local variable, a constant, or a captured variable. I don't there's a case other than captured variables that we need to address.

            Since the main motivation here is converting closures into global functions (to avoid the overhead of preparing the closure context), I'm not sure we get a big win if we only partially eliminate the captured variables.

            Keith Randall

            It would be nice, if we knew that a captured variable was constant, to not put it in the closure and the copy it back out. Just use that constant in the body.
            Makes closures smaller, and code constructing them shorter. And might get some followon constant propagation.

            Cuong Manh Le

            Fair point.

            But at this time, we have already created the temporary for closures (during order pass) using old closure type. So if we optimized the closure here, its type would change and causing a panic since the closure type is tied to its closure variables.

            Clearing `clo.Prealloc` might makes things works, but I'm not sure it's better than using already allocated temp.

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Keith Randall
            • Keith Randall
            • t hepudds
            Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedNo-Wait-Release
            • requirement is not satisfiedReview-Enforcement
            • requirement satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
            Gerrit-Change-Number: 783641
            Gerrit-PatchSet: 10
            Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Reviewer: Keith Randall <k...@golang.org>
            Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
            Gerrit-CC: Keith Randall <k...@google.com>
            Gerrit-Attention: Keith Randall <k...@golang.org>
            Gerrit-Attention: t hepudds <thepud...@gmail.com>
            Gerrit-Attention: Keith Randall <k...@google.com>
            Gerrit-Comment-Date: Tue, 09 Jun 2026 08:06:32 +0000
            unsatisfied_requirement
            satisfied_requirement
            open
            diffy

            Keith Randall (Gerrit)

            unread,
            Jun 9, 2026, 12:52:27 PM (2 days ago) Jun 9
            to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
            Attention needed from Cuong Manh Le, Keith Randall and t hepudds

            Keith Randall added 1 comment

            File src/cmd/compile/internal/walk/closure.go
            Line 97, Patchset 4 (Parent): // If not a closure, don't bother wrapping.
            Keith Randall . unresolved

            This does feel very all-or-nothing. I think it would be better to constant-propagate any constants into closures, even if it isn't all the closure captured variables.

            Cuong Manh Le

            If something is present in a closure body, it must be either a local variable, a constant, or a captured variable. I don't there's a case other than captured variables that we need to address.

            Since the main motivation here is converting closures into global functions (to avoid the overhead of preparing the closure context), I'm not sure we get a big win if we only partially eliminate the captured variables.

            Keith Randall

            It would be nice, if we knew that a captured variable was constant, to not put it in the closure and the copy it back out. Just use that constant in the body.
            Makes closures smaller, and code constructing them shorter. And might get some followon constant propagation.

            Cuong Manh Le

            Fair point.

            But at this time, we have already created the temporary for closures (during order pass) using old closure type. So if we optimized the closure here, its type would change and causing a panic since the closure type is tied to its closure variables.

            Clearing `clo.Prealloc` might makes things works, but I'm not sure it's better than using already allocated temp.

            Keith Randall

            Can we do the constant propagation before closure building then? If we got that to work, then this CL would not be needed at all - we'd just naturally convert such closures to the static, noncapturing version.

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Cuong Manh Le
            • Keith Randall
            • t hepudds
            Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement is not satisfiedNo-Wait-Release
            • requirement is not satisfiedReview-Enforcement
            • requirement satisfiedTryBots-Pass
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
            Gerrit-Change-Number: 783641
            Gerrit-PatchSet: 10
            Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Reviewer: Keith Randall <k...@golang.org>
            Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
            Gerrit-CC: Keith Randall <k...@google.com>
            Gerrit-Attention: t hepudds <thepud...@gmail.com>
            Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Attention: Keith Randall <k...@google.com>
            Gerrit-Comment-Date: Tue, 09 Jun 2026 16:52:18 +0000
            unsatisfied_requirement
            satisfied_requirement
            open
            diffy

            Cuong Manh Le (Gerrit)

            unread,
            Jun 10, 2026, 3:35:25 AM (22 hours ago) Jun 10
            to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
            Attention needed from Cuong Manh Le, Keith Randall and t hepudds

            Cuong Manh Le uploaded new patchset

            Cuong Manh Le uploaded patch set #11 to this change.
            Following approvals got outdated and were removed:

            Related details

            Attention is currently required from:
            • Cuong Manh Le
            • Keith Randall
            • t hepudds
            Submit Requirements:
              • requirement is not satisfiedCode-Review
              • requirement is not satisfiedNo-Unresolved-Comments
              • requirement is not satisfiedNo-Wait-Release
              • requirement is not satisfiedReview-Enforcement
              • requirement is not satisfiedTryBots-Pass
              Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
              Gerrit-MessageType: newpatchset
              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
              Gerrit-Change-Number: 783641
              Gerrit-PatchSet: 11
              unsatisfied_requirement
              open
              diffy

              Cuong Manh Le (Gerrit)

              unread,
              Jun 10, 2026, 3:37:23 AM (22 hours ago) Jun 10
              to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
              Attention needed from Keith Randall, Keith Randall and t hepudds

              Cuong Manh Le voted and added 2 comments

              Votes added by Cuong Manh Le

              Auto-Submit+1
              Commit-Queue+1

              2 comments

              File src/cmd/compile/internal/walk/closure.go
              Line 97, Patchset 4 (Parent): // If not a closure, don't bother wrapping.
              Keith Randall . resolved

              This does feel very all-or-nothing. I think it would be better to constant-propagate any constants into closures, even if it isn't all the closure captured variables.

              Cuong Manh Le

              If something is present in a closure body, it must be either a local variable, a constant, or a captured variable. I don't there's a case other than captured variables that we need to address.

              Since the main motivation here is converting closures into global functions (to avoid the overhead of preparing the closure context), I'm not sure we get a big win if we only partially eliminate the captured variables.

              Keith Randall

              It would be nice, if we knew that a captured variable was constant, to not put it in the closure and the copy it back out. Just use that constant in the body.
              Makes closures smaller, and code constructing them shorter. And might get some followon constant propagation.

              Cuong Manh Le

              Fair point.

              But at this time, we have already created the temporary for closures (during order pass) using old closure type. So if we optimized the closure here, its type would change and causing a panic since the closure type is tied to its closure variables.

              Clearing `clo.Prealloc` might makes things works, but I'm not sure it's better than using already allocated temp.

              Keith Randall

              Can we do the constant propagation before closure building then? If we got that to work, then this CL would not be needed at all - we'd just naturally convert such closures to the static, noncapturing version.

              Cuong Manh Le

              Fair point, fixed this in patchset 11, PTAL!

              Line 111, Patchset 4: ro.Init(clofn.ClosureParent)
              Keith Randall . resolved

              I worry this is going to re-analyze the parent lots of times if the parent has lots of closures in it. Any better way to organize it?

              t hepudds

              I need to read through this a bit more to understand better, but I'll note that I introduced `(*batch).reassignOracle` in escape analysis which tries to avoid repeated work for closure parents:

              https://github.com/golang/go/blob/d96f55fe49dda34ad4aa7af7cbf04321fc86cd27/src/cmd/compile/internal/escape/escape.go#L639-L644

              Maybe that approach is not useful here, but when working on that, I had wondered if the `ir` package should maybe take on making it more convenient to efficiently create ir.ReassignOracles including handling closures well (e.g., maybe a function taking a package and returning a struct that then returns ir.ReassignOracles efficiently for that package, or something like that, though TBH I would need to look at the details again to remember what an actual API might look like).

              Something like that might allow deleting `(*batch).reassignOracle`, and maybe could then be used here and elsewhere.

              There's also `analyzePreWalk` in `internal/walk.go` which creates ir.ReassignOracles.

              While reviewing that, I think Keith might have floated maybe a new field on `ir.Func` or similar if most funcs are going to end up needing an ir.ReassignOracle in practice, though I think some small care would need to be used if so to stop using an ir.ReassignOracle when its no longer valid after many modifications to the IR.

              Sorry, probably too off topic for this particular CL, but maybe some food for thought.

              Cuong Manh Le

              I worry this is going to re-analyze the parent lots of times if the parent has lots of closures in it. Any better way to organize it?

              Latest patch adds a cache so we only analyze the parent once. Note that we must walk the parent after it was walked, otherwise, reassignment oracle may not work properly.

              Cuong Manh Le

              Hmm, it seems to me that we have to re-analyze the parent, otherwise nested closure may cause trouble after the immediate enclosing function walked.

              Cuong Manh Le

              Patchset 11 does the optimization during escape analysis, so we won't re-analyze the closure parent a lot of times anymore.

              Open in Gerrit

              Related details

              Attention is currently required from:
              • Keith Randall
              • Keith Randall
              • t hepudds
              Submit Requirements:
                • requirement is not satisfiedCode-Review
                • requirement satisfiedNo-Unresolved-Comments
                • requirement is not satisfiedNo-Wait-Release
                • requirement is not satisfiedReview-Enforcement
                • requirement is not satisfiedTryBots-Pass
                Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                Gerrit-MessageType: comment
                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
                Gerrit-Change-Number: 783641
                Gerrit-PatchSet: 11
                Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
                Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
                Gerrit-Reviewer: Keith Randall <k...@golang.org>
                Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
                Gerrit-CC: Keith Randall <k...@google.com>
                Gerrit-Attention: Keith Randall <k...@golang.org>
                Gerrit-Attention: t hepudds <thepud...@gmail.com>
                Gerrit-Attention: Keith Randall <k...@google.com>
                Gerrit-Comment-Date: Wed, 10 Jun 2026 07:37:19 +0000
                Gerrit-HasComments: Yes
                Gerrit-Has-Labels: Yes
                Comment-In-Reply-To: Keith Randall <k...@golang.org>
                Comment-In-Reply-To: t hepudds <thepud...@gmail.com>
                unsatisfied_requirement
                satisfied_requirement
                open
                diffy

                Cuong Manh Le (Gerrit)

                unread,
                Jun 10, 2026, 7:42:48 AM (18 hours ago) Jun 10
                to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
                Attention needed from Keith Randall, Keith Randall and t hepudds

                Cuong Manh Le added 1 comment

                File src/cmd/compile/internal/walk/closure.go
                Line 97, Patchset 4 (Parent): // If not a closure, don't bother wrapping.
                Keith Randall . unresolved

                This does feel very all-or-nothing. I think it would be better to constant-propagate any constants into closures, even if it isn't all the closure captured variables.

                Cuong Manh Le

                If something is present in a closure body, it must be either a local variable, a constant, or a captured variable. I don't there's a case other than captured variables that we need to address.

                Since the main motivation here is converting closures into global functions (to avoid the overhead of preparing the closure context), I'm not sure we get a big win if we only partially eliminate the captured variables.

                Keith Randall

                It would be nice, if we knew that a captured variable was constant, to not put it in the closure and the copy it back out. Just use that constant in the body.
                Makes closures smaller, and code constructing them shorter. And might get some followon constant propagation.

                Cuong Manh Le

                Fair point.

                But at this time, we have already created the temporary for closures (during order pass) using old closure type. So if we optimized the closure here, its type would change and causing a panic since the closure type is tied to its closure variables.

                Clearing `clo.Prealloc` might makes things works, but I'm not sure it's better than using already allocated temp.

                Keith Randall

                Can we do the constant propagation before closure building then? If we got that to work, then this CL would not be needed at all - we'd just naturally convert such closures to the static, noncapturing version.

                Cuong Manh Le

                Fair point, fixed this in patchset 11, PTAL!

                Cuong Manh Le

                Hmm, so I fixed the current failed tests in PS 11 locally. However, this kind of code will fail:

                ```
                t.Run("2 pairs", func(t *testing.T) {
                s := "abc"
                i := 2000
                wantAllocs(t, 0, func() {
                dl.Info("hello",
                "n", i,
                "s", s,
                )
                })
                })
                ```

                will now failed because it is re-written as:

                ```
                t.Run("2 pairs", func(t *testing.T) {
                s := "abc"
                i := 2000
                wantAllocs(t, 0, func() {
                dl.Info("hello",
                "n", i,
                "s", s,
                )
                })
                })
                ```

                because it is rewritten as:

                ```
                t.Run("2 pairs", func(t *testing.T) {
                wantAllocs(t, 0, func() {
                tmp_s := "abc"
                tmp_i := 2000
                dl.Info("hello",
                "n", tmp_i,
                "s", tmp_s,
                )
                })
                })
                ```

                Thus it's counted as 2 allocations.

                Open in Gerrit

                Related details

                Attention is currently required from:
                • Keith Randall
                • Keith Randall
                • t hepudds
                Submit Requirements:
                  • requirement is not satisfiedCode-Review
                  • requirement is not satisfiedNo-Unresolved-Comments
                  • requirement is not satisfiedNo-Wait-Release
                  • requirement is not satisfiedReview-Enforcement
                  • requirement is not satisfiedTryBots-Pass
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: comment
                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
                  Gerrit-Change-Number: 783641
                  Gerrit-PatchSet: 11
                  Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Reviewer: Keith Randall <k...@golang.org>
                  Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
                  Gerrit-CC: Keith Randall <k...@google.com>
                  Gerrit-Attention: Keith Randall <k...@golang.org>
                  Gerrit-Attention: t hepudds <thepud...@gmail.com>
                  Gerrit-Attention: Keith Randall <k...@google.com>
                  Gerrit-Comment-Date: Wed, 10 Jun 2026 11:42:38 +0000
                  Gerrit-HasComments: Yes
                  Gerrit-Has-Labels: No
                  Comment-In-Reply-To: Keith Randall <k...@golang.org>
                  Comment-In-Reply-To: Cuong Manh Le <cuong.m...@gmail.com>
                  unsatisfied_requirement
                  open
                  diffy

                  t hepudds (Gerrit)

                  unread,
                  Jun 10, 2026, 8:40:30 AM (17 hours ago) Jun 10
                  to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, golang-co...@googlegroups.com
                  Attention needed from Cuong Manh Le, Keith Randall and Keith Randall

                  t hepudds added 1 comment

                  File src/cmd/compile/internal/walk/closure.go
                  t hepudds

                  Hi Cuong, is that maybe an ordering issue?

                  I wonder if it would help to run your new code after `b.rewriteWithLiterals`? (Or maybe that would create different challenge?)

                  Open in Gerrit

                  Related details

                  Attention is currently required from:
                  • Cuong Manh Le
                  • Keith Randall
                  • Keith Randall
                  Submit Requirements:
                  • requirement is not satisfiedCode-Review
                  • requirement is not satisfiedNo-Unresolved-Comments
                  • requirement is not satisfiedNo-Wait-Release
                  • requirement is not satisfiedReview-Enforcement
                  • requirement is not satisfiedTryBots-Pass
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: comment
                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
                  Gerrit-Change-Number: 783641
                  Gerrit-PatchSet: 11
                  Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Reviewer: Keith Randall <k...@golang.org>
                  Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
                  Gerrit-CC: Keith Randall <k...@google.com>
                  Gerrit-Attention: Keith Randall <k...@golang.org>
                  Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Attention: Keith Randall <k...@google.com>
                  Gerrit-Comment-Date: Wed, 10 Jun 2026 12:40:24 +0000
                  unsatisfied_requirement
                  open
                  diffy

                  Cuong Manh Le (Gerrit)

                  unread,
                  Jun 10, 2026, 8:57:48 AM (17 hours ago) Jun 10
                  to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
                  Attention needed from Keith Randall, Keith Randall and t hepudds

                  Cuong Manh Le added 1 comment

                  File src/cmd/compile/internal/walk/closure.go
                  Cuong Manh Le

                  I think it’s the ordering issue, since both optimizations are not overlapped. It’s just that the new autotmp injections inside the closure causes them visible to `wantAllocs`.

                  Open in Gerrit

                  Related details

                  Attention is currently required from:
                  • Keith Randall
                  • Keith Randall
                  • t hepudds
                  Submit Requirements:
                  • requirement is not satisfiedCode-Review
                  • requirement is not satisfiedNo-Unresolved-Comments
                  • requirement is not satisfiedNo-Wait-Release
                  • requirement is not satisfiedReview-Enforcement
                  • requirement is not satisfiedTryBots-Pass
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: comment
                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
                  Gerrit-Change-Number: 783641
                  Gerrit-PatchSet: 11
                  Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Reviewer: Keith Randall <k...@golang.org>
                  Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
                  Gerrit-CC: Keith Randall <k...@google.com>
                  Gerrit-Attention: Keith Randall <k...@golang.org>
                  Gerrit-Attention: t hepudds <thepud...@gmail.com>
                  Gerrit-Attention: Keith Randall <k...@google.com>
                  Gerrit-Comment-Date: Wed, 10 Jun 2026 12:57:43 +0000
                  Gerrit-HasComments: Yes
                  Gerrit-Has-Labels: No
                  Comment-In-Reply-To: Keith Randall <k...@golang.org>
                  Comment-In-Reply-To: t hepudds <thepud...@gmail.com>
                  unsatisfied_requirement
                  open
                  diffy

                  Keith Randall (Gerrit)

                  unread,
                  Jun 10, 2026, 5:00:42 PM (9 hours ago) Jun 10
                  to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Keith Randall, t hepudds, golang-co...@googlegroups.com
                  Attention needed from Cuong Manh Le, Keith Randall and t hepudds

                  Keith Randall added 1 comment

                  File src/cmd/compile/internal/walk/closure.go
                  Keith Randall

                  Could we re-apply until convergence? It looks like it might move the decls in one level each time.

                  Open in Gerrit

                  Related details

                  Attention is currently required from:
                  • Cuong Manh Le
                  • Keith Randall
                  • t hepudds
                  Submit Requirements:
                  • requirement is not satisfiedCode-Review
                  • requirement is not satisfiedNo-Unresolved-Comments
                  • requirement is not satisfiedNo-Wait-Release
                  • requirement is not satisfiedReview-Enforcement
                  • requirement is not satisfiedTryBots-Pass
                  Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
                  Gerrit-MessageType: comment
                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: Ib311f7f76b01398d08c9c82d624b0de1d5d578a8
                  Gerrit-Change-Number: 783641
                  Gerrit-PatchSet: 11
                  Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Reviewer: Keith Randall <k...@golang.org>
                  Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
                  Gerrit-CC: Keith Randall <k...@google.com>
                  Gerrit-Attention: t hepudds <thepud...@gmail.com>
                  Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Attention: Keith Randall <k...@google.com>
                  Gerrit-Comment-Date: Wed, 10 Jun 2026 21:00:36 +0000
                  unsatisfied_requirement
                  open
                  diffy
                  Reply all
                  Reply to author
                  Forward
                  0 new messages