When a simple type is nested in the function, e.g as an helper DMD fails to inline:
°°°°°°°°°°°°°°°°°°°°°°°°°°°°
#!runnable-flags: -O -inline
module runnable;
import std.stdio;
pragma(inline, true)
auto foo(int t)
{
struct Bar{}
return t;
}
void main()
{
auto v = foo(1);
}
°°°°°°°°°°°°°°°°°°°°°°°°°°°°
outputs:
> /tmp/temp_7FD0A006D9F0.d(7,6): Error: function runnable.foo cannot inline function
Comment #1 by b2.temp — 2016-08-13T23:28:43Z
LDC succeeds, so DMD inliner only.
Comment #2 by ag0aep6g — 2016-08-14T00:15:10Z
I'm removing the "wrong-code" keyword, and downgrading this to an enhancement request.
A wrong-code bug is when incorrect machine code is generated. The test case must compile and link for that, but dmd rejects the test case.
It's only an enhancement request, because the spec explicitly allows the compiler to error out when it can't inline a function that has pragma(inline, true).
Comment #3 by turkeyman — 2018-06-27T06:35:31Z
This code should obviously inline.
I think rejecting inline should be because there's a reason it can't inline. There's no such reason here, failure to inline is an implementation detail (ie, a bug).
Comment #4 by b2.temp — 2018-06-27T08:59:47Z
(In reply to Basile B. from comment #0)
> When a simple type is nested in the function, e.g as an helper DMD fails to
> inline:
>
> °°°°°°°°°°°°°°°°°°°°°°°°°°°°
> #!runnable-flags: -O -inline
> module runnable;
>
> import std.stdio;
>
> pragma(inline, true)
> auto foo(int t)
> {
> struct Bar{}
> return t;
> }
>
> void main()
> {
> auto v = foo(1);
> }
> °°°°°°°°°°°°°°°°°°°°°°°°°°°°
>
> outputs:
> > /tmp/temp_7FD0A006D9F0.d(7,6): Error: function runnable.foo cannot inline function
Note :
1. this also fails if Bar is a nested static struct, which is more surprising.
2. this case is suspected to be part of the perf problem DMD has with ranges and pipelines (Voldemort types are often nested...)