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.
Comment #1 by dlang-bot — 2019-07-09T07:03:02Z
@rainers created dlang/dmd pull request #10154 "fix issue 20037 - Imports in module info should be deduplicated" fixing this issue:
- fix issue 20037 - Imports in module info should be deduplicated
imports only need to be mentioned once in the ModuleInfo
https://github.com/dlang/dmd/pull/10154
Comment #2 by dlang-bot — 2019-07-09T08:40:45Z
dlang/dmd pull request #10154 "fix issue 20037 - Imports in module info should be deduplicated" was merged into master:
- 1671403b42dc4f8a4d4c0b2bb1ee75e1ea9267a0 by Rainer Schuetze:
fix issue 20037 - Imports in module info should be deduplicated
imports only need to be mentioned once in the ModuleInfo
https://github.com/dlang/dmd/pull/10154
Comment #3 by r.sagitario — 2019-08-23T20:31:03Z
*** Issue 16208 has been marked as a duplicate of this issue. ***