From 0f1d2129c4c294a895480b79eeab8d22c07ac573 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Thu, 31 Dec 2020 21:48:27 -0800 Subject: [dev.regabi] cmd/compile: reshuffle type-checking code [generated] This commit splits up typecheck.Package and moves the code elsewhere. The type-checking code is moved into noder, so that it can eventually be interleaved with the noding process. The non-type-checking code is moved back into package gc, so that it can be incorporated into appropriate compiler backend phases. While here, deadcode removal is moved into its own package. Passes toolstash -cmp. [git-generate] cd src/cmd/compile/internal/typecheck : Split into two functions. sed -i -e '/Phase 6/i}\n\nfunc postTypecheck() {' typecheck.go rf ' # Export needed identifiers. mv deadcode Deadcode mv loadsys InitRuntime mv declareUniverse DeclareUniverse mv dirtyAddrtaken DirtyAddrtaken mv computeAddrtaken ComputeAddrtaken mv incrementalAddrtaken IncrementalAddrtaken # Move into new package. mv Deadcode deadcodeslice deadcodeexpr deadcode.go mv deadcode.go cmd/compile/internal/deadcode # Move top-level type-checking code into noder. # Move DeclVars there too, now that nothing else uses it. mv DeclVars Package noder.go mv noder.go cmd/compile/internal/noder # Move non-type-checking code back into gc. mv postTypecheck main.go mv main.go cmd/compile/internal/gc ' cd ../deadcode rf ' # Destutter names. mv Deadcode Func mv deadcodeslice stmts mv deadcodeexpr expr ' cd ../noder rf ' # Move functions up, next to their related code. mv noder.go:/func Package/-1,$ \ noder.go:/makeSrcPosBase translates/-1 mv noder.go:/func DeclVars/-3,$ \ noder.go:/constState tracks/-1 ' cd ../gc rf ' # Inline postTypecheck code back into gc.Main. mv main.go:/func postTypecheck/+0,/AllImportedBodies/+1 \ main.go:/Build init task/-1 rm postTypecheck ' Change-Id: Ie5e992ece4a42204cce6aa98dd6eb52112d098c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/280974 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/deadcode/deadcode.go | 150 ++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/cmd/compile/internal/deadcode/deadcode.go (limited to 'src/cmd/compile/internal/deadcode/deadcode.go') diff --git a/src/cmd/compile/internal/deadcode/deadcode.go b/src/cmd/compile/internal/deadcode/deadcode.go new file mode 100644 index 0000000000..5453cfe396 --- /dev/null +++ b/src/cmd/compile/internal/deadcode/deadcode.go @@ -0,0 +1,150 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package deadcode + +import ( + "go/constant" + + "cmd/compile/internal/base" + "cmd/compile/internal/ir" +) + +func Func(fn *ir.Func) { + stmts(&fn.Body) + + if len(fn.Body) == 0 { + return + } + + for _, n := range fn.Body { + if len(n.Init()) > 0 { + return + } + switch n.Op() { + case ir.OIF: + n := n.(*ir.IfStmt) + if !ir.IsConst(n.Cond, constant.Bool) || len(n.Body) > 0 || len(n.Else) > 0 { + return + } + case ir.OFOR: + n := n.(*ir.ForStmt) + if !ir.IsConst(n.Cond, constant.Bool) || ir.BoolVal(n.Cond) { + return + } + default: + return + } + } + + fn.Body.Set([]ir.Node{ir.NewBlockStmt(base.Pos, nil)}) +} + +func stmts(nn *ir.Nodes) { + var lastLabel = -1 + for i, n := range *nn { + if n != nil && n.Op() == ir.OLABEL { + lastLabel = i + } + } + for i, n := range *nn { + // Cut is set to true when all nodes after i'th position + // should be removed. + // In other words, it marks whole slice "tail" as dead. + cut := false + if n == nil { + continue + } + if n.Op() == ir.OIF { + n := n.(*ir.IfStmt) + n.Cond = expr(n.Cond) + if ir.IsConst(n.Cond, constant.Bool) { + var body ir.Nodes + if ir.BoolVal(n.Cond) { + n.Else = ir.Nodes{} + body = n.Body + } else { + n.Body = ir.Nodes{} + body = n.Else + } + // If "then" or "else" branch ends with panic or return statement, + // it is safe to remove all statements after this node. + // isterminating is not used to avoid goto-related complications. + // We must be careful not to deadcode-remove labels, as they + // might be the target of a goto. See issue 28616. + if body := body; len(body) != 0 { + switch body[(len(body) - 1)].Op() { + case ir.ORETURN, ir.ORETJMP, ir.OPANIC: + if i > lastLabel { + cut = true + } + } + } + } + } + + stmts(n.PtrInit()) + switch n.Op() { + case ir.OBLOCK: + n := n.(*ir.BlockStmt) + stmts(&n.List) + case ir.OFOR: + n := n.(*ir.ForStmt) + stmts(&n.Body) + case ir.OIF: + n := n.(*ir.IfStmt) + stmts(&n.Body) + stmts(&n.Else) + case ir.ORANGE: + n := n.(*ir.RangeStmt) + stmts(&n.Body) + case ir.OSELECT: + n := n.(*ir.SelectStmt) + for _, cas := range n.Cases { + stmts(&cas.Body) + } + case ir.OSWITCH: + n := n.(*ir.SwitchStmt) + for _, cas := range n.Cases { + stmts(&cas.Body) + } + } + + if cut { + nn.Set((*nn)[:i+1]) + break + } + } +} + +func expr(n ir.Node) ir.Node { + // Perform dead-code elimination on short-circuited boolean + // expressions involving constants with the intent of + // producing a constant 'if' condition. + switch n.Op() { + case ir.OANDAND: + n := n.(*ir.LogicalExpr) + n.X = expr(n.X) + n.Y = expr(n.Y) + if ir.IsConst(n.X, constant.Bool) { + if ir.BoolVal(n.X) { + return n.Y // true && x => x + } else { + return n.X // false && x => false + } + } + case ir.OOROR: + n := n.(*ir.LogicalExpr) + n.X = expr(n.X) + n.Y = expr(n.Y) + if ir.IsConst(n.X, constant.Bool) { + if ir.BoolVal(n.X) { + return n.X // true || x => true + } else { + return n.Y // false || x => x + } + } + } + return n +} -- cgit v1.3 From 2f2d4b4e68ab2fc448a1c2daf793b11ccde2fb16 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sat, 2 Jan 2021 01:04:19 -0800 Subject: [dev.regabi] cmd/compile: remove {Ptr,Set}Init from Node interface This CL separates out PtrInit and SetInit into a new InitNode extension interface, and adds a new TakeInit helper function for taking and clearing the Init list (if any) from a Node. This allows removing miniNode.SetInit and miniNode.PtrInit, which in turn allow getting rid of immutableEmptyNodes, and will allow simplification of the Nodes API. It would be nice to get rid of the default Init method too, but there's way more code that expects to be able to call that at the moment, so that'll have to wait. Passes toolstash -cmp. Change-Id: Ia8c18fab9555b774376f7f43eeecfde4f07b5946 Reviewed-on: https://go-review.googlesource.com/c/go/+/281001 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/deadcode/deadcode.go | 4 +- src/cmd/compile/internal/inline/inl.go | 4 +- src/cmd/compile/internal/ir/mini.go | 8 +--- src/cmd/compile/internal/ir/node.go | 52 +++++++++++-------------- src/cmd/compile/internal/noder/noder.go | 2 +- src/cmd/compile/internal/typecheck/typecheck.go | 2 +- src/cmd/compile/internal/walk/assign.go | 10 ++--- src/cmd/compile/internal/walk/builtin.go | 2 +- src/cmd/compile/internal/walk/expr.go | 6 +-- src/cmd/compile/internal/walk/order.go | 9 ++--- src/cmd/compile/internal/walk/range.go | 2 +- src/cmd/compile/internal/walk/select.go | 9 ++--- src/cmd/compile/internal/walk/stmt.go | 12 +++--- src/cmd/compile/internal/walk/walk.go | 3 +- 14 files changed, 52 insertions(+), 73 deletions(-) (limited to 'src/cmd/compile/internal/deadcode/deadcode.go') diff --git a/src/cmd/compile/internal/deadcode/deadcode.go b/src/cmd/compile/internal/deadcode/deadcode.go index 5453cfe396..474532bc17 100644 --- a/src/cmd/compile/internal/deadcode/deadcode.go +++ b/src/cmd/compile/internal/deadcode/deadcode.go @@ -84,7 +84,9 @@ func stmts(nn *ir.Nodes) { } } - stmts(n.PtrInit()) + if len(n.Init()) != 0 { + stmts(n.(ir.InitNode).PtrInit()) + } switch n.Op() { case ir.OBLOCK: n := n.(*ir.BlockStmt) diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 31b97a3787..24fbe3dac0 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -639,7 +639,7 @@ func inlCallee(fn ir.Node) *ir.Func { return nil } -func inlParam(t *types.Field, as ir.Node, inlvars map[*ir.Name]*ir.Name) ir.Node { +func inlParam(t *types.Field, as ir.InitNode, inlvars map[*ir.Name]*ir.Name) ir.Node { if t.Nname == nil { return ir.BlankNode } @@ -741,7 +741,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b callee := n.X for callee.Op() == ir.OCONVNOP { conv := callee.(*ir.ConvExpr) - ninit.Append(conv.PtrInit().Take()...) + ninit.Append(ir.TakeInit(conv)...) callee = conv.X } if callee.Op() != ir.ONAME && callee.Op() != ir.OCLOSURE && callee.Op() != ir.OMETHEXPR { diff --git a/src/cmd/compile/internal/ir/mini.go b/src/cmd/compile/internal/ir/mini.go index 9270132621..93aa15abec 100644 --- a/src/cmd/compile/internal/ir/mini.go +++ b/src/cmd/compile/internal/ir/mini.go @@ -80,13 +80,7 @@ func (n *miniNode) SetDiag(x bool) { n.bits.set(miniDiag, x) } // Empty, immutable graph structure. -func (n *miniNode) Init() Nodes { return Nodes{} } -func (n *miniNode) PtrInit() *Nodes { return &immutableEmptyNodes } -func (n *miniNode) SetInit(x Nodes) { - if x != nil { - panic(n.no("SetInit")) - } -} +func (n *miniNode) Init() Nodes { return Nodes{} } // Additional functionality unavailable. diff --git a/src/cmd/compile/internal/ir/node.go b/src/cmd/compile/internal/ir/node.go index 9536503085..9945cc987a 100644 --- a/src/cmd/compile/internal/ir/node.go +++ b/src/cmd/compile/internal/ir/node.go @@ -34,8 +34,6 @@ type Node interface { // Abstract graph structure, for generic traversals. Op() Op Init() Nodes - PtrInit() *Nodes - SetInit(x Nodes) // Fields specific to certain Ops only. Type() *types.Type @@ -90,6 +88,20 @@ func MayBeShared(n Node) bool { return false } +type InitNode interface { + Node + PtrInit() *Nodes + SetInit(x Nodes) +} + +func TakeInit(n Node) Nodes { + init := n.Init() + if len(init) != 0 { + n.(InitNode).SetInit(nil) + } + return init +} + //go:generate stringer -type=Op -trimprefix=O node.go type Op uint8 @@ -311,35 +323,15 @@ const ( // a slice to save space. type Nodes []Node -// immutableEmptyNodes is an immutable, empty Nodes list. -// The methods that would modify it panic instead. -var immutableEmptyNodes = Nodes{} - -func (n *Nodes) mutate() { - if n == &immutableEmptyNodes { - panic("immutable Nodes.Set") - } -} - // Set sets n to a slice. // This takes ownership of the slice. -func (n *Nodes) Set(s []Node) { - if n == &immutableEmptyNodes { - if len(s) == 0 { - // Allow immutableEmptyNodes.Set(nil) (a no-op). - return - } - n.mutate() - } - *n = s -} +func (n *Nodes) Set(s []Node) { *n = s } // Append appends entries to Nodes. func (n *Nodes) Append(a ...Node) { if len(a) == 0 { return } - n.mutate() *n = append(*n, a...) } @@ -349,7 +341,6 @@ func (n *Nodes) Prepend(a ...Node) { if len(a) == 0 { return } - n.mutate() *n = append(a, *n...) } @@ -544,15 +535,16 @@ func SetPos(n Node) src.XPos { // The result of InitExpr MUST be assigned back to n, e.g. // n.Left = InitExpr(init, n.Left) -func InitExpr(init []Node, n Node) Node { +func InitExpr(init []Node, expr Node) Node { if len(init) == 0 { - return n + return expr } - if MayBeShared(n) { + + n, ok := expr.(InitNode) + if !ok || MayBeShared(n) { // Introduce OCONVNOP to hold init list. - old := n - n = NewConvExpr(base.Pos, OCONVNOP, nil, old) - n.SetType(old.Type()) + n = NewConvExpr(base.Pos, OCONVNOP, nil, expr) + n.SetType(expr.Type()) n.SetTypecheck(1) } diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go index cc8a1c7c89..948833f46e 100644 --- a/src/cmd/compile/internal/noder/noder.go +++ b/src/cmd/compile/internal/noder/noder.go @@ -1200,7 +1200,7 @@ func (p *noder) stmtFall(stmt syntax.Stmt, fallOK bool) ir.Node { panic("unhandled Stmt") } -func (p *noder) assignList(expr syntax.Expr, defn ir.Node, colas bool) []ir.Node { +func (p *noder) assignList(expr syntax.Expr, defn ir.InitNode, colas bool) []ir.Node { if !colas { return p.exprList(expr) } diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 0822a4624c..0ee66df2cf 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -914,7 +914,7 @@ func typecheck1(n ir.Node, top int) ir.Node { // Each must execute its own return n. } -func typecheckargs(n ir.Node) { +func typecheckargs(n ir.InitNode) { var list []ir.Node switch n := n.(type) { default: diff --git a/src/cmd/compile/internal/walk/assign.go b/src/cmd/compile/internal/walk/assign.go index c01079d236..762baa0dd9 100644 --- a/src/cmd/compile/internal/walk/assign.go +++ b/src/cmd/compile/internal/walk/assign.go @@ -17,7 +17,7 @@ import ( // walkAssign walks an OAS (AssignExpr) or OASOP (AssignOpExpr) node. func walkAssign(init *ir.Nodes, n ir.Node) ir.Node { - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) var left, right ir.Node switch n.Op() { @@ -124,7 +124,7 @@ func walkAssignDotType(n *ir.AssignListStmt, init *ir.Nodes) ir.Node { // walkAssignFunc walks an OAS2FUNC node. func walkAssignFunc(init *ir.Nodes, n *ir.AssignListStmt) ir.Node { - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) r := n.Rhs[0] walkExprListSafe(n.Lhs, init) @@ -142,7 +142,7 @@ func walkAssignFunc(init *ir.Nodes, n *ir.AssignListStmt) ir.Node { // walkAssignList walks an OAS2 node. func walkAssignList(init *ir.Nodes, n *ir.AssignListStmt) ir.Node { - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) walkExprListSafe(n.Lhs, init) walkExprListSafe(n.Rhs, init) return ir.NewBlockStmt(src.NoXPos, ascompatee(ir.OAS, n.Lhs, n.Rhs, init)) @@ -150,7 +150,7 @@ func walkAssignList(init *ir.Nodes, n *ir.AssignListStmt) ir.Node { // walkAssignMapRead walks an OAS2MAPR node. func walkAssignMapRead(init *ir.Nodes, n *ir.AssignListStmt) ir.Node { - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) r := n.Rhs[0].(*ir.IndexExpr) walkExprListSafe(n.Lhs, init) @@ -213,7 +213,7 @@ func walkAssignMapRead(init *ir.Nodes, n *ir.AssignListStmt) ir.Node { // walkAssignRecv walks an OAS2RECV node. func walkAssignRecv(init *ir.Nodes, n *ir.AssignListStmt) ir.Node { - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) r := n.Rhs[0].(*ir.UnaryExpr) // recv walkExprListSafe(n.Lhs, init) diff --git a/src/cmd/compile/internal/walk/builtin.go b/src/cmd/compile/internal/walk/builtin.go index fe6045cbbd..13837eeffc 100644 --- a/src/cmd/compile/internal/walk/builtin.go +++ b/src/cmd/compile/internal/walk/builtin.go @@ -206,7 +206,7 @@ func walkCopy(n *ir.BinaryExpr, init *ir.Nodes, runtimecall bool) ir.Node { // walkDelete walks an ODELETE node. func walkDelete(init *ir.Nodes, n *ir.CallExpr) ir.Node { - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) map_ := n.Args[0] key := n.Args[1] map_ = walkExpr(map_, init) diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go index 1fd09b42af..7dfac30094 100644 --- a/src/cmd/compile/internal/walk/expr.go +++ b/src/cmd/compile/internal/walk/expr.go @@ -26,7 +26,7 @@ func walkExpr(n ir.Node, init *ir.Nodes) ir.Node { return n } - if init == n.PtrInit() { + if n, ok := n.(ir.InitNode); ok && init == n.PtrInit() { // not okay to use n->ninit when walking n, // because we might replace n with some other node // and would lose the init list. @@ -35,7 +35,7 @@ func walkExpr(n ir.Node, init *ir.Nodes) ir.Node { if len(n.Init()) != 0 { walkStmtList(n.Init()) - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) } lno := ir.SetPos(n) @@ -359,7 +359,7 @@ func safeExpr(n ir.Node, init *ir.Nodes) ir.Node { if len(n.Init()) != 0 { walkStmtList(n.Init()) - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) } switch n.Op() { diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go index e40c877ea9..679b795270 100644 --- a/src/cmd/compile/internal/walk/order.go +++ b/src/cmd/compile/internal/walk/order.go @@ -466,8 +466,7 @@ func (o *orderState) init(n ir.Node) { } return } - o.stmtList(n.Init()) - n.PtrInit().Set(nil) + o.stmtList(ir.TakeInit(n)) } // call orders the call expression n. @@ -938,8 +937,7 @@ func (o *orderState) stmt(n ir.Node) { if !ir.IsAutoTmp(recv.X) { recv.X = o.copyExpr(recv.X) } - init := *r.PtrInit() - r.PtrInit().Set(nil) + init := ir.TakeInit(r) colas := r.Def do := func(i int, t *types.Type) { @@ -1000,8 +998,7 @@ func (o *orderState) stmt(n ir.Node) { // TODO(mdempsky): Is this actually necessary? // walkselect appears to walk Ninit. - cas.Body.Prepend(cas.Init()...) - cas.PtrInit().Set(nil) + cas.Body.Prepend(ir.TakeInit(cas)...) } o.out = append(o.out, n) diff --git a/src/cmd/compile/internal/walk/range.go b/src/cmd/compile/internal/walk/range.go index 49a69e9751..3092b71d72 100644 --- a/src/cmd/compile/internal/walk/range.go +++ b/src/cmd/compile/internal/walk/range.go @@ -210,7 +210,7 @@ func walkRange(nrange *ir.RangeStmt) ir.Node { a.SetTypecheck(1) a.Lhs = []ir.Node{hv1, hb} a.Rhs = []ir.Node{ir.NewUnaryExpr(base.Pos, ir.ORECV, ha)} - *nfor.Cond.PtrInit() = []ir.Node{a} + nfor.Cond = ir.InitExpr([]ir.Node{a}, nfor.Cond) if v1 == nil { body = nil } else { diff --git a/src/cmd/compile/internal/walk/select.go b/src/cmd/compile/internal/walk/select.go index 1c5e1d7e64..c6e9b71384 100644 --- a/src/cmd/compile/internal/walk/select.go +++ b/src/cmd/compile/internal/walk/select.go @@ -17,8 +17,7 @@ func walkSelect(sel *ir.SelectStmt) { base.Fatalf("double walkselect") } - init := sel.Init() - sel.PtrInit().Set(nil) + init := ir.TakeInit(sel) init = append(init, walkSelectCases(sel.Cases)...) sel.Cases = nil @@ -45,8 +44,7 @@ func walkSelectCases(cases []*ir.CommClause) []ir.Node { l := cas.Init() if cas.Comm != nil { // not default: n := cas.Comm - l = append(l, n.Init()...) - n.PtrInit().Set(nil) + l = append(l, ir.TakeInit(n)...) switch n.Op() { default: base.Fatalf("select %v", n.Op()) @@ -171,8 +169,7 @@ func walkSelectCases(cases []*ir.CommClause) []ir.Node { for _, cas := range cases { ir.SetPos(cas) - init = append(init, cas.Init()...) - cas.PtrInit().Set(nil) + init = append(init, ir.TakeInit(cas)...) n := cas.Comm if n == nil { // default: diff --git a/src/cmd/compile/internal/walk/stmt.go b/src/cmd/compile/internal/walk/stmt.go index 8641a58e2e..3440c66506 100644 --- a/src/cmd/compile/internal/walk/stmt.go +++ b/src/cmd/compile/internal/walk/stmt.go @@ -55,8 +55,7 @@ func walkStmt(n ir.Node) ir.Node { if n.Typecheck() == 0 { base.Fatalf("missing typecheck: %+v", n) } - init := n.Init() - n.PtrInit().Set(nil) + init := ir.TakeInit(n) n = walkExpr(n, &init) if n.Op() == ir.ONAME { // copy rewrote to a statement list and a temp for the length. @@ -67,7 +66,7 @@ func walkStmt(n ir.Node) ir.Node { if len(init) > 0 { switch n.Op() { case ir.OAS, ir.OAS2, ir.OBLOCK: - n.PtrInit().Prepend(init...) + n.(ir.InitNode).PtrInit().Prepend(init...) default: init.Append(n) @@ -191,9 +190,8 @@ func walkDecl(n *ir.Decl) ir.Node { // walkFor walks an OFOR or OFORUNTIL node. func walkFor(n *ir.ForStmt) ir.Node { if n.Cond != nil { - walkStmtList(n.Cond.Init()) - init := n.Cond.Init() - n.Cond.PtrInit().Set(nil) + init := ir.TakeInit(n.Cond) + walkStmtList(init) n.Cond = walkExpr(n.Cond, &init) n.Cond = ir.InitExpr(init, n.Cond) } @@ -257,7 +255,7 @@ func walkIf(n *ir.IfStmt) ir.Node { func wrapCall(n *ir.CallExpr, init *ir.Nodes) ir.Node { if len(n.Init()) != 0 { walkStmtList(n.Init()) - init.Append(n.PtrInit().Take()...) + init.Append(ir.TakeInit(n)...) } isBuiltinCall := n.Op() != ir.OCALLFUNC && n.Op() != ir.OCALLMETH && n.Op() != ir.OCALLINTER diff --git a/src/cmd/compile/internal/walk/walk.go b/src/cmd/compile/internal/walk/walk.go index 25f53a8e7c..57c2d43753 100644 --- a/src/cmd/compile/internal/walk/walk.go +++ b/src/cmd/compile/internal/walk/walk.go @@ -81,8 +81,7 @@ func walkRecv(n *ir.UnaryExpr) ir.Node { if n.Typecheck() == 0 { base.Fatalf("missing typecheck: %+v", n) } - init := n.Init() - n.PtrInit().Set(nil) + init := ir.TakeInit(n) n.X = walkExpr(n.X, &init) call := walkExpr(mkcall1(chanfn("chanrecv1", 2, n.X.Type()), nil, &init, n.X, typecheck.NodNil()), &init) -- cgit v1.3 From f2538033c08a8c215a19610680d66f5909c5bcdd Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sat, 2 Jan 2021 01:27:29 -0800 Subject: [dev.regabi] cmd/compile: remove Nodes.Set [generated] Just "=". It's cleaner. Passes toolstash -cmp. [git-generate] cd src/cmd/compile/internal/ir pkgs=$(go list . ../...) rf ' ex '"$(echo $pkgs)"' { var l Nodes var p *Nodes p.Set(l) -> *p = l } ex '"$(echo $pkgs)"' { var n InitNode var l Nodes *n.PtrInit() = l -> n.SetInit(l) } rm Nodes.Set ' Change-Id: Ic97219792243667146a02776553942ae1189ff7d Reviewed-on: https://go-review.googlesource.com/c/go/+/281002 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/deadcode/deadcode.go | 4 ++-- src/cmd/compile/internal/inline/inl.go | 16 ++++++++-------- src/cmd/compile/internal/ir/expr.go | 10 +++++----- src/cmd/compile/internal/ir/node.go | 4 ---- src/cmd/compile/internal/ir/stmt.go | 16 ++++++++-------- src/cmd/compile/internal/noder/noder.go | 14 +++++++------- src/cmd/compile/internal/pkginit/init.go | 2 +- src/cmd/compile/internal/reflectdata/reflect.go | 2 +- src/cmd/compile/internal/ssagen/abi.go | 2 +- src/cmd/compile/internal/typecheck/const.go | 4 ++-- src/cmd/compile/internal/typecheck/func.go | 8 ++++---- src/cmd/compile/internal/typecheck/iimport.go | 16 ++++++++-------- src/cmd/compile/internal/typecheck/typecheck.go | 8 ++++---- src/cmd/compile/internal/walk/assign.go | 4 ++-- src/cmd/compile/internal/walk/builtin.go | 6 +++--- src/cmd/compile/internal/walk/closure.go | 4 ++-- src/cmd/compile/internal/walk/expr.go | 6 +++--- src/cmd/compile/internal/walk/order.go | 12 ++++++------ src/cmd/compile/internal/walk/range.go | 2 +- src/cmd/compile/internal/walk/select.go | 8 ++++---- src/cmd/compile/internal/walk/stmt.go | 4 ++-- 21 files changed, 74 insertions(+), 78 deletions(-) (limited to 'src/cmd/compile/internal/deadcode/deadcode.go') diff --git a/src/cmd/compile/internal/deadcode/deadcode.go b/src/cmd/compile/internal/deadcode/deadcode.go index 474532bc17..c409320fc4 100644 --- a/src/cmd/compile/internal/deadcode/deadcode.go +++ b/src/cmd/compile/internal/deadcode/deadcode.go @@ -38,7 +38,7 @@ func Func(fn *ir.Func) { } } - fn.Body.Set([]ir.Node{ir.NewBlockStmt(base.Pos, nil)}) + fn.Body = []ir.Node{ir.NewBlockStmt(base.Pos, nil)} } func stmts(nn *ir.Nodes) { @@ -114,7 +114,7 @@ func stmts(nn *ir.Nodes) { } if cut { - nn.Set((*nn)[:i+1]) + *nn = (*nn)[:i+1] break } } diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 24fbe3dac0..2887abb061 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -544,7 +544,7 @@ func inlnode(n ir.Node, maxCost int32, inlMap map[*ir.Func]bool, edit func(ir.No if as := n; as.Op() == ir.OAS2FUNC { as := as.(*ir.AssignListStmt) if as.Rhs[0].Op() == ir.OINLCALL { - as.Rhs.Set(inlconv2list(as.Rhs[0].(*ir.InlinedCallExpr))) + as.Rhs = inlconv2list(as.Rhs[0].(*ir.InlinedCallExpr)) as.SetOp(ir.OAS2) as.SetTypecheck(0) n = typecheck.Stmt(as) @@ -867,7 +867,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b vas.Y.SetType(param.Type) } else { lit := ir.NewCompLitExpr(base.Pos, ir.OCOMPLIT, ir.TypeNode(param.Type), nil) - lit.List.Set(varargs) + lit.List = varargs vas.Y = lit } } @@ -944,9 +944,9 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b //dumplist("ninit post", ninit); call := ir.NewInlinedCallExpr(base.Pos, nil, nil) - call.PtrInit().Set(ninit) - call.Body.Set(body) - call.ReturnVars.Set(retvars) + *call.PtrInit() = ninit + call.Body = body + call.ReturnVars = retvars call.SetType(n.Type()) call.SetTypecheck(1) @@ -1120,7 +1120,7 @@ func (subst *inlsubst) node(n ir.Node) ir.Node { for _, n := range subst.retvars { as.Lhs.Append(n) } - as.Rhs.Set(subst.list(n.Results)) + as.Rhs = subst.list(n.Results) if subst.delayretvars { for _, n := range as.Lhs { @@ -1139,7 +1139,7 @@ func (subst *inlsubst) node(n ir.Node) ir.Node { n := n.(*ir.BranchStmt) m := ir.Copy(n).(*ir.BranchStmt) m.SetPos(subst.updatedPos(m.Pos())) - m.PtrInit().Set(nil) + *m.PtrInit() = nil p := fmt.Sprintf("%s·%d", n.Label.Name, inlgen) m.Label = typecheck.Lookup(p) return m @@ -1148,7 +1148,7 @@ func (subst *inlsubst) node(n ir.Node) ir.Node { n := n.(*ir.LabelStmt) m := ir.Copy(n).(*ir.LabelStmt) m.SetPos(subst.updatedPos(m.Pos())) - m.PtrInit().Set(nil) + *m.PtrInit() = nil p := fmt.Sprintf("%s·%d", n.Label.Name, inlgen) m.Label = typecheck.Lookup(p) return m diff --git a/src/cmd/compile/internal/ir/expr.go b/src/cmd/compile/internal/ir/expr.go index 88fbdff1e0..1b88427146 100644 --- a/src/cmd/compile/internal/ir/expr.go +++ b/src/cmd/compile/internal/ir/expr.go @@ -67,7 +67,7 @@ func NewAddStringExpr(pos src.XPos, list []Node) *AddStringExpr { n := &AddStringExpr{} n.pos = pos n.op = OADDSTR - n.List.Set(list) + n.List = list return n } @@ -173,7 +173,7 @@ func NewCallExpr(pos src.XPos, op Op, fun Node, args []Node) *CallExpr { n.pos = pos n.orig = n n.SetOp(op) - n.Args.Set(args) + n.Args = args return n } @@ -231,7 +231,7 @@ func NewCompLitExpr(pos src.XPos, op Op, typ Ntype, list []Node) *CompLitExpr { n := &CompLitExpr{Ntype: typ} n.pos = pos n.SetOp(op) - n.List.Set(list) + n.List = list n.orig = n return n } @@ -364,8 +364,8 @@ func NewInlinedCallExpr(pos src.XPos, body, retvars []Node) *InlinedCallExpr { n := &InlinedCallExpr{} n.pos = pos n.op = OINLCALL - n.Body.Set(body) - n.ReturnVars.Set(retvars) + n.Body = body + n.ReturnVars = retvars return n } diff --git a/src/cmd/compile/internal/ir/node.go b/src/cmd/compile/internal/ir/node.go index 9945cc987a..9d1ee17aa8 100644 --- a/src/cmd/compile/internal/ir/node.go +++ b/src/cmd/compile/internal/ir/node.go @@ -323,10 +323,6 @@ const ( // a slice to save space. type Nodes []Node -// Set sets n to a slice. -// This takes ownership of the slice. -func (n *Nodes) Set(s []Node) { *n = s } - // Append appends entries to Nodes. func (n *Nodes) Append(a ...Node) { if len(a) == 0 { diff --git a/src/cmd/compile/internal/ir/stmt.go b/src/cmd/compile/internal/ir/stmt.go index 9c2cba9a08..b13c6b7795 100644 --- a/src/cmd/compile/internal/ir/stmt.go +++ b/src/cmd/compile/internal/ir/stmt.go @@ -70,8 +70,8 @@ func NewAssignListStmt(pos src.XPos, op Op, lhs, rhs []Node) *AssignListStmt { n := &AssignListStmt{} n.pos = pos n.SetOp(op) - n.Lhs.Set(lhs) - n.Rhs.Set(rhs) + n.Lhs = lhs + n.Rhs = rhs return n } @@ -141,7 +141,7 @@ func NewBlockStmt(pos src.XPos, list []Node) *BlockStmt { } } n.op = OBLOCK - n.List.Set(list) + n.List = list return n } @@ -216,7 +216,7 @@ func NewForStmt(pos src.XPos, init Node, cond, post Node, body []Node) *ForStmt if init != nil { n.init = []Node{init} } - n.Body.Set(body) + n.Body = body return n } @@ -262,8 +262,8 @@ func NewIfStmt(pos src.XPos, cond Node, body, els []Node) *IfStmt { n := &IfStmt{Cond: cond} n.pos = pos n.op = OIF - n.Body.Set(body) - n.Else.Set(els) + n.Body = body + n.Else = els return n } @@ -315,7 +315,7 @@ func NewRangeStmt(pos src.XPos, key, value, x Node, body []Node) *RangeStmt { n := &RangeStmt{X: x, Key: key, Value: value} n.pos = pos n.op = ORANGE - n.Body.Set(body) + n.Body = body return n } @@ -331,7 +331,7 @@ func NewReturnStmt(pos src.XPos, results []Node) *ReturnStmt { n.pos = pos n.op = ORETURN n.orig = n - n.Results.Set(results) + n.Results = results return n } diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go index 948833f46e..678e378291 100644 --- a/src/cmd/compile/internal/noder/noder.go +++ b/src/cmd/compile/internal/noder/noder.go @@ -245,7 +245,7 @@ func (p *noder) funcBody(fn *ir.Func, block *syntax.BlockStmt) { if body == nil { body = []ir.Node{ir.NewBlockStmt(base.Pos, nil)} } - fn.Body.Set(body) + fn.Body = body base.Pos = p.makeXPos(block.Rbrace) fn.Endlineno = base.Pos @@ -772,7 +772,7 @@ func (p *noder) expr(expr syntax.Expr) ir.Node { for i, e := range l { l[i] = p.wrapname(expr.ElemList[i], e) } - n.List.Set(l) + n.List = l base.Pos = p.makeXPos(expr.Rbrace) return n case *syntax.KeyValueExpr: @@ -1128,8 +1128,8 @@ func (p *noder) stmtFall(stmt syntax.Stmt, fallOK bool) ir.Node { if list, ok := stmt.Lhs.(*syntax.ListExpr); ok && len(list.ElemList) != 1 || len(rhs) != 1 { n := ir.NewAssignListStmt(p.pos(stmt), ir.OAS2, nil, nil) n.Def = stmt.Op == syntax.Def - n.Lhs.Set(p.assignList(stmt.Lhs, n, n.Def)) - n.Rhs.Set(rhs) + n.Lhs = p.assignList(stmt.Lhs, n, n.Def) + n.Rhs = rhs return n } @@ -1276,7 +1276,7 @@ func (p *noder) ifStmt(stmt *syntax.IfStmt) ir.Node { e := p.stmt(stmt.Else) if e.Op() == ir.OBLOCK { e := e.(*ir.BlockStmt) - n.Else.Set(e.List) + n.Else = e.List } else { n.Else = []ir.Node{e} } @@ -1301,7 +1301,7 @@ func (p *noder) forStmt(stmt *syntax.ForStmt) ir.Node { n.Value = lhs[1] } } - n.Body.Set(p.blockStmt(stmt.Body)) + n.Body = p.blockStmt(stmt.Body) p.closeAnotherScope() return n } @@ -1359,7 +1359,7 @@ func (p *noder) caseClauses(clauses []*syntax.CaseClause, tswitch *ir.TypeSwitch body = body[:len(body)-1] } - n.Body.Set(p.stmtsFall(body, true)) + n.Body = p.stmtsFall(body, true) if l := len(n.Body); l > 0 && n.Body[l-1].Op() == ir.OFALL { if tswitch != nil { base.Errorf("cannot fallthrough in type switch") diff --git a/src/cmd/compile/internal/pkginit/init.go b/src/cmd/compile/internal/pkginit/init.go index 24fe1a7628..a32e09879c 100644 --- a/src/cmd/compile/internal/pkginit/init.go +++ b/src/cmd/compile/internal/pkginit/init.go @@ -49,7 +49,7 @@ func Task() *ir.Name { fn.Dcl = append(fn.Dcl, typecheck.InitTodoFunc.Dcl...) typecheck.InitTodoFunc.Dcl = nil - fn.Body.Set(nf) + fn.Body = nf typecheck.FinishFuncBody() typecheck.Func(fn) diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 5f88262ddf..f926765326 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -1798,7 +1798,7 @@ func methodWrapper(rcvr *types.Type, method *types.Field) *obj.LSym { } else { fn.SetWrapper(true) // ignore frame for panic+recover matching call := ir.NewCallExpr(base.Pos, ir.OCALL, dot, nil) - call.Args.Set(ir.ParamNames(tfn.Type())) + call.Args = ir.ParamNames(tfn.Type()) call.IsDDD = tfn.Type().IsVariadic() if method.Type.NumResults() > 0 { ret := ir.NewReturnStmt(base.Pos, nil) diff --git a/src/cmd/compile/internal/ssagen/abi.go b/src/cmd/compile/internal/ssagen/abi.go index cd5d962b91..1c013dd2d8 100644 --- a/src/cmd/compile/internal/ssagen/abi.go +++ b/src/cmd/compile/internal/ssagen/abi.go @@ -303,7 +303,7 @@ func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) { tail = ir.NewBranchStmt(base.Pos, ir.ORETJMP, f.Nname.Sym()) } else { call := ir.NewCallExpr(base.Pos, ir.OCALL, f.Nname, nil) - call.Args.Set(ir.ParamNames(tfn.Type())) + call.Args = ir.ParamNames(tfn.Type()) call.IsDDD = tfn.Type().IsVariadic() tail = call if tfn.Type().NumResults() > 0 { diff --git a/src/cmd/compile/internal/typecheck/const.go b/src/cmd/compile/internal/typecheck/const.go index 5259218ef9..d6bf101974 100644 --- a/src/cmd/compile/internal/typecheck/const.go +++ b/src/cmd/compile/internal/typecheck/const.go @@ -509,7 +509,7 @@ func EvalConst(n ir.Node) ir.Node { } nl := ir.Copy(n).(*ir.AddStringExpr) - nl.List.Set(s[i:i2]) + nl.List = s[i:i2] newList = append(newList, OrigConst(nl, constant.MakeString(strings.Join(strs, "")))) i = i2 - 1 } else { @@ -518,7 +518,7 @@ func EvalConst(n ir.Node) ir.Node { } nn := ir.Copy(n).(*ir.AddStringExpr) - nn.List.Set(newList) + nn.List = newList return nn case ir.OCAP, ir.OLEN: diff --git a/src/cmd/compile/internal/typecheck/func.go b/src/cmd/compile/internal/typecheck/func.go index 296755028d..8592397004 100644 --- a/src/cmd/compile/internal/typecheck/func.go +++ b/src/cmd/compile/internal/typecheck/func.go @@ -52,7 +52,7 @@ func FixVariadicCall(call *ir.CallExpr) { extra[i] = nil // allow GC } - call.Args.Set(append(args[:vi], slice)) + call.Args = append(args[:vi], slice) call.IsDDD = true } @@ -313,7 +313,7 @@ func MethodValueWrapper(dot *ir.SelectorExpr) *ir.Func { } call := ir.NewCallExpr(base.Pos, ir.OCALL, ir.NewSelectorExpr(base.Pos, ir.OXDOT, ptr, meth), nil) - call.Args.Set(ir.ParamNames(tfn.Type())) + call.Args = ir.ParamNames(tfn.Type()) call.IsDDD = tfn.Type().IsVariadic() if t0.NumResults() != 0 { ret := ir.NewReturnStmt(base.Pos, nil) @@ -323,7 +323,7 @@ func MethodValueWrapper(dot *ir.SelectorExpr) *ir.Func { body = append(body, call) } - fn.Body.Set(body) + fn.Body = body FinishFuncBody() Func(fn) @@ -798,7 +798,7 @@ func tcMake(n *ir.CallExpr) ir.Node { return n } - n.Args.Set(nil) + n.Args = nil l := args[0] l = typecheck(l, ctxType) t := l.Type() diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index 00ecd9b819..0caac362e3 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -779,7 +779,7 @@ func (r *importReader) caseList(switchExpr ir.Node) []*ir.CaseClause { cases := make([]*ir.CaseClause, r.uint64()) for i := range cases { cas := ir.NewCaseStmt(r.pos(), nil, nil) - cas.List.Set(r.stmtList()) + cas.List = r.stmtList() if namedTypeSwitch { // Note: per-case variables will have distinct, dotted // names after import. That's okay: swt.go only needs @@ -789,7 +789,7 @@ func (r *importReader) caseList(switchExpr ir.Node) []*ir.CaseClause { cas.Var = caseVar caseVar.Defn = switchExpr } - cas.Body.Set(r.stmtList()) + cas.Body = r.stmtList() cases[i] = cas } return cases @@ -932,7 +932,7 @@ func (r *importReader) node() ir.Node { case ir.OCOPY, ir.OCOMPLEX, ir.OREAL, ir.OIMAG, ir.OAPPEND, ir.OCAP, ir.OCLOSE, ir.ODELETE, ir.OLEN, ir.OMAKE, ir.ONEW, ir.OPANIC, ir.ORECOVER, ir.OPRINT, ir.OPRINTN: n := builtinCall(r.pos(), op) - n.Args.Set(r.exprList()) + n.Args = r.exprList() if op == ir.OAPPEND { n.IsDDD = r.bool() } @@ -945,7 +945,7 @@ func (r *importReader) node() ir.Node { pos := r.pos() init := r.stmtList() n := ir.NewCallExpr(pos, ir.OCALL, r.expr(), r.exprList()) - n.PtrInit().Set(init) + *n.PtrInit() = init n.IsDDD = r.bool() return n @@ -1033,14 +1033,14 @@ func (r *importReader) node() ir.Node { case ir.OIF: pos, init := r.pos(), r.stmtList() n := ir.NewIfStmt(pos, r.expr(), r.stmtList(), r.stmtList()) - n.PtrInit().Set(init) + *n.PtrInit() = init return n case ir.OFOR: pos, init := r.pos(), r.stmtList() cond, post := r.exprsOrNil() n := ir.NewForStmt(pos, nil, cond, post, r.stmtList()) - n.PtrInit().Set(init) + *n.PtrInit() = init return n case ir.ORANGE: @@ -1052,7 +1052,7 @@ func (r *importReader) node() ir.Node { pos := r.pos() init := r.stmtList() n := ir.NewSelectStmt(pos, r.commList()) - n.PtrInit().Set(init) + *n.PtrInit() = init return n case ir.OSWITCH: @@ -1060,7 +1060,7 @@ func (r *importReader) node() ir.Node { init := r.stmtList() x, _ := r.exprsOrNil() n := ir.NewSwitchStmt(pos, x, r.caseList(x)) - n.PtrInit().Set(init) + *n.PtrInit() = init return n // case OCASE: diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 0ee66df2cf..d0922e8508 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -64,7 +64,7 @@ func FuncBody(n *ir.Func) { CheckUnused(n) CheckReturn(n) if base.Errors() > errorsBefore { - n.Body.Set(nil) // type errors; do not compile + n.Body = nil // type errors; do not compile } } @@ -971,9 +971,9 @@ func typecheckargs(n ir.InitNode) { switch n := n.(type) { case *ir.CallExpr: - n.Args.Set(list) + n.Args = list case *ir.ReturnStmt: - n.Results.Set(list) + n.Results = list } n.PtrInit().Append(Stmt(as)) @@ -1687,7 +1687,7 @@ func stringtoruneslit(n *ir.ConvExpr) ir.Node { } nn := ir.NewCompLitExpr(base.Pos, ir.OCOMPLIT, ir.TypeNode(n.Type()), nil) - nn.List.Set(l) + nn.List = l return Expr(nn) } diff --git a/src/cmd/compile/internal/walk/assign.go b/src/cmd/compile/internal/walk/assign.go index 762baa0dd9..7f3e4cc995 100644 --- a/src/cmd/compile/internal/walk/assign.go +++ b/src/cmd/compile/internal/walk/assign.go @@ -264,7 +264,7 @@ func walkReturn(n *ir.ReturnStmt) ir.Node { // move function calls out, to make ascompatee's job easier. walkExprListSafe(n.Results, n.PtrInit()) - n.Results.Set(ascompatee(n.Op(), rl, n.Results, n.PtrInit())) + n.Results = ascompatee(n.Op(), rl, n.Results, n.PtrInit()) return n } walkExprList(n.Results, n.PtrInit()) @@ -281,7 +281,7 @@ func walkReturn(n *ir.ReturnStmt) ir.Node { a := ir.NewAssignStmt(base.Pos, nname, rhs[i]) res[i] = convas(a, n.PtrInit()) } - n.Results.Set(res) + n.Results = res return n } diff --git a/src/cmd/compile/internal/walk/builtin.go b/src/cmd/compile/internal/walk/builtin.go index 13837eeffc..a061181e2f 100644 --- a/src/cmd/compile/internal/walk/builtin.go +++ b/src/cmd/compile/internal/walk/builtin.go @@ -531,7 +531,7 @@ func walkPrint(nn *ir.CallExpr, init *ir.Nodes) ir.Node { t = append(t, n) } t = append(t, ir.NewString("\n")) - nn.Args.Set(t) + nn.Args = t } // Collapse runs of constant strings. @@ -551,7 +551,7 @@ func walkPrint(nn *ir.CallExpr, init *ir.Nodes) ir.Node { i++ } } - nn.Args.Set(t) + nn.Args = t calls := []ir.Node{mkcall("printlock", nil, init)} for i, n := range nn.Args { @@ -653,7 +653,7 @@ func walkPrint(nn *ir.CallExpr, init *ir.Nodes) ir.Node { walkExprList(calls, init) r := ir.NewBlockStmt(base.Pos, nil) - r.List.Set(calls) + r.List = calls return walkStmt(typecheck.Stmt(r)) } diff --git a/src/cmd/compile/internal/walk/closure.go b/src/cmd/compile/internal/walk/closure.go index 62d2a362b1..fcdb43f113 100644 --- a/src/cmd/compile/internal/walk/closure.go +++ b/src/cmd/compile/internal/walk/closure.go @@ -107,7 +107,7 @@ func Closure(fn *ir.Func) { if len(body) > 0 { typecheck.Stmts(body) - fn.Enter.Set(body) + fn.Enter = body fn.SetNeedctxt(true) } } @@ -131,7 +131,7 @@ func walkClosure(clo *ir.ClosureExpr, init *ir.Nodes) ir.Node { clos := ir.NewCompLitExpr(base.Pos, ir.OCOMPLIT, ir.TypeNode(typ), nil) clos.SetEsc(clo.Esc()) - clos.List.Set(append([]ir.Node{ir.NewUnaryExpr(base.Pos, ir.OCFUNC, fn.Nname)}, closureArgs(clo)...)) + clos.List = append([]ir.Node{ir.NewUnaryExpr(base.Pos, ir.OCFUNC, fn.Nname)}, closureArgs(clo)...) addr := typecheck.NodAddr(clos) addr.SetEsc(clo.Esc()) diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go index 7dfac30094..8a56526a36 100644 --- a/src/cmd/compile/internal/walk/expr.go +++ b/src/cmd/compile/internal/walk/expr.go @@ -477,7 +477,7 @@ func walkAddString(n *ir.AddStringExpr, init *ir.Nodes) ir.Node { cat := typecheck.LookupRuntime(fn) r := ir.NewCallExpr(base.Pos, ir.OCALL, cat, nil) - r.Args.Set(args) + r.Args = args r1 := typecheck.Expr(r) r1 = walkExpr(r1, init) r1.SetType(n.Type()) @@ -562,8 +562,8 @@ func walkCall1(n *ir.CallExpr, init *ir.Nodes) { } } - n.Args.Set(tempAssigns) - n.Rargs.Set(args) + n.Args = tempAssigns + n.Rargs = args } // walkDivMod walks an ODIV or OMOD node. diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go index 679b795270..767af07414 100644 --- a/src/cmd/compile/internal/walk/order.go +++ b/src/cmd/compile/internal/walk/order.go @@ -423,7 +423,7 @@ func orderBlock(n *ir.Nodes, free map[string][]*ir.Name) { order.edge() order.stmtList(*n) order.cleanTemp(mark) - n.Set(order.out) + *n = order.out } // exprInPlace orders the side effects in *np and @@ -1233,9 +1233,9 @@ func (o *orderState) expr1(n, lhs ir.Node) ir.Node { // If left-hand side doesn't cause a short-circuit, issue right-hand side. nif := ir.NewIfStmt(base.Pos, r, nil, nil) if n.Op() == ir.OANDAND { - nif.Body.Set(gen) + nif.Body = gen } else { - nif.Else.Set(gen) + nif.Else = gen } o.out = append(o.out, nif) return r @@ -1401,7 +1401,7 @@ func (o *orderState) expr1(n, lhs ir.Node) ir.Node { statics = append(statics, r) } - n.List.Set(statics) + n.List = statics if len(dynamics) == 0 { return n @@ -1448,8 +1448,8 @@ func (o *orderState) as2(n *ir.AssignListStmt) { o.out = append(o.out, n) as := ir.NewAssignListStmt(base.Pos, ir.OAS2, nil, nil) - as.Lhs.Set(left) - as.Rhs.Set(tmplist) + as.Lhs = left + as.Rhs = tmplist o.stmt(typecheck.Stmt(as)) } diff --git a/src/cmd/compile/internal/walk/range.go b/src/cmd/compile/internal/walk/range.go index 3092b71d72..9225c429f0 100644 --- a/src/cmd/compile/internal/walk/range.go +++ b/src/cmd/compile/internal/walk/range.go @@ -429,7 +429,7 @@ func arrayClear(loop *ir.RangeStmt, v1, v2, a ir.Node) ir.Node { // i = len(a) - 1 // } n := ir.NewIfStmt(base.Pos, nil, nil, nil) - n.Body.Set(nil) + n.Body = nil n.Cond = ir.NewBinaryExpr(base.Pos, ir.ONE, ir.NewUnaryExpr(base.Pos, ir.OLEN, a), ir.NewInt(0)) // hp = &a[0] diff --git a/src/cmd/compile/internal/walk/select.go b/src/cmd/compile/internal/walk/select.go index c6e9b71384..776b020155 100644 --- a/src/cmd/compile/internal/walk/select.go +++ b/src/cmd/compile/internal/walk/select.go @@ -22,7 +22,7 @@ func walkSelect(sel *ir.SelectStmt) { init = append(init, walkSelectCases(sel.Cases)...) sel.Cases = nil - sel.Compiled.Set(init) + sel.Compiled = init walkStmtList(sel.Compiled) base.Pos = lno @@ -104,7 +104,7 @@ func walkSelectCases(cases []*ir.CommClause) []ir.Node { n := cas.Comm ir.SetPos(n) r := ir.NewIfStmt(base.Pos, nil, nil, nil) - r.PtrInit().Set(cas.Init()) + *r.PtrInit() = cas.Init() var call ir.Node switch n.Op() { default: @@ -136,8 +136,8 @@ func walkSelectCases(cases []*ir.CommClause) []ir.Node { } r.Cond = typecheck.Expr(call) - r.Body.Set(cas.Body) - r.Else.Set(append(dflt.Init(), dflt.Body...)) + r.Body = cas.Body + r.Else = append(dflt.Init(), dflt.Body...) return []ir.Node{r, ir.NewBranchStmt(base.Pos, ir.OBREAK, nil)} } diff --git a/src/cmd/compile/internal/walk/stmt.go b/src/cmd/compile/internal/walk/stmt.go index 3440c66506..460c0a7c10 100644 --- a/src/cmd/compile/internal/walk/stmt.go +++ b/src/cmd/compile/internal/walk/stmt.go @@ -61,7 +61,7 @@ func walkStmt(n ir.Node) ir.Node { // copy rewrote to a statement list and a temp for the length. // Throw away the temp to avoid plain values as statements. n = ir.NewBlockStmt(n.Pos(), init) - init.Set(nil) + init = nil } if len(init) > 0 { switch n.Op() { @@ -265,7 +265,7 @@ func wrapCall(n *ir.CallExpr, init *ir.Nodes) ir.Node { last := len(n.Args) - 1 if va := n.Args[last]; va.Op() == ir.OSLICELIT { va := va.(*ir.CompLitExpr) - n.Args.Set(append(n.Args[:last], va.List...)) + n.Args = append(n.Args[:last], va.List...) n.IsDDD = false } } -- cgit v1.3 From 87845d14f9822c104cc192c8f7858a2a24d0029f Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sun, 17 Jan 2021 00:30:32 -0800 Subject: [dev.regabi] cmd/compile: add ir.TailCallStmt This CL splits out ORETJMP as a new TailCallStmt node, separate from the other BranchStmt nodes. In doing so, this allows us to change it from identifying a function by *types.Sym to identifying one by directly pointing to the *ir.Func. While here, also rename the operation to OTAILCALL. Passes toolstash -cmp. Change-Id: I273e6ea5d92bf3005ae02fb59b3240a190a6cf1b Reviewed-on: https://go-review.googlesource.com/c/go/+/284227 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/deadcode/deadcode.go | 2 +- src/cmd/compile/internal/escape/escape.go | 4 ++-- src/cmd/compile/internal/inline/inl.go | 2 +- src/cmd/compile/internal/ir/fmt.go | 6 +++--- src/cmd/compile/internal/ir/node.go | 4 ++-- src/cmd/compile/internal/ir/node_gen.go | 22 ++++++++++++++++++++++ src/cmd/compile/internal/ir/op_string.go | 6 +++--- src/cmd/compile/internal/ir/stmt.go | 22 ++++++++++++++++++---- src/cmd/compile/internal/reflectdata/reflect.go | 2 +- src/cmd/compile/internal/ssagen/abi.go | 2 +- src/cmd/compile/internal/ssagen/ssa.go | 6 +++--- src/cmd/compile/internal/typecheck/typecheck.go | 6 +++--- src/cmd/compile/internal/walk/order.go | 2 +- src/cmd/compile/internal/walk/stmt.go | 4 ++-- 14 files changed, 63 insertions(+), 27 deletions(-) (limited to 'src/cmd/compile/internal/deadcode/deadcode.go') diff --git a/src/cmd/compile/internal/deadcode/deadcode.go b/src/cmd/compile/internal/deadcode/deadcode.go index c409320fc4..520203787f 100644 --- a/src/cmd/compile/internal/deadcode/deadcode.go +++ b/src/cmd/compile/internal/deadcode/deadcode.go @@ -75,7 +75,7 @@ func stmts(nn *ir.Nodes) { // might be the target of a goto. See issue 28616. if body := body; len(body) != 0 { switch body[(len(body) - 1)].Op() { - case ir.ORETURN, ir.ORETJMP, ir.OPANIC: + case ir.ORETURN, ir.OTAILCALL, ir.OPANIC: if i > lastLabel { cut = true } diff --git a/src/cmd/compile/internal/escape/escape.go b/src/cmd/compile/internal/escape/escape.go index 26420b820a..5ee6d4f498 100644 --- a/src/cmd/compile/internal/escape/escape.go +++ b/src/cmd/compile/internal/escape/escape.go @@ -534,8 +534,8 @@ func (e *escape) stmt(n ir.Node) { e.stmts(n.Call.Init()) e.call(nil, n.Call, n) - case ir.ORETJMP: - // TODO(mdempsky): What do? esc.go just ignores it. + case ir.OTAILCALL: + // TODO(mdempsky): Treat like a normal call? esc.go used to just ignore it. } } diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 4bb849cdae..143fbe9efe 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -359,7 +359,7 @@ func (v *hairyVisitor) doNode(n ir.Node) error { ir.OGO, ir.ODEFER, ir.ODCLTYPE, // can't print yet - ir.ORETJMP: + ir.OTAILCALL: return errors.New("unhandled op " + n.Op().String()) case ir.OAPPEND: diff --git a/src/cmd/compile/internal/ir/fmt.go b/src/cmd/compile/internal/ir/fmt.go index 68e1bc1569..ee6a62625a 100644 --- a/src/cmd/compile/internal/ir/fmt.go +++ b/src/cmd/compile/internal/ir/fmt.go @@ -378,9 +378,9 @@ func stmtFmt(n Node, s fmt.State) { n := n.(*ReturnStmt) fmt.Fprintf(s, "return %.v", n.Results) - case ORETJMP: - n := n.(*BranchStmt) - fmt.Fprintf(s, "retjmp %v", n.Label) + case OTAILCALL: + n := n.(*TailCallStmt) + fmt.Fprintf(s, "tailcall %v", n.Target) case OINLMARK: n := n.(*InlineMarkStmt) diff --git a/src/cmd/compile/internal/ir/node.go b/src/cmd/compile/internal/ir/node.go index a725307c2c..291e1286bb 100644 --- a/src/cmd/compile/internal/ir/node.go +++ b/src/cmd/compile/internal/ir/node.go @@ -306,8 +306,8 @@ const ( OLINKSYMOFFSET // offset within a name // arch-specific opcodes - ORETJMP // return to other function - OGETG // runtime.getg() (read g pointer) + OTAILCALL // tail call to another function + OGETG // runtime.getg() (read g pointer) OEND ) diff --git a/src/cmd/compile/internal/ir/node_gen.go b/src/cmd/compile/internal/ir/node_gen.go index 8f89c67748..af9ee8d86e 100644 --- a/src/cmd/compile/internal/ir/node_gen.go +++ b/src/cmd/compile/internal/ir/node_gen.go @@ -1227,6 +1227,28 @@ func (n *SwitchStmt) editChildren(edit func(Node) Node) { editNodes(n.Compiled, edit) } +func (n *TailCallStmt) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) } +func (n *TailCallStmt) copy() Node { + c := *n + c.init = copyNodes(c.init) + return &c +} +func (n *TailCallStmt) doChildren(do func(Node) bool) bool { + if doNodes(n.init, do) { + return true + } + if n.Target != nil && do(n.Target) { + return true + } + return false +} +func (n *TailCallStmt) editChildren(edit func(Node) Node) { + editNodes(n.init, edit) + if n.Target != nil { + n.Target = edit(n.Target).(*Name) + } +} + func (n *TypeAssertExpr) Format(s fmt.State, verb rune) { fmtNode(n, s, verb) } func (n *TypeAssertExpr) copy() Node { c := *n diff --git a/src/cmd/compile/internal/ir/op_string.go b/src/cmd/compile/internal/ir/op_string.go index 35196b01ae..15c60baf44 100644 --- a/src/cmd/compile/internal/ir/op_string.go +++ b/src/cmd/compile/internal/ir/op_string.go @@ -157,14 +157,14 @@ func _() { _ = x[ORESULT-146] _ = x[OINLMARK-147] _ = x[OLINKSYMOFFSET-148] - _ = x[ORETJMP-149] + _ = x[OTAILCALL-149] _ = x[OGETG-150] _ = x[OEND-151] } -const _Op_name = "XXXNAMENONAMETYPEPACKLITERALNILADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMAKESLICECOPYMULDIVMODLSHRSHANDANDNOTNEWNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFMETHEXPRSTMTEXPRBLOCKBREAKCASECONTINUEDEFERFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYTSLICEINLCALLEFACEITABIDATASPTRCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKLINKSYMOFFSETRETJMPGETGEND" +const _Op_name = "XXXNAMENONAMETYPEPACKLITERALNILADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMAKESLICECOPYMULDIVMODLSHRSHANDANDNOTNEWNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFMETHEXPRSTMTEXPRBLOCKBREAKCASECONTINUEDEFERFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYTSLICEINLCALLEFACEITABIDATASPTRCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKLINKSYMOFFSETTAILCALLGETGEND" -var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 37, 39, 42, 48, 52, 58, 64, 73, 85, 94, 103, 115, 124, 126, 129, 139, 146, 153, 160, 164, 168, 176, 184, 193, 201, 204, 209, 216, 223, 229, 238, 246, 254, 260, 264, 273, 280, 284, 287, 294, 302, 309, 315, 318, 324, 331, 339, 343, 350, 358, 360, 362, 364, 366, 368, 370, 375, 380, 388, 391, 400, 403, 407, 415, 422, 431, 444, 447, 450, 453, 456, 459, 462, 468, 471, 474, 480, 484, 487, 491, 496, 501, 507, 512, 516, 521, 529, 537, 543, 552, 563, 570, 574, 581, 589, 593, 597, 601, 608, 615, 623, 629, 637, 645, 650, 655, 659, 667, 672, 676, 679, 687, 691, 693, 698, 700, 705, 711, 717, 723, 729, 734, 738, 745, 751, 756, 762, 768, 775, 780, 784, 789, 793, 798, 806, 812, 819, 826, 832, 839, 852, 858, 862, 865} +var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 37, 39, 42, 48, 52, 58, 64, 73, 85, 94, 103, 115, 124, 126, 129, 139, 146, 153, 160, 164, 168, 176, 184, 193, 201, 204, 209, 216, 223, 229, 238, 246, 254, 260, 264, 273, 280, 284, 287, 294, 302, 309, 315, 318, 324, 331, 339, 343, 350, 358, 360, 362, 364, 366, 368, 370, 375, 380, 388, 391, 400, 403, 407, 415, 422, 431, 444, 447, 450, 453, 456, 459, 462, 468, 471, 474, 480, 484, 487, 491, 496, 501, 507, 512, 516, 521, 529, 537, 543, 552, 563, 570, 574, 581, 589, 593, 597, 601, 608, 615, 623, 629, 637, 645, 650, 655, 659, 667, 672, 676, 679, 687, 691, 693, 698, 700, 705, 711, 717, 723, 729, 734, 738, 745, 751, 756, 762, 768, 775, 780, 784, 789, 793, 798, 806, 812, 819, 826, 832, 839, 852, 860, 864, 867} func (i Op) String() string { if i >= Op(len(_Op_index)-1) { diff --git a/src/cmd/compile/internal/ir/stmt.go b/src/cmd/compile/internal/ir/stmt.go index 0358569a1f..c304867e1d 100644 --- a/src/cmd/compile/internal/ir/stmt.go +++ b/src/cmd/compile/internal/ir/stmt.go @@ -144,9 +144,6 @@ func NewBlockStmt(pos src.XPos, list []Node) *BlockStmt { } // A BranchStmt is a break, continue, fallthrough, or goto statement. -// -// For back-end code generation, Op may also be RETJMP (return+jump), -// in which case the label names another function entirely. type BranchStmt struct { miniStmt Label *types.Sym // label if present @@ -154,7 +151,7 @@ type BranchStmt struct { func NewBranchStmt(pos src.XPos, op Op, label *types.Sym) *BranchStmt { switch op { - case OBREAK, OCONTINUE, OFALL, OGOTO, ORETJMP: + case OBREAK, OCONTINUE, OFALL, OGOTO: // ok default: panic("NewBranch " + op.String()) @@ -384,6 +381,23 @@ func NewSwitchStmt(pos src.XPos, tag Node, cases []*CaseClause) *SwitchStmt { return n } +// A TailCallStmt is a tail call statement, which is used for back-end +// code generation to jump directly to another function entirely. +type TailCallStmt struct { + miniStmt + Target *Name +} + +func NewTailCallStmt(pos src.XPos, target *Name) *TailCallStmt { + if target.Op() != ONAME || target.Class != PFUNC { + base.FatalfAt(pos, "tail call to non-func %v", target) + } + n := &TailCallStmt{Target: target} + n.pos = pos + n.op = OTAILCALL + return n +} + // A TypeSwitchGuard is the [Name :=] X.(type) in a type switch. type TypeSwitchGuard struct { miniNode diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index efe863cc3f..fd3e6beaa3 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -1794,7 +1794,7 @@ func methodWrapper(rcvr *types.Type, method *types.Field) *obj.LSym { } as := ir.NewAssignStmt(base.Pos, nthis, typecheck.ConvNop(left, rcvr)) fn.Body.Append(as) - fn.Body.Append(ir.NewBranchStmt(base.Pos, ir.ORETJMP, ir.MethodSym(methodrcvr, method.Sym))) + fn.Body.Append(ir.NewTailCallStmt(base.Pos, method.Nname.(*ir.Name))) } else { fn.SetWrapper(true) // ignore frame for panic+recover matching call := ir.NewCallExpr(base.Pos, ir.OCALL, dot, nil) diff --git a/src/cmd/compile/internal/ssagen/abi.go b/src/cmd/compile/internal/ssagen/abi.go index 274c543ca5..b5da420872 100644 --- a/src/cmd/compile/internal/ssagen/abi.go +++ b/src/cmd/compile/internal/ssagen/abi.go @@ -303,7 +303,7 @@ func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) { var tail ir.Node if tfn.Type().NumResults() == 0 && tfn.Type().NumParams() == 0 && tfn.Type().NumRecvs() == 0 && !(base.Ctxt.Arch.Name == "ppc64le" && base.Ctxt.Flag_dynlink) { - tail = ir.NewBranchStmt(base.Pos, ir.ORETJMP, f.Nname.Sym()) + tail = ir.NewTailCallStmt(base.Pos, f.Nname) } else { call := ir.NewCallExpr(base.Pos, ir.OCALL, f.Nname, nil) call.Args = ir.ParamNames(tfn.Type()) diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index 1cd49a487e..beef0d8234 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -1580,11 +1580,11 @@ func (s *state) stmt(n ir.Node) { b := s.exit() b.Pos = s.lastPos.WithIsStmt() - case ir.ORETJMP: - n := n.(*ir.BranchStmt) + case ir.OTAILCALL: + n := n.(*ir.TailCallStmt) b := s.exit() b.Kind = ssa.BlockRetJmp // override BlockRet - b.Aux = callTargetLSym(n.Label, s.curfn.LSym) + b.Aux = callTargetLSym(n.Target.Sym(), s.curfn.LSym) case ir.OCONTINUE, ir.OBREAK: n := n.(*ir.BranchStmt) diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 5b44a5743f..7881ea308d 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -857,8 +857,8 @@ func typecheck1(n ir.Node, top int) ir.Node { n := n.(*ir.ReturnStmt) return tcReturn(n) - case ir.ORETJMP: - n := n.(*ir.BranchStmt) + case ir.OTAILCALL: + n := n.(*ir.TailCallStmt) return n case ir.OSELECT: @@ -2023,7 +2023,7 @@ func isTermNode(n ir.Node) bool { n := n.(*ir.BlockStmt) return isTermNodes(n.List) - case ir.OGOTO, ir.ORETURN, ir.ORETJMP, ir.OPANIC, ir.OFALL: + case ir.OGOTO, ir.ORETURN, ir.OTAILCALL, ir.OPANIC, ir.OFALL: return true case ir.OFOR, ir.OFORUNTIL: diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go index d34c58009a..e1e9f168bb 100644 --- a/src/cmd/compile/internal/walk/order.go +++ b/src/cmd/compile/internal/walk/order.go @@ -692,7 +692,7 @@ func (o *orderState) stmt(n ir.Node) { ir.OFALL, ir.OGOTO, ir.OLABEL, - ir.ORETJMP: + ir.OTAILCALL: o.out = append(o.out, n) // Special: handle call arguments. diff --git a/src/cmd/compile/internal/walk/stmt.go b/src/cmd/compile/internal/walk/stmt.go index d892b2413f..46a621c2ba 100644 --- a/src/cmd/compile/internal/walk/stmt.go +++ b/src/cmd/compile/internal/walk/stmt.go @@ -136,8 +136,8 @@ func walkStmt(n ir.Node) ir.Node { n := n.(*ir.ReturnStmt) return walkReturn(n) - case ir.ORETJMP: - n := n.(*ir.BranchStmt) + case ir.OTAILCALL: + n := n.(*ir.TailCallStmt) return n case ir.OINLMARK: -- cgit v1.3