1
0
mirror of https://github.com/golang/go synced 2024-11-23 19:30:05 -07:00

cmd/compile/internal/gc: cleanup walkselectcases slightly

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 <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2020-07-27 16:45:48 -07:00
parent fe23ba4a14
commit a401718575

View File

@ -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
@ -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()...)
@ -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 {
@ -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 {