mirror of
https://github.com/golang/go
synced 2024-10-01 13:44:47 +00:00
[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 <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>
This commit is contained in:
parent
0f732f8c91
commit
135ce1c485
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue