From: Matthew Dempsky Date: Fri, 1 Jan 2021 09:46:55 +0000 (-0800) Subject: [dev.regabi] cmd/compile: expand documentation for Func.Closure{Vars,Enter} X-Git-Tag: go1.17beta1~1539^2~158 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ece345aa691c4097fdb8d1f2736a8fd6214515a9;p=gostls13.git [dev.regabi] cmd/compile: expand documentation for Func.Closure{Vars,Enter} 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 Run-TryBot: Matthew Dempsky Reviewed-by: Cuong Manh Le TryBot-Result: Go Bot --- diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go index 9a79a4f30f..c54b742669 100644 --- a/src/cmd/compile/internal/ir/func.go +++ b/src/cmd/compile/internal/ir/func.go @@ -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