www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15671] New: The compiler should take into account inline

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

          Issue ID: 15671
           Summary: The compiler should take into account inline pragmas
                    when inlining
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: schveiguy yahoo.com

Given the following code:
import std.random;
shared int x;
void longFunc()
{
    version(good)
       x = uniform!int();
    x = uniform!int();
    x = uniform!int();
    x = uniform!int();
    x = uniform!int();
    x = uniform!int();
    x = uniform!int();
} 

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

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

The compiler fails if passed the -inline command line switch. However, it
succeeds if -inline -version=good is passed

Here is what happens:

1. The compiler inlines longFunc into foo (perhaps even calls to uniform as
well)
2. The compiler tries to inline foo into main, but fails because of the inlined
call to longFunc.
3. Since pragma(inline, true) is specified for foo, this fails to compile.

However, the compiler could succeed inlining foo into main by not inlining
longFunc into foo first.

This is demonstrated by the version=good compilation (one extra call to uniform
prevents longFunc from being inlined)

--
Feb 10 2016