From 135ce1c485d0563d285f47a748a6d56594571a91 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sat, 26 Dec 2020 18:33:27 -0800 Subject: [PATCH] [dev.regabi] cmd/compile: desugar OMETHEXPR into ONAME during walk A subsequent CL will change FuncName to lazily create the ONAME nodes, which isn't currently safe to do during SSA construction, because that phase is concurrent. Passes toolstash -cmp. Change-Id: Ic24acc1d1160ad93b70ced3baa468f750e689ea6 Reviewed-on: https://go-review.googlesource.com/c/go/+/280435 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/ssagen/ssa.go | 4 ---- src/cmd/compile/internal/walk/expr.go | 26 ++++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index 9cdf902bcb..082cb7c321 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -2108,10 +2108,6 @@ func (s *state) expr(n ir.Node) *ssa.Value { n := n.(*ir.UnaryExpr) aux := n.X.Sym().Linksym() return s.entryNewValue1A(ssa.OpAddr, n.Type(), aux, s.sb) - case ir.OMETHEXPR: - n := n.(*ir.MethodExpr) - sym := staticdata.FuncSym(n.FuncName().Sym()).Linksym() - return s.entryNewValue1A(ssa.OpAddr, types.NewPtr(n.Type()), sym, s.sb) case ir.ONAME: n := n.(*ir.Name) if n.Class_ == ir.PFUNC { diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go index 53bffee181..fd0dd5b062 100644 --- a/src/cmd/compile/internal/walk/expr.go +++ b/src/cmd/compile/internal/walk/expr.go @@ -88,7 +88,7 @@ func walkExpr1(n ir.Node, init *ir.Nodes) ir.Node { base.Fatalf("walkexpr: switch 1 unknown op %+v", n.Op()) panic("unreachable") - case ir.ONONAME, ir.OGETG, ir.ONEWOBJ, ir.OMETHEXPR: + case ir.ONONAME, ir.OGETG, ir.ONEWOBJ: return n case ir.OTYPE, ir.ONAME, ir.OLITERAL, ir.ONIL, ir.ONAMEOFFSET: @@ -98,6 +98,11 @@ func walkExpr1(n ir.Node, init *ir.Nodes) ir.Node { // stringsym for constant strings. return n + case ir.OMETHEXPR: + // TODO(mdempsky): Do this right after type checking. + n := n.(*ir.MethodExpr) + return n.FuncName() + case ir.ONOT, ir.ONEG, ir.OPLUS, ir.OBITNOT, ir.OREAL, ir.OIMAG, ir.OSPTR, ir.OITAB, ir.OIDATA: n := n.(*ir.UnaryExpr) n.X = walkExpr(n.X, init) @@ -517,31 +522,28 @@ func walkCall1(n *ir.CallExpr, init *ir.Nodes) { return // already walked } - args := n.Args - - n.X = walkExpr(n.X, init) - walkExprList(args, init) - // 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(args)+1) + withRecv := make([]ir.Node, len(n.Args)+1) dot := n.X.(*ir.SelectorExpr) withRecv[0] = dot.X - copy(withRecv[1:], args) - args = withRecv + copy(withRecv[1:], n.Args) + n.Args = withRecv dot = ir.NewSelectorExpr(dot.Pos(), ir.OXDOT, ir.TypeNode(dot.X.Type()), dot.Selection.Sym) - fn := typecheck.Expr(dot).(*ir.MethodExpr).FuncName() - fn.Type().Size() n.SetOp(ir.OCALLFUNC) - n.X = fn + n.X = typecheck.Expr(dot) } + args := n.Args params := n.X.Type().Params() + n.X = walkExpr(n.X, init) + walkExprList(args, init) + // For any argument whose evaluation might require a function call, // store that argument into a temporary variable, // to prevent that calls from clobbering arguments already on the stack.