aboutsummaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-07-27 16:19:15 -0700
committerMatthew Dempsky <mdempsky@google.com>2020-08-18 20:06:33 +0000
commitfe23ba4a145ce8465d16ea2a92b9a7e96e15c28e (patch)
treea50c3c2cf3d82df52dfb6ed20245584c991d77a2 /src/reflect
parentd36bc7d78ad226b20056c08fb8bca041e25b3d1d (diff)
downloadgo-fe23ba4a145ce8465d16ea2a92b9a7e96e15c28e.tar.gz
go-fe23ba4a145ce8465d16ea2a92b9a7e96e15c28e.zip
runtime: eliminate scase.kind field
Currently, we include a "kind" field on scase to distinguish the three kinds of cases in a select statement: sends, receives, and defaults. This commit removes by kind field by instead arranging for the compiler to always place sends before receives, and to provide their counts separately. It also passes an explicit "block bool" parameter to avoid needing to include a default case in the array. It's safe to shuffle cases like this because the runtime will randomize the order they're polled in anyway. Fixes #40410. Change-Id: Iaeaed4cf7bddd576d78f2c863bd91a03a5c82df2 Reviewed-on: https://go-review.googlesource.com/c/go/+/245125 Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/all_test.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index ed2f225077..5a12699472 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -1725,6 +1725,14 @@ func TestSelectMaxCases(t *testing.T) {
_, _, _ = Select(sCases)
}
+func TestSelectNop(t *testing.T) {
+ // "select { default: }" should always return the default case.
+ chosen, _, _ := Select([]SelectCase{{Dir: SelectDefault}})
+ if chosen != 0 {
+ t.Fatalf("expected Select to return 0, but got %#v", chosen)
+ }
+}
+
func BenchmarkSelect(b *testing.B) {
channel := make(chan int)
close(channel)