]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: allow inlining labeled for-statement and switch-statement
authorwdvxdr <wdvxdr1123@gmail.com>
Wed, 13 Oct 2021 11:44:38 +0000 (19:44 +0800)
committerDan Scales <danscales@google.com>
Mon, 18 Oct 2021 15:38:40 +0000 (15:38 +0000)
After CL 349012 and CL 350911, we can fully handle these
labeled statements, so we can allow them when inlining.

Updates #14768

Change-Id: I0ab3fd3f8d7436b49b1aedd946516b33c63f5747
Reviewed-on: https://go-review.googlesource.com/c/go/+/355497
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: David Chase <drchase@google.com>
Trust: Dan Scales <danscales@google.com>

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

index 51270a3315dba78bf9dcc6230677b86eceaac3f6..a2268a5465e020835124e6ae6401874debdd69dc 100644 (file)
@@ -390,27 +390,6 @@ func (v *hairyVisitor) doNode(n ir.Node) bool {
                // These nodes don't produce code; omit from inlining budget.
                return false
 
-       case ir.OFOR, ir.OFORUNTIL:
-               n := n.(*ir.ForStmt)
-               if n.Label != nil {
-                       v.reason = "labeled control"
-                       return true
-               }
-       case ir.OSWITCH:
-               n := n.(*ir.SwitchStmt)
-               if n.Label != nil {
-                       v.reason = "labeled control"
-                       return true
-               }
-       // case ir.ORANGE, ir.OSELECT in "unhandled" above
-
-       case ir.OBREAK, ir.OCONTINUE:
-               n := n.(*ir.BranchStmt)
-               if n.Label != nil {
-                       // Should have short-circuited due to labeled control error above.
-                       base.Fatalf("unexpected labeled break/continue: %v", n)
-               }
-
        case ir.OIF:
                n := n.(*ir.IfStmt)
                if ir.IsConst(n.Cond, constant.Bool) {
index a73c0ba7b1da0f185268f35d76801252744a6d25..599d5233e0f3f2b373c27e56b7d72356cb16e0c4 100644 (file)
@@ -135,8 +135,7 @@ func s1(x int) int { // ERROR "can inline s1"
        return foo() // ERROR "inlining call to s1.func1"
 }
 
-// can't currently inline functions with a break statement
-func switchBreak(x, y int) int {
+func switchBreak(x, y int) int { // ERROR "can inline switchBreak"
        var n int
        switch x {
        case 0:
@@ -218,8 +217,7 @@ func for1(fn func() bool) { // ERROR "can inline for1" "fn does not escape"
        }
 }
 
-// BAD: for2 should be inlineable too.
-func for2(fn func() bool) { // ERROR "fn does not escape"
+func for2(fn func() bool) { // ERROR "can inline for2" "fn does not escape"
 Loop:
        for {
                if fn() {