aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-08-18 05:20:16 -0700
committerMatthew Dempsky <mdempsky@google.com>2022-08-18 17:26:40 +0000
commit52016be3f4e6deba54020ad8c969f1e2dba1eee3 (patch)
treef21300cf8800232712e559cd4068b4690d5edeb6 /test/typeparam
parentd6294e00f029d93b8552827bce1f24f67458d3f2 (diff)
downloadgo-52016be3f4e6deba54020ad8c969f1e2dba1eee3.tar.xz
cmd/compile: enable more inlining for unified IR
The non-unified frontend had repeated issues with inlining and generics (#49309, #51909, #52907), which led us to substantially restrict inlining when shape types were present. However, these issues are evidently not present in unified IR's inliner, and the safety restrictions added for the non-unified frontend can simply be disabled in unified mode. Fixes #54497. Change-Id: I8e6ac9f3393c588bfaf14c6452891b9640a9d1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/424775 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'test/typeparam')
-rw-r--r--test/typeparam/issue49309.go1
-rw-r--r--test/typeparam/issue54497.go19
2 files changed, 20 insertions, 0 deletions
diff --git a/test/typeparam/issue49309.go b/test/typeparam/issue49309.go
index 265e0bf525..16c97cd451 100644
--- a/test/typeparam/issue49309.go
+++ b/test/typeparam/issue49309.go
@@ -18,6 +18,7 @@ func myfunc(c string) {
//go:noinline
func test2(a interface{}) {
+ _ = a.(string)
}
func main() {
diff --git a/test/typeparam/issue54497.go b/test/typeparam/issue54497.go
new file mode 100644
index 0000000000..1b24cd9afb
--- /dev/null
+++ b/test/typeparam/issue54497.go
@@ -0,0 +1,19 @@
+// errorcheck -0 -m
+
+// Copyright 2022 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.
+
+// Test that inlining works with generic functions.
+
+package testcase
+
+type C interface{ ~uint | ~uint32 | ~uint64 }
+
+func isAligned[T C](x, y T) bool { // ERROR "can inline isAligned\[uint\]" "can inline isAligned\[go\.shape\.uint\]" "inlining call to isAligned\[go\.shape\.uint\]"
+ return x%y == 0
+}
+
+func foo(x uint) bool { // ERROR "can inline foo"
+ return isAligned(x, 64) // ERROR "inlining call to isAligned\[go\.shape\.uint\]"
+}