Bug 8858 – DMD's -v option doesn't output dependencies with imports inside functions

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-20T10:49:48Z
Last change time
2017-12-06T02:50:53Z
Assigned to
No Owner
Creator
thelastmammoth
Blocks
8856

Comments

Comment #0 by thelastmammoth — 2012-10-20T10:49:48Z
this issue is the cause of issue http://d.puremagic.com/issues/show_bug.cgi?id=8856 (import inside function sometimes causes link errors) I'm reproducing here Andrej Mitrovic's comment to the above issue: DMD's -v option doesn't output dependencies when an import is function local. test.d: module test; import foo; void main() { } foo.d: module foo; import bar; bar.d is empty $ dmd -c -v test.d > import foo (foo.d) > import bar (bar.d) Now use a local import in foo.d: foo.d: module foo; void loc() { import bar; } $ dmd -c -v test.d > import foo (foo.d) DMD doesn't output the import to bar.d when using -v. That has to be fixed.
Comment #1 by andrej.mitrovich — 2013-01-11T19:14:58Z
Caused by same issue as in 7016. *** This issue has been marked as a duplicate of issue 7016 ***
Comment #2 by timothee.cour2 — 2017-12-05T20:25:47Z
Re-opening since https://issues.dlang.org/show_bug.cgi?id=7016 dealt with -deps (cf title) whereas this issue deals with -v; 7016 has been fixed but this issue is still there as of DMD64 D Compiler v2.077.0. This bug also affects rdmd, which is based on -v : rdmd does not use -deps output - it uses -v (because -v includes more information); see also https://www.bountysource.com/issues/44926161-fix-issue-7016-local-import-does-not-create-deps-dependency a.d : import b; void main() { f(); } b.d : int f() { import c; return i; } c.d : int i = 42; dmd -v -o- a.d predefs DigitalMars Posix OSX darwin LittleEndian D_Version2 all D_SIMD D_InlineAsm_X86_64 X86_64 D_LP64 D_PIC assert D_HardFloat binary dmd version v2.077.0 config /Users/timothee/homebrew/etc/dmd.conf parse a importall a import object (/Users/timothee/homebrew/opt/dmd/include/dlang/dmd/object.d) import core.attribute (/Users/timothee/homebrew/opt/dmd/include/dlang/dmd/core/attribute.d) import b (b.d) semantic a entry main a.d semantic2 a semantic3 a
Comment #3 by timothee.cour2 — 2017-12-05T20:40:21Z
*** Issue 8856 has been marked as a duplicate of this issue. ***
Comment #4 by johnnymarler — 2017-12-05T22:01:21Z
From what I understand, getting all dependencies for a module requires more overhead than it takes to just compile the file. Compiling a single file only requires loading the imports that the file references directly, the compiler also loads indirect imports so long as they are global, but it isn't required to do this. That leaves local imports inside other imports to go unnocited. To force the compiler to load all the imports even when it just needs to compile a single file would have a bad performance impact, therefore, it makes sense to make this an option to be passed to the compiler. This command line option "-deps" already exists and already signals the compiler to load all the modules. Given this, I would mark this as "not a bug" saying that if you need to get all the imports you should include the "-deps" flag to the compiler.
Comment #5 by johnnymarler — 2017-12-06T02:50:53Z
This PR (https://github.com/dlang/dmd/pull/7400) adds the "-deps-" option to dmd so that it will analyze dependencies without printing them. This will allow rdmd to get the imports via "-v" without adding extra work to create the dependency file or print them to stderr. This PR will add the "-deps-" option when rdmd calls dmd (https://github.com/dlang/tools/pull/268).