On Monday, 6 January 2014 at 07:02:03 UTC, Andrei Alexandrescu
wrote:
On 1/5/14 10:31 PM, Walter Bright wrote:
On 1/5/2014 9:22 PM, Andrei Alexandrescu wrote:
On 1/5/14 8:44 PM, Kenji Hara wrote:
Honestly, "lazy import" (== defer loading module file and
running
semantic analysis for symbol search) would improve
compilation speed for
selective imports and static imports, but it would have no
merit for
basic imports.
So precisely, "all imports lazy would be a net large win."
is not
correct.
Consider:
import std.stdio;
void main() { writeln("Hello, world!"); }
Currently std.stdio and all modules transitively imported by
it would
be opened.
With lazy imports, std.stdio gets opened and then writeln()
gets
semantically
analyzed. Only modules required by writeln() itself will
actually be
opened. Big
difference.
import bar;
import foo;
Importing foo can never be done lazily if there are unqualified
references to symbols in bar.
Yah, but modules transitively imported in foo and bar need not
be loaded eagerly. That's where the win comes from. Took me a
while to figure.
Andrei
Right, but this fails quite quickly. Consider this:
//----
module Foo;
import tons_of_imports_here;
void foo()
{
unqualified_call();
}
//----
import Foo;
void main()
{
foo();
}
//----
The *instant* the implementation makes an unqualified call, you
*have* to import *all* the imports of the module, to figure out
what to call.
Given that you *probably* imported "foo" with the plan to *use*
one of its functions, you'll encounter an unqualified call sooner
rather than later, and any "win" will promptly be lost.