]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: enable inlining SELECT
authorWayne Zuo <wdvxdr1123@gmail.com>
Sun, 20 Mar 2022 13:28:46 +0000 (21:28 +0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 25 Mar 2022 22:34:45 +0000 (22:34 +0000)
Change-Id: I90c8e12a0be05d82bf6e147b5249859518f35c14
Reviewed-on: https://go-review.googlesource.com/c/go/+/394074
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Keith Randall <khr@golang.org>

src/cmd/compile/internal/inline/inl.go
test/inline.go

index 716a7fbcd93a25900e204efa575a3a532aabd6fd..be01914d080117c638c113f2ccf94c02af9ad0af 100644 (file)
@@ -358,8 +358,7 @@ func (v *hairyVisitor) doNode(n ir.Node) bool {
                        return true
                }
 
-       case ir.OSELECT,
-               ir.OGO,
+       case ir.OGO,
                ir.ODEFER,
                ir.ODCLTYPE, // can't print yet
                ir.OTAILCALL:
@@ -1310,7 +1309,7 @@ func (subst *inlsubst) node(n ir.Node) ir.Node {
        ir.EditChildren(m, subst.edit)
 
        if subst.newclofn == nil {
-               // Translate any label on FOR, RANGE loops or SWITCH
+               // Translate any label on FOR, RANGE loops, SWITCH or SELECT
                switch m.Op() {
                case ir.OFOR:
                        m := m.(*ir.ForStmt)
@@ -1326,8 +1325,12 @@ func (subst *inlsubst) node(n ir.Node) ir.Node {
                        m := m.(*ir.SwitchStmt)
                        m.Label = translateLabel(m.Label)
                        return m
-               }
 
+               case ir.OSELECT:
+                       m := m.(*ir.SelectStmt)
+                       m.Label = translateLabel(m.Label)
+                       return m
+               }
        }
 
        switch m := m.(type) {
index 2780e10b196c3c904df2bbb26d9cbd1aa1363eb4..95af923a26a9b4794ca8620f5d18a696ed36a6c9 100644 (file)
@@ -11,6 +11,7 @@ package foo
 
 import (
        "runtime"
+       "time"
        "unsafe"
 )
 
@@ -303,3 +304,31 @@ func conv2(v uint64) uint64 { // ERROR "can inline conv2"
 func conv1(v uint64) uint64 { // ERROR "can inline conv1"
        return uint64(uint64(uint64(uint64(uint64(uint64(uint64(uint64(uint64(uint64(uint64(v)))))))))))
 }
+
+func select1(x, y chan bool) int { // ERROR "can inline select1" "x does not escape" "y does not escape"
+       select {
+       case <-x:
+               return 1
+       case <-y:
+               return 2
+       }
+}
+
+func select2(x chan bool) { // ERROR "can inline select2" "x does not escape"
+loop: // test that labeled select can be inlined.
+       select {
+       case <-x:
+               break loop
+       case <-time.After(time.Second): // ERROR "inlining call to time.After"
+       }
+}
+
+func inlineSelect2(x, y chan bool) { // ERROR "x does not escape" "y does not escape"
+loop:
+       for i := 0; i < 5; i++ {
+               if i == 3 {
+                       break loop
+               }
+               select2(x) // ERROR "inlining call to select2" "inlining call to time.After"
+       }
+}