-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile: use new for loop semantics for Go 1.22+ compilations
This includes version-dependent support for GOEXPERIMENT and -d=loopvar, -d=loopvarhash, to allow testing/porting of old code. Includes tests of downgrade (1.22 -> 1.21) and upgrade (1.21 -> 1.22) based on //go:build lines (while running a 1.22 build/compiler). Change-Id: Idd3be61a2b46acec33c7e7edac0924158cc726b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/508819 Run-TryBot: David Chase <[email protected]> Reviewed-by: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
Showing
7 changed files
with
238 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2023 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. | ||
|
||
//go:build go1.21 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
var is []func() int | ||
|
||
func inline(j, k int) []*int { | ||
var a []*int | ||
for private := j; private < k; private++ { | ||
a = append(a, &private) | ||
} | ||
return a | ||
|
||
} | ||
|
||
//go:noinline | ||
func notinline(j, k int) ([]*int, *int) { | ||
for shared := j; shared < k; shared++ { | ||
if shared == k/2 { | ||
// want the call inlined, want "private" in that inline to be transformed, | ||
// (believe it ends up on init node of the return). | ||
// but do not want "shared" transformed, | ||
return inline(j, k), &shared | ||
} | ||
} | ||
return nil, &j | ||
} | ||
|
||
func main() { | ||
a, p := notinline(2, 9) | ||
fmt.Printf("a[0]=%d,*p=%d\n", *a[0], *p) | ||
if *a[0] != 2 { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2023 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. | ||
|
||
//go:build go1.22 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
var is []func() int | ||
|
||
func inline(j, k int) []*int { | ||
var a []*int | ||
for private := j; private < k; private++ { | ||
a = append(a, &private) | ||
} | ||
return a | ||
|
||
} | ||
|
||
//go:noinline | ||
func notinline(j, k int) ([]*int, *int) { | ||
for shared := j; shared < k; shared++ { | ||
if shared == k/2 { | ||
// want the call inlined, want "private" in that inline to be transformed, | ||
// (believe it ends up on init node of the return). | ||
// but do not want "shared" transformed, | ||
return inline(j, k), &shared | ||
} | ||
} | ||
return nil, &j | ||
} | ||
|
||
func main() { | ||
a, p := notinline(2, 9) | ||
fmt.Printf("a[0]=%d,*p=%d\n", *a[0], *p) | ||
if *a[0] != 2 { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters