www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15483] New: static if prevents inlining

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

          Issue ID: 15483
           Summary: static if prevents inlining
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: thomas.bockman gmail.com

module app;

void main() {
    import std.stdio;

    inlineme1(true);

    inlineme2(true); // Error: function app.inlineme2 cannot inline function
}

 safe pragma(inline, true) {
    bool inlineme1(bool left)
    {
        if(left)
            return true;

        return false;
    }

    bool inlineme2(bool left)
    {
        if(left)
            return true;

        static if(false)
        {
            /*
                Even though it does absolutely nothing,
                the mere presence of this block prevents inlining
                of this function.
            */
        }

        return false;
    }
}

This issue has been giving me a lot of trouble while working on checkedint, for
which inlining is critical to getting good performance.

I keep writing template functions which, if I instantiate the template by hand,
will inline fine, but refuse to do so if I let the compiler instantiate it for
me. I really don't want to be stuck using string mixins everywhere...

--
Dec 29 2015