]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: expand documentation for Func.Closure{Vars,Enter}
authorMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 09:46:55 +0000 (01:46 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 11:30:16 +0000 (11:30 +0000)
I keep getting these confused and having to look at how the code
actually uses them.

Change-Id: I86baf22b76e7dddada6830df0fac241092f716bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/280993
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

index 9a79a4f30ff83b81f526a9854d8c6df6dc11defe..c54b74266929498ea132a00ac50b250b1ad8e88c 100644 (file)
@@ -65,9 +65,22 @@ type Func struct {
        // include closurevars until transformclosure runs.
        Dcl []*Name
 
-       ClosureEnter Nodes   // list of ONAME nodes (or OADDR-of-ONAME nodes, for output parameters) of captured variables
-       ClosureType  Ntype   // closure representation type
-       ClosureVars  []*Name // closure params; each has closurevar set
+       ClosureType Ntype // closure representation type
+
+       // ClosureVars lists the free variables that are used within a
+       // function literal, but formally declared in an enclosing
+       // function. The variables in this slice are the closure function's
+       // own copy of the variables, which are used within its function
+       // body. They will also each have IsClosureVar set, and will have
+       // 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