aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
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 /src/cmd
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 'src/cmd')
-rw-r--r--src/cmd/compile/internal/inline/inl.go67
1 files changed, 35 insertions, 32 deletions
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go
index 795486f7a2..ce667d3bed 100644
--- a/src/cmd/compile/internal/inline/inl.go
+++ b/src/cmd/compile/internal/inline/inl.go
@@ -722,44 +722,47 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
return n
}
- // Don't inline a function fn that has no shape parameters, but is passed at
- // least one shape arg. This means we must be inlining a non-generic function
- // fn that was passed into a generic function, and can be called with a shape
- // arg because it matches an appropriate type parameters. But fn may include
- // an interface conversion (that may be applied to a shape arg) that was not
- // 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 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() {
+ // The non-unified frontend has issues with inlining and shape parameters.
+ if base.Debug.Unified == 0 {
+ // Don't inline a function fn that has no shape parameters, but is passed at
+ // least one shape arg. This means we must be inlining a non-generic function
+ // fn that was passed into a generic function, and can be called with a shape
+ // arg because it matches an appropriate type parameters. But fn may include
+ // an interface conversion (that may be applied to a shape arg) that was not
+ // 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 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 function %v has no-shape params with shape args", ir.FuncName(fn)))
+ }
+ return n
+ }
+ }
+ } 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 := 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
+ break
+ }
+ }
+ if !inlineable {
if logopt.Enabled() {
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", ir.FuncName(ir.CurFunc),
- fmt.Sprintf("inlining function %v has no-shape params with shape args", ir.FuncName(fn)))
+ fmt.Sprintf("inlining function %v has shape params with no-shape args", ir.FuncName(fn)))
}
return n
}
}
- } 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 := 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
- break
- }
- }
- if !inlineable {
- if logopt.Enabled() {
- logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", ir.FuncName(ir.CurFunc),
- fmt.Sprintf("inlining function %v has shape params with no-shape args", ir.FuncName(fn)))
- }
- return n
- }
}
if base.Flag.Cfg.Instrumenting && types.IsRuntimePkg(fn.Sym().Pkg) {