aboutsummaryrefslogtreecommitdiff
path: root/test/escape_iface.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-10-28 18:49:10 -0700
committerMatthew Dempsky <mdempsky@google.com>2020-10-29 19:06:32 +0000
commit5cc43c51c9929ce089ce2fc17a0f5631d21cd27d (patch)
treed6da90485c9da69adba6546839390c871e865144 /test/escape_iface.go
parentf2c0c2b90200b470c39a2db821b7c707604fe083 (diff)
downloadgo-5cc43c51c9929ce089ce2fc17a0f5631d21cd27d.tar.gz
go-5cc43c51c9929ce089ce2fc17a0f5631d21cd27d.zip
cmd/compile: early devirtualization of interface method calls
After inlining, add a pass that looks for interface calls where we can statically determine the interface value's concrete type. If such a case is found, insert an explicit type assertion to the concrete type so that escape analysis can see it. Fixes #33160. Change-Id: I36932c691693f0069e34384086d63133e249b06b Reviewed-on: https://go-review.googlesource.com/c/go/+/264837 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'test/escape_iface.go')
-rw-r--r--test/escape_iface.go19
1 files changed, 8 insertions, 11 deletions
diff --git a/test/escape_iface.go b/test/escape_iface.go
index 7b0914cadb..5a232fdbd4 100644
--- a/test/escape_iface.go
+++ b/test/escape_iface.go
@@ -58,11 +58,10 @@ func efaceEscape0() {
sink = v1
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0
v := M0{&i}
- // BAD: v does not escape to heap here
var x M = v
- x.M()
+ x.M() // ERROR "devirtualizing x.M"
}
{
i := 0 // ERROR "moved to heap: i"
@@ -115,11 +114,10 @@ func efaceEscape1() {
sink = v1 // ERROR "v1 escapes to heap"
}
{
- i := 0 // ERROR "moved to heap: i"
+ i := 0
v := M1{&i, 0}
- // BAD: v does not escape to heap here
- var x M = v // ERROR "v escapes to heap"
- x.M()
+ var x M = v // ERROR "v does not escape"
+ x.M() // ERROR "devirtualizing x.M"
}
{
i := 0 // ERROR "moved to heap: i"
@@ -189,11 +187,10 @@ func efaceEscape2() {
_ = ok
}
{
- i := 0 // ERROR "moved to heap: i"
- v := &M2{&i} // ERROR "&M2{...} escapes to heap"
- // BAD: v does not escape to heap here
+ i := 0
+ v := &M2{&i} // ERROR "&M2{...} does not escape"
var x M = v
- x.M()
+ x.M() // ERROR "devirtualizing x.M"
}
{
i := 0 // ERROR "moved to heap: i"