From ece345aa691c4097fdb8d1f2736a8fd6214515a9 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Fri, 1 Jan 2021 01:46:55 -0800 Subject: [PATCH] [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 --- src/cmd/compile/internal/ir/func.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 -- 2.50.0