Skip to content

Commit f2e6dab

Browse files
committed
[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 <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]>
1 parent d36a6bf commit f2e6dab

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/cmd/compile/internal/walk/assign.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func walkAssignFunc(init *ir.Nodes, n *ir.AssignListStmt) ir.Node {
143143
// walkAssignList walks an OAS2 node.
144144
func walkAssignList(init *ir.Nodes, n *ir.AssignListStmt) ir.Node {
145145
init.Append(ir.TakeInit(n)...)
146-
return ir.NewBlockStmt(src.NoXPos, ascompatee(ir.OAS, n.Lhs, n.Rhs, init))
146+
return ir.NewBlockStmt(src.NoXPos, ascompatee(ir.OAS, n.Lhs, n.Rhs))
147147
}
148148

149149
// walkAssignMapRead walks an OAS2MAPR node.
@@ -244,20 +244,7 @@ func walkReturn(n *ir.ReturnStmt) ir.Node {
244244
dsts[i] = typecheck.AssignExpr(v.Nname.(*ir.Name))
245245
}
246246

247-
if (ir.HasNamedResults(fn) && len(n.Results) > 1) || paramoutheap(fn) {
248-
// General case: For anything tricky, let ascompatee handle
249-
// ordering the assignments correctly.
250-
n.Results = ascompatee(n.Op(), dsts, n.Results, n.PtrInit())
251-
return n
252-
}
253-
254-
// Common case: Assignment order doesn't matter. Simply assign to
255-
// each result parameter in order.
256-
var res ir.Nodes
257-
for i, v := range n.Results {
258-
appendWalkStmt(&res, convas(ir.NewAssignStmt(base.Pos, dsts[i], v), &res))
259-
}
260-
n.Results = res
247+
n.Results = ascompatee(n.Op(), dsts, n.Results)
261248
return n
262249
}
263250

@@ -318,7 +305,7 @@ func ascompatet(nl ir.Nodes, nr *types.Type) []ir.Node {
318305
// check assign expression list to
319306
// an expression list. called in
320307
// expr-list = expr-list
321-
func ascompatee(op ir.Op, nl, nr []ir.Node, init *ir.Nodes) []ir.Node {
308+
func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node {
322309
// cannot happen: should have been rejected during type checking
323310
if len(nl) != len(nr) {
324311
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 {
413400
// We can ignore assignments to blank.
414401
continue
415402
}
403+
if op == ir.ORETURN && types.OrigSym(name.Sym()) == nil {
404+
// We can also ignore assignments to anonymous result
405+
// parameters. These can't appear in expressions anyway.
406+
continue
407+
}
416408
assigned.Add(name)
417409
}
418410

0 commit comments

Comments
 (0)