aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorYoulin Feng <fengyoulin@live.com>2024-10-08 12:49:30 +0800
committerGopher Robot <gobot@golang.org>2024-10-25 02:56:11 +0000
commit711552e98acbfda7e974dacf4e3a0a8f8dcaa371 (patch)
tree07f46ffb28a9cdbcf3a1c6f42ffac805ec407b58 /test/codegen
parent15c558016088d6aaf103b4f0fd2b716a4573e5a2 (diff)
downloadgo-711552e98acbfda7e974dacf4e3a0a8f8dcaa371.tar.xz
cmd/compile: optimize type switch for a single runtime known type with a case var
Change-Id: I03ba70076d6dd3c0b9624d14699b7dd91a3c0e9b Reviewed-on: https://go-review.googlesource.com/c/go/+/618476 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/typeswitch.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/test/codegen/typeswitch.go b/test/codegen/typeswitch.go
index 495853ed3c..93f8e84269 100644
--- a/test/codegen/typeswitch.go
+++ b/test/codegen/typeswitch.go
@@ -37,11 +37,31 @@ func swGYZ[T any](a Ig[T]) {
t.Y()
case Iz: // amd64:-".*typeAssert"
t.Z()
- case interface{ G() T }: // amd64:-".*typeAssert",".*assertE2I"
+ case interface{ G() T }: // amd64:-".*typeAssert",-".*assertE2I\\(",".*assertE2I2"
+ t.G()
+ }
+}
+
+func swE2G[T any](a any) {
+ switch t := a.(type) {
+ case Iy:
+ t.Y()
+ case Ig[T]: // amd64:-".*assertE2I\\(",".*assertE2I2"
+ t.G()
+ }
+}
+
+func swI2G[T any](a Ix) {
+ switch t := a.(type) {
+ case Iy:
+ t.Y()
+ case Ig[T]: // amd64:-".*assertE2I\\(",".*assertE2I2"
t.G()
}
}
func swCaller() {
swGYZ[int]((Ig[int])(nil))
+ swE2G[int]((Ig[int])(nil))
+ swI2G[int]((Ix)(nil))
}