diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2021-06-24 23:05:09 +0700 |
---|---|---|
committer | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2021-06-25 02:29:28 +0000 |
commit | 2493c727425547db935a1c6e519bc19d01476380 (patch) | |
tree | 357aee3a225987ebf5b1000e34d19a9b8b3a430d /src/cmd/compile/internal/typecheck/func.go | |
parent | f190a9280ddcaa958610e104a3f6c105fedd3fee (diff) | |
download | go-2493c727425547db935a1c6e519bc19d01476380.tar.gz go-2493c727425547db935a1c6e519bc19d01476380.zip |
[dev.typeparams] cmd/compile: rewrite method call into method expression during escape analysis
CL 330331 extended escape analysis to analyze method expression calls
the same as normal method calls. We can now simply desugar method calls
into function calls in escape analysis.
To do this, two things must be changed:
- Folding the rewrite method call to method expression call into an
export function in typecheck package, so others can re-use it.
- walkCall now have to call usemethod for method expression calls.
(It seems to me this is a bug in current tip, because if one write
(*rtype).Method(typ, i) in package "reflect", then the function won't
be marked with AttrReflectMethod)
Passes toolstash -cmp.
Change-Id: I4745ab6110b417c7fd32949cc799811a882cd2ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/330671
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/func.go')
-rw-r--r-- | src/cmd/compile/internal/typecheck/func.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go index 031279f42c..00770c87cf 100644 --- a/src/cmd/compile/internal/typecheck/func.go +++ b/src/cmd/compile/internal/typecheck/func.go @@ -15,7 +15,7 @@ import ( "go/token" ) -// package all the arguments that match a ... T parameter into a []T. +// MakeDotArgs package all the arguments that match a ... T parameter into a []T. func MakeDotArgs(pos src.XPos, typ *types.Type, args []ir.Node) ir.Node { var n ir.Node if len(args) == 0 { @@ -57,6 +57,25 @@ func FixVariadicCall(call *ir.CallExpr) { call.IsDDD = true } +// FixMethodCall rewrites a method call t.M(...) into a function call T.M(t, ...). +func FixMethodCall(call *ir.CallExpr) { + if call.X.Op() != ir.ODOTMETH { + return + } + + dot := call.X.(*ir.SelectorExpr) + + fn := Expr(ir.NewSelectorExpr(dot.Pos(), ir.OXDOT, ir.TypeNode(dot.X.Type()), dot.Selection.Sym)) + + args := make([]ir.Node, 1+len(call.Args)) + args[0] = dot.X + copy(args[1:], call.Args) + + call.SetOp(ir.OCALLFUNC) + call.X = fn + call.Args = args +} + // ClosureType returns the struct type used to hold all the information // needed in the closure for clo (clo must be a OCLOSURE node). // The address of a variable of the returned type can be cast to a func. |