pragma(inline, true) errors?
Steven Schveighoffer
schveiguy at gmail.com
Thu Apr 1 18:38:45 UTC 2021
Was diagnosing an issue on raylib-d with inlining. I have found some
curious behavior.
Observe the following code:
```d
extern(C) pragma(inline, true) static float EaseBounceOut(float t, float
b, float c, float d)
{
if ((t/=d) < (1.0f/2.75f))
{
return (c*(7.5625f*t*t) + b);
}
else if (t < (2.0f/2.75f))
{
float postFix = t-=(1.5f/2.75f);
return (c*(7.5625f*(postFix)*t + 0.75f) + b);
}
else if (t < (2.5/2.75))
{
float postFix = t-=(2.25f/2.75f);
return (c*(7.5625f*(postFix)*t + 0.9375f) + b);
}
else
{
float postFix = t-=(2.625f/2.75f);
return (c*(7.5625f*(postFix)*t + 0.984375f) + b);
}
}
void main()
{
auto f = EaseBounceOut(0.5, 1, 1, 1);
}
```
Here is a relevant run.dlang.io snippet: https://run.dlang.io/is/UEtyE8
Some interesting things about this:
1. With -w, I get no errors.
2. With -wi, I get a warning that the function can be inlined
3. Using ASM view, it appears the function is NOT inlined in either case.
I checked historical compilers, and I found that this behavior stems
from 2.094. I looked at the changelog, and see this [1].
So I feel like this is a bug, but I'm not sure. I'm assuming the
intended behavior is to inline at all costs, and error if it cannot. But
I'm not sure of the intended uses of pragma(inline). I feel like if we
"fix" this, it will break *a lot* of code.
In general, my thoughts on the pragma(inline) feature are that it is a
complete failure. It either doesn't do what I want, or it is so fragile
that I don't want to use it. My only use case is for a shim that should
never really be emitted into the object file. But D tries to inline not
just the shim, but every function it calls as well.
-Steve
[1] https://dlang.org/changelog/2.094.0.html#hasAlwaysInlines
More information about the Digitalmars-d
mailing list