diff options
author | Hugues Bruant <hugues.bruant@gmail.com> | 2017-09-18 14:54:10 -0700 |
---|---|---|
committer | Daniel Martà <mvdan@mvdan.cc> | 2017-10-11 22:32:36 +0000 |
commit | 4f70a2a699d23bb47eae36c5170086688d2fa764 (patch) | |
tree | d764c2417d55ecf69bd8ae20822e9c5fafff9893 /test/escape4.go | |
parent | 44d9e96da9b7625be81f2c7eacf73fcc609874ce (diff) | |
download | go-4f70a2a699d23bb47eae36c5170086688d2fa764.tar.gz go-4f70a2a699d23bb47eae36c5170086688d2fa764.zip |
cmd/compile: inline calls to local closures
Calls to a closure held in a local, non-escaping,
variable can be inlined, provided the closure body
can be inlined and the variable is never written to.
The current implementation has the following limitations:
- closures with captured variables are not inlined because
doing so naively triggers invariant violation in the SSA
phase
- re-assignment check is currently approximated by checking
the Addrtaken property of the variable which should be safe
but may miss optimization opportunities if the address is
not used for a write before the invocation
Updates #15561
Change-Id: I508cad5d28f027bd7e933b1f793c14dcfef8b5a1
Reviewed-on: https://go-review.googlesource.com/65071
Run-TryBot: Daniel Martà <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hugues Bruant <hugues.bruant@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/escape4.go')
-rw-r--r-- | test/escape4.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/test/escape4.go b/test/escape4.go index 69a54ac721..22a37c1d0a 100644 --- a/test/escape4.go +++ b/test/escape4.go @@ -22,9 +22,9 @@ func f1() { // Escape analysis used to miss inlined code in closures. - func() { // ERROR "func literal does not escape" "can inline f1.func1" - p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x" - }() + func() { // ERROR "can inline f1.func1" + p = alloc(3) // ERROR "inlining call to alloc" + }() // ERROR "inlining call to f1.func1" "inlining call to alloc" "&x escapes to heap" "moved to heap: x" f = func() { // ERROR "func literal escapes to heap" "can inline f1.func2" p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x" |