]> Cypherpunks repositories - gostls13.git/commitdiff
gc: remove non-blocking send, receive syntax
authorRuss Cox <rsc@golang.org>
Mon, 31 Jan 2011 23:52:16 +0000 (18:52 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 31 Jan 2011 23:52:16 +0000 (18:52 -0500)
R=ken2
CC=golang-dev
https://golang.org/cl/4126043

src/cmd/gc/builtin.c.boot
src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/runtime.go
src/cmd/gc/sinit.c
src/cmd/gc/typecheck.c
src/cmd/gc/walk.c
src/pkg/runtime/chan.c
test/syntax/chan1.go [new file with mode: 0644]

index 421ce19552351a777aea5db29113f2f48a68cb6d..48f45293fc819ff3cf81f32cd9b1f7cf153d89d9 100644 (file)
@@ -66,10 +66,8 @@ char *runtimeimport =
        "func \"\".mapiter2 (hiter *any) (key any, val any)\n"
        "func \"\".makechan (elem *uint8, hint int64) chan any\n"
        "func \"\".chanrecv1 (hchan <-chan any) any\n"
-       "func \"\".chanrecv2 (hchan <-chan any) (elem any, pres bool)\n"
        "func \"\".chanrecv3 (hchan <-chan any) (elem any, closed bool)\n"
        "func \"\".chansend1 (hchan chan<- any, elem any)\n"
-       "func \"\".chansend2 (hchan chan<- any, elem any) bool\n"
        "func \"\".closechan (hchan any)\n"
        "func \"\".closedchan (hchan any) bool\n"
        "func \"\".selectnbsend (hchan chan<- any, elem any) bool\n"
index b2d025b787f2c5f2d7150c88255076db68de2f71..bf84c12a13aa8dd99ffd3635d8d74655a27fed4e 100644 (file)
@@ -356,7 +356,7 @@ enum
        OARRAY,
        OARRAYBYTESTR, OARRAYRUNESTR,
        OSTRARRAYBYTE, OSTRARRAYRUNE,
-       OAS, OAS2, OAS2MAPW, OAS2FUNC, OAS2RECV, OAS2RECVCLOSED, OAS2MAPR, OAS2DOTTYPE, OASOP,
+       OAS, OAS2, OAS2MAPW, OAS2FUNC, OAS2RECVCLOSED, OAS2MAPR, OAS2DOTTYPE, OASOP,
        OBAD,
        OCALL, OCALLFUNC, OCALLMETH, OCALLINTER,
        OCAP,
@@ -383,7 +383,7 @@ enum
        ONOT, OCOM, OPLUS, OMINUS,
        OOROR,
        OPANIC, OPRINT, OPRINTN,
-       OSEND, OSENDNB,
+       OSEND,
        OSLICE, OSLICEARR, OSLICESTR,
        ORECOVER,
        ORECV,
index 917265758b581ad933d33cff82dc66271db08ac1..1060fdd2bf22b061cf9a9fba6e59d216b5473531 100644 (file)
@@ -764,6 +764,7 @@ expr:
        {
                $$ = nod(ORSH, $1, $3);
        }
+       /* not an expression anymore, but left in so we can give a good error */
 |      expr LCOMM expr
        {
                $$ = nod(OSEND, $1, $3);
index d7ab17f1ce015ed20a629f1ff75962cf05306ebc..bf7d045c049a3ec4dc79014c2ea9d4f4287bcf24 100644 (file)
@@ -92,10 +92,8 @@ func mapiter2(hiter *any) (key any, val any)
 // *byte is really *runtime.Type
 func makechan(elem *byte, hint int64) (hchan chan any)
 func chanrecv1(hchan <-chan any) (elem any)
-func chanrecv2(hchan <-chan any) (elem any, pres bool)
 func chanrecv3(hchan <-chan any) (elem any, closed bool)
 func chansend1(hchan chan<- any, elem any)
-func chansend2(hchan chan<- any, elem any) (pres bool)
 func closechan(hchan any)
 func closedchan(hchan any) bool
 
index 44e33dae90f861864d4f6a2a3bd153eab3f57888..31781646d1bfd112d8989cd41e8b55d57d2d09f7 100644 (file)
@@ -94,7 +94,6 @@ init1(Node *n, NodeList **out)
                case OAS2FUNC:
                case OAS2MAPR:
                case OAS2DOTTYPE:
-               case OAS2RECV:
                case OAS2RECVCLOSED:
                        if(n->defn->initorder)
                                break;
index 8e8f8da29c936b57f5f627d369f1d71adb20ea9d..931d0327a4e88c61179c1dd789c95f5f29c70f52 100644 (file)
@@ -668,10 +668,7 @@ reswitch:
                goto ret;
 
        case OSEND:
-               if(0 && top == Erv) {
-                       // can happen because grammar for if header accepts
-                       // simple_stmt for condition.  Falling through would give
-                       // an error "c <- v used as value" but we can do better.
+               if(top & Erv) {
                        yyerror("send statement %#N used as value; use select for non-blocking send", n);
                        goto error;
                }
@@ -698,10 +695,6 @@ reswitch:
                // TODO: more aggressive
                n->etype = 0;
                n->type = T;
-               if(top & Erv) {
-                       n->op = OSENDNB;
-                       n->type = types[TBOOL];
-               }
                goto ret;
 
        case OSLICE:
@@ -2383,8 +2376,6 @@ typecheckas2(Node *n)
                        n->op = OAS2MAPR;
                        goto common;
                case ORECV:
-                       n->op = OAS2RECV;
-                       goto common;
                        yyerror("cannot use multiple-value assignment for non-blocking receive; use select");
                        goto out;
                case ODOTTYPE:
index 8b89d9ee49a2eefe2c70262e68be2a23260ba006..b32b6fff5c828ef24dbe65c4b9bb3934cf9f4542 100644 (file)
@@ -403,7 +403,6 @@ walkstmt(Node **np)
        case OAS:
        case OAS2:
        case OAS2DOTTYPE:
-       case OAS2RECV:
        case OAS2RECVCLOSED:
        case OAS2FUNC:
        case OAS2MAPW:
@@ -823,19 +822,6 @@ walkexpr(Node **np, NodeList **init)
                n = liststmt(concat(concat(list1(r), ll), lpost));
                goto ret;
 
-       case OAS2RECV:
-               // a,b = <-c
-               *init = concat(*init, n->ninit);
-               n->ninit = nil;
-               r = n->rlist->n;
-               walkexprlistsafe(n->list, init);
-               walkexpr(&r->left, init);
-               fn = chanfn("chanrecv2", 2, r->left->type);
-               r = mkcall1(fn, getoutargx(fn->type), init, r->left);
-               n->rlist->n = r;
-               n->op = OAS2FUNC;
-               goto as2func;
-
        case OAS2RECVCLOSED:
                // a = <-c; b = closed(c) but atomic
                *init = concat(*init, n->ninit);
@@ -1421,10 +1407,6 @@ walkexpr(Node **np, NodeList **init)
                n = mkcall1(chanfn("chansend1", 2, n->left->type), T, init, n->left, n->right);
                goto ret;
 
-       case OSENDNB:
-               n = mkcall1(chanfn("chansend2", 2, n->left->type), n->type, init, n->left, n->right);
-               goto ret;
-
        case OCLOSURE:
                n = walkclosure(n, init);
                goto ret;
index f3b804df447d8faf6aad986355d5f941c2b8acbc..8d3ac2ca4f1c53741a1e490cd7dcf9b6da07fc73 100644 (file)
@@ -402,25 +402,6 @@ runtime·chansend1(Hchan* c, ...)
        runtime·chansend(c, ae, nil);
 }
 
-// chansend2(hchan *chan any, elem any) (pres bool);
-#pragma textflag 7
-void
-runtime·chansend2(Hchan* c, ...)
-{
-       int32 o;
-       byte *ae, *ap;
-
-       if(c == nil)
-               runtime·panicstring("send to nil channel");
-
-       o = runtime·rnd(sizeof(c), c->elemalign);
-       ae = (byte*)&c + o;
-       o = runtime·rnd(o+c->elemsize, Structrnd);
-       ap = (byte*)&c + o;
-
-       runtime·chansend(c, ae, ap);
-}
-
 // chanrecv1(hchan *chan any) (elem any);
 #pragma textflag 7
 void
@@ -435,28 +416,6 @@ runtime·chanrecv1(Hchan* c, ...)
        runtime·chanrecv(c, ae, nil, nil);
 }
 
-// chanrecv2(hchan *chan any) (elem any, pres bool);
-#pragma textflag 7
-void
-runtime·chanrecv2(Hchan* c, ...)
-{
-       int32 o;
-       byte *ae, *ap;
-
-       if(c == nil)
-               runtime·panicstring("receive from nil channel");
-
-       o = runtime·rnd(sizeof(c), Structrnd);
-       ae = (byte*)&c + o;
-       o = runtime·rnd(o+c->elemsize, 1);
-       ap = (byte*)&c + o;
-
-       runtime·chanrecv(c, ae, ap, nil);
-       
-       if(!*ap)
-               c->elemalg->copy(c->elemsize, ae, nil);
-}
-
 // chanrecv3(hchan *chan any) (elem any, closed bool);
 #pragma textflag 7
 void
diff --git a/test/syntax/chan1.go b/test/syntax/chan1.go
new file mode 100644 (file)
index 0000000..9c12e5e
--- /dev/null
@@ -0,0 +1,17 @@
+// errchk $G -e $D/$F.go
+
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+var c chan int
+var v int
+
+func main() {
+       if c <- v { // ERROR "send statement.*value.*select"
+       }
+}
+
+var _ = c <- v // ERROR "send statement.*value.*select"