[Issue 10985] New: Inliner doesn't attempt to inline non-templated functions from libraries (even having the full source)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 7 03:37:51 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10985

           Summary: Inliner doesn't attempt to inline non-templated
                    functions from libraries (even having the full source)
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dmitry.olsh at gmail.com


--- Comment #0 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2013-09-07 03:37:49 PDT ---
First smallish test case that outlines the problem:

import mylib;

void main()
{
    templated("abcde");
    templated("abcde"w);
    nonTemplated(56);
}

//a module
module mylib;

struct MyStuff{
    int value;
    @property int fuzz(){
        return value*3/2;
    }
    @property int buzz(){
        return value*2/3;
    }
}

int templated(S)(S string)
{
    auto myf = MyStuff(string.length);
    return myf.fuzz*myf.buzz;
}

int nonTemplated(int k)
{
    auto myf = MyStuff(k);
    return myf.fuzz + 2 * myf.buzz;   
}


Observe in below logs that functions are not scanned for inlining even though
the full source is right there and is used for import. This severly cripples
Phobos performance.

Command line:
C:\dmd2\src\phobos>dmd -lib mylib.d

C:\dmd2\src\phobos>dmd -v -inline test_inline.d mylib.lib
binary    C:\dmd2\windows\bin\dmd.exe
version   v2.064
config    C:\dmd2\windows\bin\sc.ini
parse     test_inline
importall test_inline
import    object       
(C:\dmd2\windows\bin\..\..\src\druntime\import\object.di)
import    mylib (mylib.d)
semantic  test_inline
entry     main          test_inline.d
semantic2 test_inline
semantic3 test_inline
inline scan test_inline
code      test_inline
function  D main
function  test_inline.main
function  mylib.templated!string.templated
function  mylib.templated!(immutable(wchar)[]).templated
C:\dmd2\windows\bin\link.exe test_inline,,nul,"mylib.lib"+user32+kernel32/noi;

C:\dmd2\src\phobos>dmd -v -inline test_inline.d mylib.d
binary    C:\dmd2\windows\bin\dmd.exe
version   v2.064
config    C:\dmd2\windows\bin\sc.ini
parse     test_inline
parse     mylib
importall test_inline
import    object       
(C:\dmd2\windows\bin\..\..\src\druntime\import\object.di)
importall mylib
semantic  test_inline
entry     main          test_inline.d
semantic  mylib
semantic2 test_inline
semantic2 mylib
semantic3 test_inline
semantic3 mylib
inline scan test_inline
inline scan mylib
code      test_inline
function  D main
function  test_inline.main
code      mylib
function  mylib.MyStuff.fuzz
function  mylib.MyStuff.buzz
function  mylib.nonTemplated
function  mylib.templated!string.templated
function  mylib.templated!(immutable(wchar)[]).templated
C:\dmd2\windows\bin\link.exe test_inline,,nul,user32+kernel32/noi;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list