]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: remove Func.ClosureEnter
authorMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 10:14:45 +0000 (02:14 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 11:30:18 +0000 (11:30 +0000)
We can easily compute this on demand.

Passes toolstash -cmp.

Change-Id: I433d8adb2b1615ae05b2764e69904369a59542c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/280994
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/ir/func.go
src/cmd/compile/internal/ir/sizeof_test.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/walk/closure.go
src/cmd/compile/internal/walk/expr.go

index c54b74266929498ea132a00ac50b250b1ad8e88c..1eaca9c6f38c6880c0e3815c4f4a73a16fc72e5c 100644 (file)
@@ -75,13 +75,6 @@ type Func struct {
        // Byval set if they're captured by value.
        ClosureVars []*Name
 
-       // ClosureEnter holds the expressions that the enclosing function
-       // will use to initialize the closure's free variables. These
-       // correspond one-to-one with the variables in ClosureVars, and will
-       // be either an ONAME node (if the variable is captured by value) or
-       // an OADDR-of-ONAME node (if not).
-       ClosureEnter Nodes
-
        // Parents records the parent scope of each scope within a
        // function. The root scope (0) has no parent, so the i'th
        // scope's parent is stored at Parents[i-1].
index 8f5fae8a1200f94009073980053332fb7e8f9d45..60120f2998c838e59b1b30b5f859164068049692 100644 (file)
@@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) {
                _32bit uintptr     // size on 32bit platforms
                _64bit uintptr     // size on 64bit platforms
        }{
-               {Func{}, 196, 344},
+               {Func{}, 184, 320},
                {Name{}, 124, 216},
        }
 
index d8c17484323632659c19831b540a93b333f764e6..2bc911882f74da3833c1cdf203ed10722505ba5d 100644 (file)
@@ -122,20 +122,17 @@ func CaptureVars(fn *ir.Func) {
                }
                out = append(out, v)
 
-               // type check the & of closed variables outside the closure,
+               // type check closed variables outside the closure,
                // so that the outer frame also grabs them and knows they escape.
-               types.CalcSize(v.Type())
+               Expr(v.Outer)
 
-               var outer ir.Node
-               outer = v.Outer
                outermost := v.Defn.(*ir.Name)
 
                // out parameters will be assigned to implicitly upon return.
-               if outermost.Class_ != ir.PPARAMOUT && !outermost.Addrtaken() && !outermost.Assigned() && v.Type().Width <= 128 {
+               if outermost.Class_ != ir.PPARAMOUT && !outermost.Addrtaken() && !outermost.Assigned() && v.Type().Size() <= 128 {
                        v.SetByval(true)
                } else {
                        outermost.SetAddrtaken(true)
-                       outer = NodAddr(outer)
                }
 
                if base.Flag.LowerM > 1 {
@@ -147,11 +144,8 @@ func CaptureVars(fn *ir.Func) {
                        if v.Byval() {
                                how = "value"
                        }
-                       base.WarnfAt(v.Pos(), "%v capturing by %s: %v (addr=%v assign=%v width=%d)", name, how, v.Sym(), outermost.Addrtaken(), outermost.Assigned(), int32(v.Type().Width))
+                       base.WarnfAt(v.Pos(), "%v capturing by %s: %v (addr=%v assign=%v width=%d)", name, how, v.Sym(), outermost.Addrtaken(), outermost.Assigned(), v.Type().Size())
                }
-
-               outer = Expr(outer)
-               fn.ClosureEnter.Append(outer)
        }
 
        fn.ClosureVars = out
index 0726d3b5521eacc192de8a61846089a96bae3d2f..d4eb4eb8a3d07dc8424746f1ba2492ecf340e5c7 100644 (file)
@@ -131,7 +131,7 @@ func walkClosure(clo *ir.ClosureExpr, init *ir.Nodes) ir.Node {
 
        clos := ir.NewCompLitExpr(base.Pos, ir.OCOMPLIT, ir.TypeNode(typ).(ir.Ntype), nil)
        clos.SetEsc(clo.Esc())
-       clos.List.Set(append([]ir.Node{ir.NewUnaryExpr(base.Pos, ir.OCFUNC, fn.Nname)}, fn.ClosureEnter...))
+       clos.List.Set(append([]ir.Node{ir.NewUnaryExpr(base.Pos, ir.OCFUNC, fn.Nname)}, closureArgs(clo)...))
 
        addr := typecheck.NodAddr(clos)
        addr.SetEsc(clo.Esc())
@@ -151,6 +151,26 @@ func walkClosure(clo *ir.ClosureExpr, init *ir.Nodes) ir.Node {
        return walkExpr(cfn, init)
 }
 
+// closureArgs returns a slice of expressions that an be used to
+// initialize the given closure's free variables. These correspond
+// one-to-one with the variables in clo.Func.ClosureVars, and will be
+// either an ONAME node (if the variable is captured by value) or an
+// OADDR-of-ONAME node (if not).
+func closureArgs(clo *ir.ClosureExpr) []ir.Node {
+       fn := clo.Func
+
+       args := make([]ir.Node, len(fn.ClosureVars))
+       for i, v := range fn.ClosureVars {
+               var outer ir.Node
+               outer = v.Outer
+               if !v.Byval() {
+                       outer = typecheck.NodAddrAt(fn.Pos(), outer)
+               }
+               args[i] = typecheck.Expr(outer)
+       }
+       return args
+}
+
 func walkCallPart(n *ir.SelectorExpr, init *ir.Nodes) ir.Node {
        // Create closure in the form of a composite literal.
        // For x.M with receiver (x) type T, the generated code looks like:
index f06a87c37fd7efb18a4d3d425457393ef82fada9..1fd09b42af4ca4e1d0911fa2d090c7d03ab3590d 100644 (file)
@@ -498,8 +498,7 @@ func walkCall(n *ir.CallExpr, init *ir.Nodes) ir.Node {
 
                // Prepend captured variables to argument list.
                clo := n.X.(*ir.ClosureExpr)
-               n.Args.Prepend(clo.Func.ClosureEnter...)
-               clo.Func.ClosureEnter.Set(nil)
+               n.Args.Prepend(closureArgs(clo)...)
 
                // Replace OCLOSURE with ONAME/PFUNC.
                n.X = clo.Func.Nname