Would it be possible to perform private selective imports lazily?
i.e. only import when the symbol selectively imported is
requested.
--------------------------------------
// not used => std.stdio not imported
import std.stdio : writeln;
void main()
--------------------------------------
// used => std.stdio imported
import std.stdio : writeln;
void main() { writeln("Hello, world"); }
--------------------------------------
// non-selective std.stdio imported
import std.stdio;
void writeln(
void main() {}
--------------------------------------
Are there problems with this?
One semantic difference this would make is that module
constructors wouldn't be run in the first case whereas they would
be without this change. Public selective imports would need to be
done eagerly.
The idea is to reduce code bloat and parse times without having
to resort to local imports everywhere and hacks like this:
https://github.com/D-Programming-Language/phobos/pull/2047/files

This is a very recent issue, as a matter of fact, I ran into it
*TODAY*:
https://github.com/D-Programming-Language/phobos/pull/2047
By combining templates and aliases, you can have a library
solution:
//----
template lazyWriteln()
{
import std.stdio : writeln;
alias lazyWriteln = std.stdio.writeln;
}
void main()
{
lazyWriteln(5);
}
//----
Heck, with proper renamed imports, you can even re-use the
initial name:
//----
template writeln()
{
import std.stdio : stdwriteln = writeln;
alias writeln = stdwriteln;
}
void main()
{
writeln(5);
}
//----
HOWEVER (word of warning), for the second solutions, I've run
into conflicting alias issues:
std/conv.d(4864): Error:
std.string.format!(char, uint, string, uint).format at
std/string.d(2401)
conflicts with
std.string.format!(char, uint, string, uint).format at
std/string.d(2401)
I didn't dig very far to know if this is 313/314 related, or a
new issue though.
In any case, while not as convenient as a built-in "lazy import",
it could be a solution worth digging into.

Would it be possible to perform private selective imports
lazily? i.e.
only import when the symbol selectively imported is requested.

Laziness only makes sense for static imports, because otherwise
the compiler needs to check for overloads during symbol lookup.

If I only import writeln from std.stdio then you only overload
resolution that could effect is that of the symbol writeln. That
means you only need to process the import when writeln is
encountered. No?
e.g.
import std.stdio : writeln;
void main() { foo(); }
There should be no need to look in std.stdio at all here,
regardless of whether it contains foo or not because I'm only
importing writeln.