aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/walk
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2021-06-03 18:25:47 -0400
committerCherry Mui <cherryyz@google.com>2021-06-04 17:00:19 +0000
commit46beeed0ac4cd409554167c315861eaf8ae68c4a (patch)
treed3f6c1c4b1f4067f48f636e966b98267d88313ab /src/cmd/compile/internal/walk
parent8e6dfe1b315ca0ef6497b28e16523c2dc4019503 (diff)
downloadgo-46beeed0ac4cd409554167c315861eaf8ae68c4a.tar.gz
go-46beeed0ac4cd409554167c315861eaf8ae68c4a.zip
[dev.typeparams] cmd/compile: allow go'd closure to escape when compiling runtime
When compiling runtime, we don't allow closures to escape, because we don't want (implicit) allocations to occur when it is not okay to allocate (e.g. in the allocator itself). However, for go statement, it already allocates a new goroutine anyway. It is okay to allocate the closure. Allow it. Also include the closure's name when reporting error. Updates #40724. Change-Id: Id7574ed17cc27709609a059c4eaa67ba1c4436dc Reviewed-on: https://go-review.googlesource.com/c/go/+/325109 Trust: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/compile/internal/walk')
-rw-r--r--src/cmd/compile/internal/walk/order.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go
index b733d3a29f..19d9551566 100644
--- a/src/cmd/compile/internal/walk/order.go
+++ b/src/cmd/compile/internal/walk/order.go
@@ -1570,8 +1570,9 @@ func (o *orderState) wrapGoDefer(n *ir.GoDeferStmt) {
// only in-register results?
if len(callArgs) == 0 && call.Op() == ir.OCALLFUNC && callX.Type().NumResults() == 0 {
if c, ok := call.(*ir.CallExpr); ok && callX != nil && callX.Op() == ir.OCLOSURE {
- cloFunc := callX.(*ir.ClosureExpr).Func
- cloFunc.SetClosureCalled(false)
+ clo := callX.(*ir.ClosureExpr)
+ clo.Func.SetClosureCalled(false)
+ clo.IsGoWrap = true
c.PreserveClosure = true
}
return
@@ -1777,12 +1778,9 @@ func (o *orderState) wrapGoDefer(n *ir.GoDeferStmt) {
// Set escape properties for closure.
if n.Op() == ir.OGO {
- // For "go", assume that the closure is going to escape
- // (with an exception for the runtime, which doesn't
- // permit heap-allocated closures).
- if base.Ctxt.Pkgpath != "runtime" {
- clo.SetEsc(ir.EscHeap)
- }
+ // For "go", assume that the closure is going to escape.
+ clo.SetEsc(ir.EscHeap)
+ clo.IsGoWrap = true
} else {
// For defer, just use whatever result escape analysis
// has determined for the defer.