mirror of
https://github.com/golang/go
synced 2024-11-11 21:20:21 -07:00
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 <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>
This commit is contained in:
parent
b79c135f37
commit
f2b1cde544
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user