diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-01-04 02:24:48 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-01-10 08:02:16 +0000 |
commit | c9c26d7ffb3c4077ffaa80f7c8e2d550528e1445 (patch) | |
tree | 21e3971160c7b871237f8fb9453efb25c4d7f8f5 /src/cmd/compile/internal/typecheck/func.go | |
parent | 950cf4d46c5bc343644e7ef08828b9e5114d4676 (diff) | |
download | go-c9c26d7ffb3c4077ffaa80f7c8e2d550528e1445.tar.gz go-c9c26d7ffb3c4077ffaa80f7c8e2d550528e1445.zip |
[dev.regabi] cmd/compile: use ClosureVars for method value wrappers
Similar to with regular closures, we can change method value wrappers
to use ClosureVars and allow SSA construction to take care of wiring
it up appropriately.
Change-Id: I05c0b1bcec4e24305324755df35b7bc5b8a6ce7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/281353
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/func.go')
-rw-r--r-- | src/cmd/compile/internal/typecheck/func.go | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go index 8789395ffb..12762f7ee8 100644 --- a/src/cmd/compile/internal/typecheck/func.go +++ b/src/cmd/compile/internal/typecheck/func.go @@ -246,29 +246,26 @@ func MethodValueWrapper(dot *ir.SelectorExpr) *ir.Func { fn.SetWrapper(true) // Declare and initialize variable holding receiver. - cr := ir.NewClosureRead(rcvrtype, types.Rnd(int64(types.PtrSize), int64(rcvrtype.Align))) - var ptr *ir.Name - var body []ir.Node - if rcvrtype.IsPtr() || rcvrtype.IsInterface() { - ptr = Temp(rcvrtype) - body = append(body, ir.NewAssignStmt(base.Pos, ptr, cr)) - } else { - ptr = Temp(types.NewPtr(rcvrtype)) - body = append(body, ir.NewAssignStmt(base.Pos, ptr, NodAddr(cr))) - } + ptr := ir.NewNameAt(base.Pos, Lookup(".this")) + ptr.Class = ir.PAUTOHEAP + ptr.SetType(rcvrtype) + ptr.Curfn = fn + ptr.SetIsClosureVar(true) + ptr.SetByval(true) + fn.ClosureVars = append(fn.ClosureVars, ptr) call := ir.NewCallExpr(base.Pos, ir.OCALL, ir.NewSelectorExpr(base.Pos, ir.OXDOT, ptr, meth), nil) call.Args = ir.ParamNames(tfn.Type()) call.IsDDD = tfn.Type().IsVariadic() + + var body ir.Node = call if t0.NumResults() != 0 { ret := ir.NewReturnStmt(base.Pos, nil) ret.Results = []ir.Node{call} - body = append(body, ret) - } else { - body = append(body, call) + body = ret } - fn.Body = body + fn.Body = []ir.Node{body} FinishFuncBody() Func(fn) |