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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 6 15:30:40 UTC 2020


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

--- Comment #2 from Steven Schveighoffer <schveiguy at yahoo.com> ---
First, to update the issue, you need a lot less uniform calls (probably the
underlying uniform call is more code than it used to be), update longFunc to
this:

void longFunc()
{
    version(good)
       x = uniform!int();
    x = uniform!int();
}

Second, the problem here is not the inliner heuristic. There is no reason that
the compiler cannot change:

foo!longFunc();

into:

longFunc();
x = uniform!int();

In other words, inline foo, but NOT inline func (and all the stuff it calls).

The point of forced inlining is to change a common call situation into directly
written code.

What this bug report is saying is that the inlining heuristic should take into
account that an outer portion should be inlined even if all the underlying code
cannot be.

If I change this to make longFunc opaque, it works:

pragma(mangle, "longFunc")
void longFunc_impl()
{
    x = uniform!int();
} 


void foo(alias func)()
{
    pragma(inline, true);
    func();
    x = uniform!int();
}

extern(C) void longFunc();

void main()
{
    foo!longFunc();
}

This is the behavior I would expect -- inline *this function* even if you can't
inline the calls it makes.

--


More information about the Digitalmars-d-bugs mailing list