D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17067 - D header file generation includes excess imports
Summary: D header file generation includes excess imports
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-07 19:43 UTC by Neia Neutuladh
Modified: 2022-11-14 14:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Neia Neutuladh 2017-01-07 19:43:32 UTC
Consider the following module:

---
import std.stdio;

class Foo
{
    void bar()
    {
        writeln("Hello world!");
    }
}
---

While it includes a top-level import, that import isn't used in any of its declarations.

dmd -H produces:

---
// D import file generated from 'ditest.d'
import std.stdio;
class Foo
{
	void bar();
}
---

The unneeded import is retained.

Thanks to Peaker on IRC for pointing this out -- apparently they have a project that takes many minutes to compile, but, aside from excessive import costs, incremental builds can finish within a couple seconds.

As an aside, it would be relatively straightforward to map all imports to static imports in .di files, which would achieve significant savings if we made static imports lazy.
Comment 1 RazvanN 2018-06-20 10:40:17 UTC
This is probably a WONTFIX since the header generation is done immediately after the parsing phase so at that point no symbol resolution is done to see which symbols come from which imports and the safe thing to do is to just put them there; a workaround for this is to use scoped imports :

import std.stdio;

class Foo
{
    void bar()
    {
        import std.stdio : writeln;
        writeln("Hello world!");
    }
}