]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: tighten the condition for inlining shape/non-shape function
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sun, 15 May 2022 01:05:41 +0000 (08:05 +0700)
committerGopher Robot <gobot@golang.org>
Tue, 17 May 2022 00:58:22 +0000 (00:58 +0000)
CL 395854 made inline pass to not inlining function with shape params,
but pass no shape arguments. This is intended to be the reverse case of
CL 361260.

However, CL 361260 is using wider condition than necessary. Though it
only needs to check against function parameters, it checks whether the
function type has no shape. It does not cause any issue, because
!fn.Type().HasShape() implies !fn.Type().Params().HasShape().

But for the reverse case, it's not true. Function may have shape type,
but has no shape arguments. Thus, we must tighten the condition to
explicitly check against the function parameters only.

Fixes #52907

Change-Id: Ib87e87ff767c31d99d5b36aa4a6c1d8baf32746d
Reviewed-on: https://go-review.googlesource.com/c/go/+/406475
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>

src/cmd/compile/internal/inline/inl.go
test/fixedbugs/issue52907.go

index ff2780de8256078ffe0c949519dac767988119c4..9ef016ab73f0a622fc8adddb86f3c9e7e324a2d8 100644 (file)
@@ -701,13 +701,15 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
        // apparent when we first created the instantiation of the generic function.
        // We can't handle this if we actually do the inlining, since we want to know
        // all interface conversions immediately after stenciling. So, we avoid
-       // inlining in this case. See #49309. (1)
-       if !fn.Type().HasShape() {
+       // inlining in this case, see issue #49309. (1)
+       //
+       // See discussion on go.dev/cl/406475 for more background.
+       if !fn.Type().Params().HasShape() {
                for _, arg := range n.Args {
                        if arg.Type().HasShape() {
                                if logopt.Enabled() {
                                        logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", ir.FuncName(ir.CurFunc),
-                                               fmt.Sprintf("inlining non-shape function %v with shape args", ir.FuncName(fn)))
+                                               fmt.Sprintf("inlining function %v has no-shape params with shape args", ir.FuncName(fn)))
                                }
                                return n
                        }
@@ -725,7 +727,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
                if !inlineable {
                        if logopt.Enabled() {
                                logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", ir.FuncName(ir.CurFunc),
-                                       fmt.Sprintf("inlining shape function %v with no shape args", ir.FuncName(fn)))
+                                       fmt.Sprintf("inlining function %v has shape params with no-shape args", ir.FuncName(fn)))
                        }
                        return n
                }
index 776be7f28061baa5761f6803a0832eaf982cd93c..f54b2049eb9a4b94afa47c5dc9b0cc04851fd62c 100644 (file)
@@ -14,6 +14,13 @@ func f[T int](t T) {
        }
 }
 
+func g[T int](g T) {
+       for true {
+               _ = func() T { return func(int) T { return g }(0) }()
+       }
+}
+
 func main() {
        f(0)
+       g(0)
 }