mirror of
https://github.com/golang/go
synced 2024-11-23 10:00:03 -07:00
ed7a8332c4
We still disallow inlining for an immediately-recursive function, but allow inlining if a function is in a recursion chain. If all functions in the recursion chain are simple, then we could inline forever down the recursion chain (eventually running out of stack on the compiler), so we add a map to keep track of the functions we have already inlined at a call site. We stop inlining when we reach a function that we have already inlined in the recursive chain. Of course, normally the inlining will have stopped earlier, because of the cost function. We could also limit the depth of inlining by a simple count (say, limit max inlining of 10 at any given site). Would that limit other opportunities too much? Added a test in test/inline.go. runtime.BenchmarkStackCopyNoCache() is also already a good test that triggers the check to stop inlining when we reach the start of the recursive chain again. For the bent benchmark suite, the performance improvement was mostly not statistically significant, but the geomean averaged out to: -0.68%. The text size increase was less than .1% for all bent benchmarks. The cmd/go text size increase was 0.02% and the cmd/compile text size increase was .1%. Fixes #29737 Change-Id: I892fa84bb07a947b3125ec8f25ed0e508bf2bdf5 Reviewed-on: https://go-review.googlesource.com/c/go/+/226818 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
95 lines
1.2 KiB
Go
95 lines
1.2 KiB
Go
// errorcheck -+
|
|
|
|
// Copyright 2016 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 go:nowritebarrier and related directives.
|
|
|
|
package p
|
|
|
|
type t struct {
|
|
f *t
|
|
}
|
|
|
|
var x t
|
|
var y *t
|
|
|
|
//go:nowritebarrier
|
|
func a1() {
|
|
x.f = y // ERROR "write barrier prohibited"
|
|
a2() // no error
|
|
}
|
|
|
|
//go:noinline
|
|
func a2() {
|
|
x.f = y
|
|
}
|
|
|
|
//go:nowritebarrierrec
|
|
func b1() {
|
|
b2()
|
|
}
|
|
|
|
//go:noinline
|
|
func b2() {
|
|
x.f = y // ERROR "write barrier prohibited by caller"
|
|
}
|
|
|
|
// Test recursive cycles through nowritebarrierrec and yeswritebarrierrec.
|
|
|
|
//go:nowritebarrierrec
|
|
func c1() {
|
|
c2()
|
|
}
|
|
|
|
//go:yeswritebarrierrec
|
|
func c2() {
|
|
c3()
|
|
}
|
|
|
|
func c3() {
|
|
x.f = y
|
|
c4()
|
|
}
|
|
|
|
//go:nowritebarrierrec
|
|
func c4() {
|
|
c2()
|
|
}
|
|
|
|
//go:nowritebarrierrec
|
|
func d1() {
|
|
d2()
|
|
}
|
|
|
|
func d2() {
|
|
d3()
|
|
}
|
|
|
|
//go:noinline
|
|
func d3() {
|
|
x.f = y // ERROR "write barrier prohibited by caller"
|
|
d4()
|
|
}
|
|
|
|
//go:yeswritebarrierrec
|
|
func d4() {
|
|
d2()
|
|
}
|
|
|
|
//go:noinline
|
|
func systemstack(func()) {}
|
|
|
|
//go:nowritebarrierrec
|
|
func e1() {
|
|
systemstack(e2)
|
|
systemstack(func() {
|
|
x.f = y // ERROR "write barrier prohibited by caller"
|
|
})
|
|
}
|
|
|
|
func e2() {
|
|
x.f = y // ERROR "write barrier prohibited by caller"
|
|
}
|