www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20037] New: Imports in module info should be deduplicated

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

          Issue ID: 20037
           Summary: Imports in module info should be deduplicated
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

When building phobos unittests per package I noticed that a ridiculous number
of imports are added to the ModuleInfo of the modules as each local import is
appended unconditionally. The Win64 debug executable size shrinks from 65 MB to
58 MB if the imports are deduplicated.

Here's a test to detect duplicate entries:

import core.stdc.stdio;
import core.stdc.stdio;

void main()
{
    int duplicates = 0;
    foreach(mi; ModuleInfo)
    {
        //printf("Module %.*s:\n", mi.name.length, mi.name.ptr);
        auto imp = mi.importedModules;
    L_nextImport:
        for(size_t i = 0; i < imp.length; i++)
        {
            auto m = imp[i];
            //printf("    Import %.*s:\n", m.name.length, m.name.ptr);
            foreach(n; imp[i+1..$])
                if (n is m)
                {
                    duplicates++;
                    continue L_nextImport;
                }
        }
    }
    if(duplicates > 0)
        printf("%d duplicates\n", duplicates);
    assert(duplicates == 0);
}

For the phobos unittests, this reports 576910 duplicates.

--
Jul 08 2019