]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: desugar OMETHEXPR into ONAME during walk
authorMatthew Dempsky <mdempsky@google.com>
Sun, 27 Dec 2020 02:33:27 +0000 (18:33 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 28 Dec 2020 07:43:31 +0000 (07:43 +0000)
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 <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>
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/walk/expr.go

index 9cdf902bcb957d8a9561d2653b9f240516d9865e..082cb7c3210ae99905bb6a65d529341fff9726a0 100644 (file)
@@ -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 {
index 53bffee1817b495c4d90fd0d0002072f761f1aec..fd0dd5b06248a2563c1e0f496e1cb0c2d65519d4 100644 (file)
@@ -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.