]> Cypherpunks repositories - gostls13.git/commitdiff
gc: empty select
authorRuss Cox <rsc@golang.org>
Tue, 3 Aug 2010 08:07:57 +0000 (01:07 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 3 Aug 2010 08:07:57 +0000 (01:07 -0700)
R=ken2
CC=golang-dev
https://golang.org/cl/1871057

src/cmd/gc/select.c
src/pkg/runtime/chan.c
test/chan/select3.go

index 9cba01fa51e0ebfc6ebccf073a9dc578b7e75cf1..2fa435316543c41f4d53a62bd7dbcf5638090ada 100644 (file)
@@ -68,8 +68,6 @@ typecheckselect(Node *sel)
                typechecklist(ncase->nbody, Etop);
        }
        sel->xoffset = count;
-       if(count == 0)
-               yyerror("empty select");
        lineno = lno;
 }
 
@@ -91,7 +89,7 @@ walkselect(Node *sel)
        typecheck(&r, Etop);
        init = list(init, r);
 
-       if(sel->list == nil)
+       if(sel->list == nil && sel->xoffset != 0)
                fatal("double walkselect");     // already rewrote
 
        // register cases
index 9e88e824a4b584ce902565b5a9e9c00d66314751..16c02e8e78b9e404060b7598bce5b73b10fef3e4 100644 (file)
@@ -631,9 +631,11 @@ void
                printf("select: sel=%p\n", sel);
 
        if(sel->ncase < 2) {
-               if(sel->ncase < 1)
-                       throw("select: no cases");
-               // make special case of one.
+               if(sel->ncase < 1) {
+                       g->status = Gwaiting;   // forever
+                       gosched();
+               }
+               // TODO: make special case of one.
        }
 
        // select a (relative) prime
index d4f7ebcec0896cfc6325d268def373fc3ce606b4..a1a2ef50b56ed38ca935e3bf013406728779c41b 100644 (file)
@@ -112,38 +112,33 @@ func main() {
                <-ch
        })
 
-       // TODO(gri) remove this if once 6g accepts empty selects
-       enabled := false
-       if enabled {
-               // empty selects always block
-               testBlock(always, func() {
-                       select {
-                       case <-make(chan int): // remove this once 6g accepts empty selects
-                       }
-               })
+       // empty selects always block
+       testBlock(always, func() {
+               select {
+               }
+       })
 
-               // selects with only nil channels always block
-               testBlock(always, func() {
-                       select {
-                       case <-nilch:
-                               unreachable()
-                       }
-               })
-               testBlock(always, func() {
-                       select {
-                       case nilch <- 7:
-                               unreachable()
-                       }
-               })
-               testBlock(always, func() {
-                       select {
-                       case <-nilch:
-                               unreachable()
-                       case nilch <- 7:
-                               unreachable()
-                       }
-               })
-       }
+       // selects with only nil channels always block
+       testBlock(always, func() {
+               select {
+               case <-nilch:
+                       unreachable()
+               }
+       })
+       testBlock(always, func() {
+               select {
+               case nilch <- 7:
+                       unreachable()
+               }
+       })
+       testBlock(always, func() {
+               select {
+               case <-nilch:
+                       unreachable()
+               case nilch <- 7:
+                       unreachable()
+               }
+       })
 
        // selects with non-ready non-nil channels always block
        testBlock(always, func() {