diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-08-03 11:36:24 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-08-03 16:40:00 -0700 |
commit | e435e72ad713cadd661072427588ec1c777c04e3 (patch) | |
tree | 7b5fc4228c17022dccb00087e230a45aedcca017 /libgo | |
parent | compiler: check slice to pointer-to-array conversion element type (diff) | |
download | gcc-e435e72ad713cadd661072427588ec1c777c04e3.tar.gz gcc-e435e72ad713cadd661072427588ec1c777c04e3.tar.bz2 gcc-e435e72ad713cadd661072427588ec1c777c04e3.tar.xz |
compile, runtime: make selectnbrecv return two values
The only different between selectnbrecv and selectnbrecv2 is the later
set the input pointer value by second return value from chanrecv.
So by making selectnbrecv return two values from chanrecv, we can get
rid of selectnbrecv2, the compiler can now call only selectnbrecv and
generate simpler code.
This is the gofrontend version of https://golang.org/cl/292890.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/339529
Diffstat (limited to 'libgo')
-rw-r--r-- | libgo/go/runtime/chan.go | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/libgo/go/runtime/chan.go b/libgo/go/runtime/chan.go index 7878a8fe012..e3d0ad5acbe 100644 --- a/libgo/go/runtime/chan.go +++ b/libgo/go/runtime/chan.go | |||
@@ -33,7 +33,6 @@ import ( | |||
33 | //go:linkname closechan | 33 | //go:linkname closechan |
34 | //go:linkname selectnbsend | 34 | //go:linkname selectnbsend |
35 | //go:linkname selectnbrecv | 35 | //go:linkname selectnbrecv |
36 | //go:linkname selectnbrecv2 | ||
37 | 36 | ||
38 | const ( | 37 | const ( |
39 | maxAlign = 8 | 38 | maxAlign = 8 |
@@ -712,28 +711,6 @@ func selectnbsend(c *hchan, elem unsafe.Pointer) (selected bool) { | |||
712 | // compiler implements | 711 | // compiler implements |
713 | // | 712 | // |
714 | // select { | 713 | // select { |
715 | // case v = <-c: | ||
716 | // ... foo | ||
717 | // default: | ||
718 | // ... bar | ||
719 | // } | ||
720 | // | ||
721 | // as | ||
722 | // | ||
723 | // if selectnbrecv(&v, c) { | ||
724 | // ... foo | ||
725 | // } else { | ||
726 | // ... bar | ||
727 | // } | ||
728 | // | ||
729 | func selectnbrecv(elem unsafe.Pointer, c *hchan) (selected bool) { | ||
730 | selected, _ = chanrecv(c, elem, false) | ||
731 | return | ||
732 | } | ||
733 | |||
734 | // compiler implements | ||
735 | // | ||
736 | // select { | ||
737 | // case v, ok = <-c: | 714 | // case v, ok = <-c: |
738 | // ... foo | 715 | // ... foo |
739 | // default: | 716 | // default: |
@@ -742,16 +719,14 @@ func selectnbrecv(elem unsafe.Pointer, c *hchan) (selected bool) { | |||
742 | // | 719 | // |
743 | // as | 720 | // as |
744 | // | 721 | // |
745 | // if c != nil && selectnbrecv2(&v, &ok, c) { | 722 | // if selected, ok = selectnbrecv(&v, c); selected { |
746 | // ... foo | 723 | // ... foo |
747 | // } else { | 724 | // } else { |
748 | // ... bar | 725 | // ... bar |
749 | // } | 726 | // } |
750 | // | 727 | // |
751 | func selectnbrecv2(elem unsafe.Pointer, received *bool, c *hchan) (selected bool) { | 728 | func selectnbrecv(elem unsafe.Pointer, c *hchan) (selected, received bool) { |
752 | // TODO(khr): just return 2 values from this function, now that it is in Go. | 729 | return chanrecv(c, elem, false) |
753 | selected, *received = chanrecv(c, elem, false) | ||
754 | return | ||
755 | } | 730 | } |
756 | 731 | ||
757 | //go:linkname reflect_chansend reflect.chansend | 732 | //go:linkname reflect_chansend reflect.chansend |