aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/walk
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-06-24 23:05:09 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-06-25 02:29:28 +0000
commit2493c727425547db935a1c6e519bc19d01476380 (patch)
tree357aee3a225987ebf5b1000e34d19a9b8b3a430d /src/cmd/compile/internal/walk
parentf190a9280ddcaa958610e104a3f6c105fedd3fee (diff)
downloadgo-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/walk')
-rw-r--r--src/cmd/compile/internal/walk/expr.go16
1 files changed, 2 insertions, 14 deletions
diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go
index bbf289d90e..d8bded8075 100644
--- a/src/cmd/compile/internal/walk/expr.go
+++ b/src/cmd/compile/internal/walk/expr.go
@@ -489,7 +489,7 @@ func walkAddString(n *ir.AddStringExpr, init *ir.Nodes) ir.Node {
// walkCall walks an OCALLFUNC, OCALLINTER, or OCALLMETH node.
func walkCall(n *ir.CallExpr, init *ir.Nodes) ir.Node {
- if n.Op() == ir.OCALLINTER || n.Op() == ir.OCALLMETH {
+ if n.Op() == ir.OCALLINTER || n.X.Op() == ir.OMETHEXPR {
// We expect both interface call reflect.Type.Method and concrete
// call reflect.(*rtype).Method.
usemethod(n)
@@ -549,20 +549,8 @@ func walkCall1(n *ir.CallExpr, init *ir.Nodes) {
}
n.SetWalked(true)
- // If this is a method call t.M(...),
- // rewrite into a function call T.M(t, ...).
- // TODO(mdempsky): Do this right after type checking.
if n.Op() == ir.OCALLMETH {
- withRecv := make([]ir.Node, len(n.Args)+1)
- dot := n.X.(*ir.SelectorExpr)
- withRecv[0] = dot.X
- copy(withRecv[1:], n.Args)
- n.Args = withRecv
-
- dot = ir.NewSelectorExpr(dot.Pos(), ir.OXDOT, ir.TypeNode(dot.X.Type()), dot.Selection.Sym)
-
- n.SetOp(ir.OCALLFUNC)
- n.X = typecheck.Expr(dot)
+ typecheck.FixMethodCall(n)
}
args := n.Args