Skip to content

Commit f2b1cde

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: tighten the condition for inlining shape/non-shape function
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]>
1 parent b79c135 commit f2b1cde

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/cmd/compile/internal/inline/inl.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,15 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
701701
// apparent when we first created the instantiation of the generic function.
702702
// We can't handle this if we actually do the inlining, since we want to know
703703
// all interface conversions immediately after stenciling. So, we avoid
704-
// inlining in this case. See #49309. (1)
705-
if !fn.Type().HasShape() {
704+
// inlining in this case, see issue #49309. (1)
705+
//
706+
// See discussion on go.dev/cl/406475 for more background.
707+
if !fn.Type().Params().HasShape() {
706708
for _, arg := range n.Args {
707709
if arg.Type().HasShape() {
708710
if logopt.Enabled() {
709711
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", ir.FuncName(ir.CurFunc),
710-
fmt.Sprintf("inlining non-shape function %v with shape args", ir.FuncName(fn)))
712+
fmt.Sprintf("inlining function %v has no-shape params with shape args", ir.FuncName(fn)))
711713
}
712714
return n
713715
}
@@ -725,7 +727,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
725727
if !inlineable {
726728
if logopt.Enabled() {
727729
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", ir.FuncName(ir.CurFunc),
728-
fmt.Sprintf("inlining shape function %v with no shape args", ir.FuncName(fn)))
730+
fmt.Sprintf("inlining function %v has shape params with no-shape args", ir.FuncName(fn)))
729731
}
730732
return n
731733
}

test/fixedbugs/issue52907.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ func f[T int](t T) {
1414
}
1515
}
1616

17+
func g[T int](g T) {
18+
for true {
19+
_ = func() T { return func(int) T { return g }(0) }()
20+
}
21+
}
22+
1723
func main() {
1824
f(0)
25+
g(0)
1926
}

0 commit comments

Comments
 (0)