D-Programming-Language/dmd — pull request #1839 by eskimor (2013-04-04 17:52:26+00:00)
Title: Implemented feature 767 partially.

(Only string imports are tracked, no pragma(lib)).

It is not intended to be merged directly, at least for the following reason:

Currently the emitted dependencies are incorrect for templates (just as with regular -deps, which needs to be fixed too).

Both -deps and -filedeps emit dependencies for the module that references the dependency, even if this reference is within a template. This is incorrect, as only the code instantiating the template really depends on the template dependencies, there is no need to rebuild a module, if an import within a template changes.

Consider this simplified example, which makes the issue most clear:
```D
// module a
void templateFunc(string myImport)() {
mixin(myImport);
// ....
}

// module b:
void main() {
templateFunc("import std.string;")();
}
```
It seems a bit artificial, but in fact it is not (consider Diet templates for example). In this example the dependencies for module a change, depending on what code it uses.

The effect is not severe, it will just make build tools less efficient, because modules need to be compiled needlessly, it should nevertheless be fixed.

The problem is, how do I get a pointer to the instantiating module? loc of a template instantiation contains the right information, but I was not able to retrieve the instantiating module. Any help would be appreciated, I would then fix both -deps and -filedeps.

Thanks!

Best regards,
Robert