Skip to content

Commit

Permalink
cmd/compile/internal/gc: cleanup walkselectcases slightly
Browse files Browse the repository at this point in the history
Remove some unnecessary code. Most significantly, we can skip testing
"if ch == nil { block() }", because this is already the semantics
implied by normal send/receive operations.

Updates #40410.

Change-Id: I4acd33383cc876719fc3b998d85244d4ac1ff9d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/245126
Run-TryBot: Matthew Dempsky <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Cuong Manh Le <[email protected]>
  • Loading branch information
mdempsky committed Aug 18, 2020
1 parent fe23ba4 commit a401718
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/cmd/compile/internal/gc/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,14 @@ func walkselectcases(cases *Nodes) []*Node {
n := cas.Left
l = append(l, n.Ninit.Slice()...)
n.Ninit.Set(nil)
var ch *Node
switch n.Op {
default:
Fatalf("select %v", n.Op)

// ok already
case OSEND:
ch = n.Left
// already ok

case OSELRECV, OSELRECV2:
ch = n.Right.Left
if n.Op == OSELRECV || n.List.Len() == 0 {
if n.Left == nil {
n = n.Right
Expand All @@ -157,16 +154,7 @@ func walkselectcases(cases *Nodes) []*Node {
n = typecheck(n, ctxStmt)
}

// if ch == nil { block() }; n;
a := nod(OIF, nil, nil)

a.Left = nod(OEQ, ch, nodnil())
var ln Nodes
ln.Set(l)
a.Nbody.Set1(mkcall("block", nil, &ln))
l = ln.Slice()
a = typecheck(a, ctxStmt)
l = append(l, a, n)
l = append(l, n)
}

l = append(l, cas.Nbody.Slice()...)
Expand Down Expand Up @@ -223,8 +211,6 @@ func walkselectcases(cases *Nodes) []*Node {

case OSELRECV:
// if selectnbrecv(&v, c) { body } else { default body }
r = nod(OIF, nil, nil)
r.Ninit.Set(cas.Ninit.Slice())
ch := n.Right.Left
elem := n.Left
if elem == nil {
Expand All @@ -234,8 +220,6 @@ func walkselectcases(cases *Nodes) []*Node {

case OSELRECV2:
// if selectnbrecv2(&v, &received, c) { body } else { default body }
r = nod(OIF, nil, nil)
r.Ninit.Set(cas.Ninit.Slice())
ch := n.Right.Left
elem := n.Left
if elem == nil {
Expand Down

0 comments on commit a401718

Please sign in to comment.