aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/walk
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-07-02 16:29:42 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-07-03 10:21:47 +0000
commit5dac279fbdd8a4273253de98a4e44484b20bec5b (patch)
treef25e5345d2179c0fd2aa1b18d4b533d92ba4b420 /src/cmd/compile/internal/walk
parent611056ec34b0c017df4c2ea9c6ae6ff99487db27 (diff)
downloadgo-5dac279fbdd8a4273253de98a4e44484b20bec5b.tar.gz
go-5dac279fbdd8a4273253de98a4e44484b20bec5b.zip
[dev.typeparams] cmd/compile: formalize "hidden parameters" idea
This CL formalizes the closure-var trick used for method-value wrappers to be reusable for defining other functions that take hidden parameters via the closure-context register. In particular, it: 1. Adds a new ir.NewHiddenParam function for creating hidden parameters. 2. Changes ir.NewClosureVar to copy Type/Typecheck from the closure variable, so that callers can needing to manually copy these. 3. Updates existing code accordingly (i.e., method-value wrappers to start using ir.NewHiddenParam, and closure builders to stop copying types). Longer term, I anticipate using this to pass dictionaries to stenciled functions within unified IR. Change-Id: I9da3ffdb2a26d15c6e89a21b4e080686d6dc872c Reviewed-on: https://go-review.googlesource.com/c/go/+/332612 Trust: Matthew Dempsky <mdempsky@google.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/walk')
-rw-r--r--src/cmd/compile/internal/walk/closure.go9
1 files changed, 1 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/walk/closure.go b/src/cmd/compile/internal/walk/closure.go
index a86ed2ab80..7f6ef473bf 100644
--- a/src/cmd/compile/internal/walk/closure.go
+++ b/src/cmd/compile/internal/walk/closure.go
@@ -238,17 +238,10 @@ func methodValueWrapper(dot *ir.SelectorExpr) *ir.Func {
fn := typecheck.DeclFunc(sym, tfn)
fn.SetDupok(true)
- fn.SetNeedctxt(true)
fn.SetWrapper(true)
// Declare and initialize variable holding receiver.
- ptr := ir.NewNameAt(base.Pos, typecheck.Lookup(".this"))
- ptr.Class = ir.PAUTOHEAP
- ptr.SetType(rcvrtype)
- ptr.Curfn = fn
- ptr.SetIsClosureVar(true)
- ptr.SetByval(true)
- fn.ClosureVars = append(fn.ClosureVars, ptr)
+ ptr := ir.NewHiddenParam(base.Pos, fn, typecheck.Lookup(".this"), rcvrtype)
call := ir.NewCallExpr(base.Pos, ir.OCALL, ir.NewSelectorExpr(base.Pos, ir.OXDOT, ptr, meth), nil)
call.Args = ir.ParamNames(tfn.Type())