1
0
mirror of https://github.com/golang/go synced 2024-09-23 13:20:14 -06:00

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>
This commit is contained in:
Matthew Dempsky 2022-08-18 05:20:16 -07:00
parent d6294e00f0
commit 52016be3f4
4 changed files with 56 additions and 32 deletions

View File

@ -722,6 +722,8 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
return n
}
// 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
@ -761,6 +763,7 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b
return n
}
}
}
if base.Flag.Cfg.Instrumenting && types.IsRuntimePkg(fn.Sym().Pkg) {
// Runtime package must not be instrumented.

View File

@ -1990,6 +1990,7 @@ var go118Failures = setOf(
"fixedbugs/issue54343.go", // 1.18 compiler assigns receiver parameter to global variable
"typeparam/nested.go", // 1.18 compiler doesn't support function-local types with generics
"typeparam/issue51521.go", // 1.18 compiler produces bad panic message and link error
"typeparam/issue54497.go", // 1.18 compiler is more conservative about inlining due to repeated issues
"typeparam/mdempsky/16.go", // 1.18 compiler uses interface shape type in failed type assertions
"typeparam/mdempsky/17.go", // 1.18 compiler mishandles implicit conversions from range loops
"typeparam/mdempsky/18.go", // 1.18 compiler mishandles implicit conversions in select statements

View File

@ -18,6 +18,7 @@ func myfunc(c string) {
//go:noinline
func test2(a interface{}) {
_ = a.(string)
}
func main() {

View File

@ -0,0 +1,19 @@
// errorcheck -0 -m
// 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.
// Test that inlining works with generic functions.
package testcase
type C interface{ ~uint | ~uint32 | ~uint64 }
func isAligned[T C](x, y T) bool { // ERROR "can inline isAligned\[uint\]" "can inline isAligned\[go\.shape\.uint\]" "inlining call to isAligned\[go\.shape\.uint\]"
return x%y == 0
}
func foo(x uint) bool { // ERROR "can inline foo"
return isAligned(x, 64) // ERROR "inlining call to isAligned\[go\.shape\.uint\]"
}