Skip to content

Commit ba6aeb6

Browse files
cuonglmmdempsky
authored andcommitted
cmd/compile: simplify OAS2XXX nodes handle in order
Passes toolstash-check. Updates #23017 Change-Id: I0ae82e28a6e9e732ba2a6aa98f9b35551efcea10 Reviewed-on: https://go-review.googlesource.com/c/go/+/200580 Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 54abb5f commit ba6aeb6

File tree

2 files changed

+24
-43
lines changed

2 files changed

+24
-43
lines changed

src/cmd/compile/internal/gc/order.go

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -562,23 +562,7 @@ func (o *Order) stmt(n *Node) {
562562
o.mapAssign(n)
563563
o.cleanTemp(t)
564564

565-
// Special: make sure key is addressable if needed,
566-
// and make sure OINDEXMAP is not copied out.
567-
case OAS2MAPR:
568-
t := o.markTemp()
569-
o.exprList(n.List)
570-
r := n.Right
571-
r.Left = o.expr(r.Left, nil)
572-
r.Right = o.expr(r.Right, nil)
573-
574-
// See similar conversion for OINDEXMAP below.
575-
_ = mapKeyReplaceStrConv(r.Right)
576-
577-
r.Right = o.mapKeyTemp(r.Left.Type, r.Right)
578-
o.okAs2(n)
579-
o.cleanTemp(t)
580-
581-
// Special: avoid copy of func call n.Rlist.First().
565+
// Special: avoid copy of func call n.Right
582566
case OAS2FUNC:
583567
t := o.markTemp()
584568
o.exprList(n.List)
@@ -588,32 +572,29 @@ func (o *Order) stmt(n *Node) {
588572
o.cleanTemp(t)
589573

590574
// Special: use temporary variables to hold result,
591-
// so that assertI2Tetc can take address of temporary.
575+
// so that runtime can take address of temporary.
592576
// No temporary for blank assignment.
593-
case OAS2DOTTYPE:
577+
//
578+
// OAS2MAPR: make sure key is addressable if needed,
579+
// and make sure OINDEXMAP is not copied out.
580+
case OAS2DOTTYPE, OAS2RECV, OAS2MAPR:
594581
t := o.markTemp()
595582
o.exprList(n.List)
596-
n.Right.Left = o.expr(n.Right.Left, nil) // i in i.(T)
597-
o.okAs2(n)
598-
o.cleanTemp(t)
599583

600-
// Special: use temporary variables to hold result,
601-
// so that chanrecv can take address of temporary.
602-
case OAS2RECV:
603-
t := o.markTemp()
604-
o.exprList(n.List)
605-
n.Right.Left = o.expr(n.Right.Left, nil) // arg to recv
606-
ch := n.Right.Left.Type
607-
tmp1 := o.newTemp(ch.Elem(), types.Haspointers(ch.Elem()))
608-
tmp2 := o.newTemp(types.Types[TBOOL], false)
609-
o.out = append(o.out, n)
610-
r := nod(OAS, n.List.First(), tmp1)
611-
r = typecheck(r, ctxStmt)
612-
o.mapAssign(r)
613-
r = okas(n.List.Second(), tmp2)
614-
r = typecheck(r, ctxStmt)
615-
o.mapAssign(r)
616-
n.List.Set2(tmp1, tmp2)
584+
switch r := n.Right; r.Op {
585+
case ODOTTYPE2, ORECV:
586+
r.Left = o.expr(r.Left, nil)
587+
case OINDEXMAP:
588+
r.Left = o.expr(r.Left, nil)
589+
r.Right = o.expr(r.Right, nil)
590+
// See similar conversion for OINDEXMAP below.
591+
_ = mapKeyReplaceStrConv(r.Right)
592+
r.Right = o.mapKeyTemp(r.Left.Type, r.Right)
593+
default:
594+
Fatalf("order.stmt: %v", r.Op)
595+
}
596+
597+
o.okAs2(n)
617598
o.cleanTemp(t)
618599

619600
// Special: does not save n onto out.
@@ -1310,7 +1291,7 @@ func okas(ok, val *Node) *Node {
13101291
}
13111292

13121293
// as2 orders OAS2XXXX nodes. It creates temporaries to ensure left-to-right assignment.
1313-
// The caller should order the right-hand side of the assignment before calling orderas2.
1294+
// The caller should order the right-hand side of the assignment before calling order.as2.
13141295
// It rewrites,
13151296
// a, b, a = ...
13161297
// as
@@ -1338,7 +1319,7 @@ func (o *Order) as2(n *Node) {
13381319
o.stmt(as)
13391320
}
13401321

1341-
// okAs2 orders OAS2 with ok.
1322+
// okAs2 orders OAS2XXX with ok.
13421323
// Just like as2, this also adds temporaries to ensure left-to-right assignment.
13431324
func (o *Order) okAs2(n *Node) {
13441325
var tmp1, tmp2 *Node

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ opswitch:
705705
n = liststmt(ll)
706706

707707
// x, y = <-c
708-
// orderstmt made sure x is addressable.
708+
// order.stmt made sure x is addressable or blank.
709709
case OAS2RECV:
710710
init.AppendNodes(&n.Ninit)
711711

@@ -720,7 +720,7 @@ opswitch:
720720
}
721721
fn := chanfn("chanrecv2", 2, r.Left.Type)
722722
ok := n.List.Second()
723-
call := mkcall1(fn, ok.Type, init, r.Left, n1)
723+
call := mkcall1(fn, types.Types[TBOOL], init, r.Left, n1)
724724
n = nod(OAS, ok, call)
725725
n = typecheck(n, ctxStmt)
726726

0 commit comments

Comments
 (0)