[Issue 15671] The compiler should take into account inline pragmas when inlining

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 9 14:03:22 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=15671

--- Comment #6 from Steven Schveighoffer <schveiguy at yahoo.com> ---
Yes, Stanislav's description is correct.

The problem with the way pragma(inline) is implemented today is that it's very
brittle if you are depending on functions that might change the heuristic in
the future.

Consider a function like:

int foo(int val)
{
   // a bunch of complicated code.
   ...
}

In normal code, I enable inlining and whether the compiler inlines this or not,
I don't care. Now, it turns out that a very frequent use of foo among users is:


auto x = someString.length ? foo(someString.to!int) : 0;

So I want to capture that as a wrapping function:

int fooStr(string val)
{
   import std.conv : to;
   return val.length ? foo(val.to!int) : 0;
}

But I don't want to change the performance of the original code, so I want the
compiler to inline fooStr. I still don't care and want to leave it up to the
compiler whether foo itself can be inlined. I just want to provide a nice way
to avoid having to import std.conv, and write that conditional call every time.
I don't care if foo is inlined, but I DO want fooStr to be inlined.

Without this functionality I'm not exactly sure why pragma(inline) even exists.

--


More information about the Digitalmars-d-bugs mailing list