When trying to debug a module cycle issue, I stumbled across the realization that each time a module imports another module, that reference is added to the list of imported modules, even if it's already there.
The compiler should eliminate these duplicates, as it slows down runtime startup during module cycle detection, and bloats the executable.
Especially when idiomatic D code is supposed to import locally only when needed. Each of these local imports adds another reference.
Comment #1 by github-bugzilla — 2018-05-30T12:57:01Z
Can you create a test case that demonstrates this problem?
Comment #3 by schveiguy — 2018-05-30T19:02:22Z
Hm... any program has this problem.
Example:
import std.stdio;
void main()
{
foreach(mi; ModuleInfo)
{
writeln("In module ", mi.name, " we import:");
foreach(imported; mi.importedModules)
writeln(imported.name);
}
}
Comment #4 by schveiguy — 2018-05-30T19:28:49Z
For archive purposes, on my system, that program prints:
In module testcycle we import:
In module core.bitop we import:
core.cpuid
core.cpuid
In module core.cpuid we import:
In module core.exception we import:
In module core.runtime we import:
In module core.thread we import:
core.time
In module core.time we import:
In module core.internal.spinlock we import:
core.thread
In module gc.config we import:
In module gc.gcinterface we import:
In module gc.proxy we import:
gc.impl.conservative.gc
core.internal.spinlock
In module gc.impl.conservative.gc we import:
core.bitop
core.thread
core.time
core.internal.spinlock
core.internal.spinlock
In module rt.critical_ we import:
In module rt.deh_win64_posix we import:
In module rt.dmain2 we import:
In module rt.lifetime we import:
rt.tlsgc
core.bitop
In module rt.minfo we import:
core.bitop
core.bitop
core.bitop
In module rt.monitor_ we import:
In module rt.sections_osx_x86_64 we import:
rt.minfo
In module rt.tlsgc we import:
rt.lifetime
Excellent! Thank you Rainer. It's possible we can clean the cycle detection code a bit now that we don't have this problem (I believe I am using a hash at runtime to deduplicate).