--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
My counter proposal is that we settle on a pattern to disable inlining and document it.
For example, I think this pattern works regardless of compiler version:
var alwaysfalse bool
func shouldNotBeInlined() {
if alwaysfalse {
shouldNotBeInlined()
}
}
Because the compiler cannot determine that the bool is always false, this function is self-recursive and cannot be inlined even if recursive inlining (-l=3) is enabled (if we disregard partial function inlining). The pattern is safe until we have whole program optimization that can discover that nothing changes the value of alwaysfalse, but I imagine it's quite hard to do while maintaining the current compile speed benefit. Even if we do have such optimization in the future, detect this pattern explicitly should be easy.
It does have negligible runtime penalty though, but you're already sacrificing performance when trying to disable inlining.
On Aug 25, 2015 2:50 PM, "Russ Cox" <r...@golang.org> wrote:
> What's the benefit over //go:noinline? It seems the same, just spelled more verbosely.
>
The benefit seems to be that it doesn't require one more directive and also it's already supported by current compilers.
Adding a new directive means the code will behave differently in compilers that doesn't support the directive (most importantly, older versions.)
--
There do exist compilers for other languages that do the work to notice that alwaysfalse is never assigned and is thus indeed alwaysfalse, and it is generally true that when compilers do this they make people happy. I am a huge fan of saying what you mean, and if the language lacks a way to say what needs to be said, add it.By-the-way, even lacking the knowledge that alwaysfalse is always false, that code could handily be optimized intofunc shouldNotBeInlined() {
if alwaysfalse {
for {}
}
}You'll note that the code can now be inlined because it contains no calls, and stack storage consumption has been infinitely optimized. Three cheers for the optimizer, right? It made your code better, isn't that what you wanted?
--
Don't forget that the proposed use case is for compiler testing, so one reason to favor the directive over polluting the control flow is that sometimes you want to feed the compiler code that lacks polluted control flow -- and if I had the time to work on it, I would also be working on improving inlining in ways that might still allow the inlining of your improved anti-inliner.Look at all the various complaints about "hey, Go is slower at X than language Y". Think about what it means to make code run 1% more efficiently across a large company's datacenters. Over time, if Go succeeds, there will be large incentives to do floats-most-boats optimizations, and these subtext-encodings-of-intent will just look like what-were-we-thinking? technical debt when that time comes.
I am concerned that people will want this feature and start relying on it; i.e., it becomes a language mechanism.Since this is explicitly for compiler testing, can we simply not document it (widely)?
Ok, how about add a runtime/debug func DoNotInline() that technically is a no-op, but if called, will inhibit inlining of the enclosing function.
For now, we just need to implement that in assembly. Future improved compiler might need to detect it.
It is as clear as //go:noinline, but doesn't require changes to the compiler.