]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix inlining function has shape in type
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 14 May 2022 09:15:26 +0000 (16:15 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 14 May 2022 15:26:27 +0000 (15:26 +0000)
CL 395854 made inline pass to not inlining function with shape params,
but pass no shape arguments. But it does not consider the case where
function has shape params, but passing zero arguments. In this case, the
un-safe interface conversion that may be applied to a shape argument can
not happen, so it's safe to inline the function.

Fixes #52907

Change-Id: Ifa7b23709bb47b97e27dc1bf32343d92683ef783
Reviewed-on: https://go-review.googlesource.com/c/go/+/406176
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/inline/inl.go
test/fixedbugs/issue52907.go [new file with mode: 0644]

index 7c45f1443beca5be3b3bbf354f0503f5bd914353..ff2780de8256078ffe0c949519dac767988119c4 100644 (file)
@@ -714,8 +714,8 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
                }
        } else {
                // Don't inline a function fn that has shape parameters, but is passed no shape arg.
-               // See comments (1) above, and issue #51909
-               inlineable := false
+               // See comments (1) above, and issue #51909.
+               inlineable := len(n.Args) == 0 // Function has shape in type, with no arguments can always be inlined.
                for _, arg := range n.Args {
                        if arg.Type().HasShape() {
                                inlineable = true
diff --git a/test/fixedbugs/issue52907.go b/test/fixedbugs/issue52907.go
new file mode 100644 (file)
index 0000000..776be7f
--- /dev/null
@@ -0,0 +1,19 @@
+// compile
+
+// 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.
+
+package main
+
+func f[T int](t T) {
+       for true {
+               func() {
+                       t = func() T { return t }()
+               }()
+       }
+}
+
+func main() {
+       f(0)
+}