aboutsummaryrefslogtreecommitdiff
path: root/test/inline.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2020-12-01 14:48:03 -0800
committerDan Scales <danscales@google.com>2021-01-20 22:53:32 +0000
commit1760d736f61265b3c78a6a48f2e1904341806643 (patch)
treefbf7575c435f30ae41e97589adeca569cbe0225e /test/inline.go
parent92cb157cf3aa51d28e441dbb2b671795f22140f8 (diff)
downloadgo-1760d736f61265b3c78a6a48f2e1904341806643.tar.gz
go-1760d736f61265b3c78a6a48f2e1904341806643.zip
[dev.regabi] cmd/compile: exporting, importing, and inlining functions with OCLOSURE
I have exporting, importing, and inlining of functions with closures working in all cases (issue #28727). all.bash runs successfully without errors. Approach: - Write out the Func type, Dcls, ClosureVars, and Body when exporting an OCLOSURE. - When importing an OCLOSURE, read in the type, dcls, closure vars, and body, and then do roughly equivalent code to (*noder).funcLit - During inlining of a closure within inlined function, create new nodes for all params and local variables (including closure variables), so they can have a new Curfn and some other field values. Must substitute not only on the Nbody of the closure, but also the Type, Cvars, and Dcl fields. Fixes #28727 Change-Id: I4da1e2567c3fa31a5121afbe82dc4e5ee32b3170 Reviewed-on: https://go-review.googlesource.com/c/go/+/283112 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com>
Diffstat (limited to 'test/inline.go')
-rw-r--r--test/inline.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/test/inline.go b/test/inline.go
index d754f06e03..37965c0d9d 100644
--- a/test/inline.go
+++ b/test/inline.go
@@ -58,7 +58,7 @@ func _() int { // ERROR "can inline _"
var somethingWrong error
// local closures can be inlined
-func l(x, y int) (int, int, error) {
+func l(x, y int) (int, int, error) { // ERROR "can inline l"
e := func(err error) (int, int, error) { // ERROR "can inline l.func1" "func literal does not escape" "leaking param: err to result"
return 0, 0, err
}
@@ -90,19 +90,19 @@ func n() int {
// make sure assignment inside closure is detected
func o() int {
foo := func() int { return 1 } // ERROR "can inline o.func1" "func literal does not escape"
- func(x int) { // ERROR "func literal does not escape"
+ func(x int) { // ERROR "can inline o.func2"
if x > 10 {
- foo = func() int { return 2 } // ERROR "can inline o.func2" "func literal escapes"
+ foo = func() int { return 2 } // ERROR "can inline o.func2"
}
- }(11)
+ }(11) // ERROR "func literal does not escape" "inlining call to o.func2"
return foo()
}
-func p() int {
+func p() int { // ERROR "can inline p"
return func() int { return 42 }() // ERROR "can inline p.func1" "inlining call to p.func1"
}
-func q(x int) int {
+func q(x int) int { // ERROR "can inline q"
foo := func() int { return x * 2 } // ERROR "can inline q.func1" "func literal does not escape"
return foo() // ERROR "inlining call to q.func1"
}
@@ -111,15 +111,15 @@ func r(z int) int {
foo := func(x int) int { // ERROR "can inline r.func1" "func literal does not escape"
return x + z
}
- bar := func(x int) int { // ERROR "func literal does not escape"
- return x + func(y int) int { // ERROR "can inline r.func2.1"
+ bar := func(x int) int { // ERROR "func literal does not escape" "can inline r.func2"
+ return x + func(y int) int { // ERROR "can inline r.func2.1" "can inline r.func3"
return 2*y + x*z
}(x) // ERROR "inlining call to r.func2.1"
}
- return foo(42) + bar(42) // ERROR "inlining call to r.func1"
+ return foo(42) + bar(42) // ERROR "inlining call to r.func1" "inlining call to r.func2" "inlining call to r.func3"
}
-func s0(x int) int {
+func s0(x int) int { // ERROR "can inline s0"
foo := func() { // ERROR "can inline s0.func1" "func literal does not escape"
x = x + 1
}
@@ -127,7 +127,7 @@ func s0(x int) int {
return x
}
-func s1(x int) int {
+func s1(x int) int { // ERROR "can inline s1"
foo := func() int { // ERROR "can inline s1.func1" "func literal does not escape"
return x
}