Spurious imports in Phobos ?

Jacob Carlborg doob at me.com
Wed Nov 9 04:15:25 PST 2011


On 2011-11-09 10:14, Somedude wrote:
> Hello,
>
> When I display the dependencies with "dmd -deps=depends", I see that
> simply importing std.stdio imports dozens of modules, among which
> std.ranges, std.datetime, std.c.windows.winsock, std.regex, etc
> In fact, the depends file is 433 lines long.
>
> I noticed that std.string imports quite a lot of stuff.
> Here is a copypasta of the code:
>
> import core.exception : onRangeError;
> import core.vararg, core.stdc.stdlib, core.stdc.string,
>      std.algorithm, std.ascii, std.conv, std.exception, std.format,
> std.functional,
>      std.metastrings, std.range, std.regex, std.traits,
>      std.typetuple, std.uni, std.utf;
>
> //Remove when repeat is finally removed. They're only here as part of the
> //deprecation of these functions in std.string.
> public import std.algorithm : startsWith, endsWith, cmp, count;
> public import std.array : join, split;
>
> So as an experiment, I tried to remove a few imports:
>
> std.range, std.regex, std.traits and std.algorithm
> as well as the two lines of public import.
>
> To my surprise, it still compiles !
> The depends file goes down to 402 lines, but the executable size is
> understandably not reduced because all the removed dependencies are
> still used elsewhere.
>
> Then I thought this may be due to public imports from other modules,
> which makes me think that public imports are a bad idea, as we can
> compile a module only because we imported unknowingly a namespace from
> imported modules.
>
> My question is: how do we know if std.range, std.regex, std.traits and
> std.algorithm are spurious imports or if we can (and threfore should)
> remove them safely from std.string ?
>
> Dude

Phobos contains a lot of templates and if a template isn't instantiated 
it won't be compiled. Meaning there can be hidden compile errors if you 
start to remove imports and they will not show until a template that 
uses something from the import is instantiate.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list