From f2e6dab04859a3211ce9f5bf5bac9edde0831ce1 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sun, 3 Jan 2021 00:03:28 -0800 Subject: [PATCH] [dev.regabi] cmd/compile: remove walkReturn "common case" path After the previous two optimization CLs, this code path now generates the same code as ascompatee does anyway. So just use that and remove some redundant code. Passes toolstash -cmp. Change-Id: I5e2e5c6dbea64d8e91abe0f2cf51aa5bb86576d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/281154 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/walk/assign.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/cmd/compile/internal/walk/assign.go b/src/cmd/compile/internal/walk/assign.go index 84ba7f0dc5..ec0f60ad93 100644 --- a/src/cmd/compile/internal/walk/assign.go +++ b/src/cmd/compile/internal/walk/assign.go @@ -143,7 +143,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(ir.TakeInit(n)...) - return ir.NewBlockStmt(src.NoXPos, ascompatee(ir.OAS, n.Lhs, n.Rhs, init)) + return ir.NewBlockStmt(src.NoXPos, ascompatee(ir.OAS, n.Lhs, n.Rhs)) } // walkAssignMapRead walks an OAS2MAPR node. @@ -244,20 +244,7 @@ func walkReturn(n *ir.ReturnStmt) ir.Node { dsts[i] = typecheck.AssignExpr(v.Nname.(*ir.Name)) } - if (ir.HasNamedResults(fn) && len(n.Results) > 1) || paramoutheap(fn) { - // General case: For anything tricky, let ascompatee handle - // ordering the assignments correctly. - n.Results = ascompatee(n.Op(), dsts, n.Results, n.PtrInit()) - return n - } - - // Common case: Assignment order doesn't matter. Simply assign to - // each result parameter in order. - var res ir.Nodes - for i, v := range n.Results { - appendWalkStmt(&res, convas(ir.NewAssignStmt(base.Pos, dsts[i], v), &res)) - } - n.Results = res + n.Results = ascompatee(n.Op(), dsts, n.Results) return n } @@ -318,7 +305,7 @@ func ascompatet(nl ir.Nodes, nr *types.Type) []ir.Node { // check assign expression list to // an expression list. called in // expr-list = expr-list -func ascompatee(op ir.Op, nl, nr []ir.Node, init *ir.Nodes) []ir.Node { +func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node { // cannot happen: should have been rejected during type checking if len(nl) != len(nr) { base.Fatalf("assignment operands mismatch: %+v / %+v", ir.Nodes(nl), ir.Nodes(nr)) @@ -413,6 +400,11 @@ func ascompatee(op ir.Op, nl, nr []ir.Node, init *ir.Nodes) []ir.Node { // We can ignore assignments to blank. continue } + if op == ir.ORETURN && types.OrigSym(name.Sym()) == nil { + // We can also ignore assignments to anonymous result + // parameters. These can't appear in expressions anyway. + continue + } assigned.Add(name) } -- 2.48.1