diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-06-22 18:10:59 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-06-23 04:03:38 +0000 |
commit | c4e0c652fbf3b17cc89f72c6569fe255fe5e1047 (patch) | |
tree | ff545984e43e0e1f95639489e9a05bde0dca6274 /src/cmd/compile/internal/noder/reader.go | |
parent | 62095c66e042024fc631a3e9514b637ae4b5ae10 (diff) | |
download | go-c4e0c652fbf3b17cc89f72c6569fe255fe5e1047.tar.gz go-c4e0c652fbf3b17cc89f72c6569fe255fe5e1047.zip |
[dev.typeparams] cmd/compile: refactor CaptureName
CaptureName currently does a few things: checks if a variable needs to
be captured at all; checks if the variable has already been captured;
and creates and saves a new variable. This full suite of functionality
is useful for noder and irgen, but unified IR and other backend code
only has a need for the last feature.
This CL refactors CaptureName a little bit and extracts out
NewClosureVar as a function usable for callers that don't need the
extra features of CaptureName.
Change-Id: I8a67c6375e44babe53344bf78e335535c57f9607
Reviewed-on: https://go-review.googlesource.com/c/go/+/330193
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/reader.go')
-rw-r--r-- | src/cmd/compile/internal/noder/reader.go | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 4fc9e7a777..b106e89892 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -1558,20 +1558,13 @@ func (r *reader) funcLit() ir.Node { fn.Nname.Ntype = ir.TypeNodeAt(typPos, xtype2) } - fn.ClosureVars = make([]*ir.Name, r.len()) - for i := range fn.ClosureVars { + fn.ClosureVars = make([]*ir.Name, 0, r.len()) + for len(fn.ClosureVars) < cap(fn.ClosureVars) { pos := r.pos() outer := r.useLocal() - cv := ir.NewNameAt(pos, outer.Sym()) + cv := ir.NewClosureVar(pos, fn, outer) r.setType(cv, outer.Type()) - cv.Curfn = fn - cv.Class = ir.PAUTOHEAP - cv.SetIsClosureVar(true) - cv.Defn = outer.Canonical() - cv.Outer = outer - - fn.ClosureVars[i] = cv } r.addBody(fn) |