Bug 16208 – moduleinfo importedModules contains needless duplicates

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-06-27T17:20:28Z
Last change time
2019-08-28T14:44:39Z
Assigned to
No Owner
Creator
Steven Schveighoffer
See also
https://issues.dlang.org/show_bug.cgi?id=20177

Comments

Comment #0 by schveiguy — 2016-06-27T17:20:28Z
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
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/b60b669b4d92398f0fb770b895c2835a71c54e3f [Refactorization] Issue 16208 - curly braces on newlines https://github.com/dlang/dmd/commit/6d76646aaca6ccc8d633fea899a1e81b84e20533 Merge pull request #8311 from RazvanN7/Followup_16206 [Refactorization] Issue 16208 - curly braces on new lines
Comment #2 by slavo5150 — 2018-05-30T16:28:14Z
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
Comment #5 by r.sagitario — 2019-08-23T20:31:03Z
Stumbled over it recently, too: https://issues.dlang.org/show_bug.cgi?id=20037 and fixed it: https://github.com/dlang/dmd/pull/10154 *** This issue has been marked as a duplicate of issue 20037 ***
Comment #6 by schveiguy — 2019-08-28T14:31:15Z
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).