The following problem is pretty frequent.
lib.d
alias apiSymbol = expensiveTemplate!SomeArgs;
void cheapFunc() {}
client.d
import lib;
void main() { cheapFunc(); }
Although the client only uses cheapFunc the compiler will still run semantic on the expensive template instance. This is a major slowdown and it also makes it useless to localize additional imports in the template.
The semantic of the aliased symbol should be deferred until the alias is actually used. Even if it's used we should not generate code for the template, because that was already done when compiling lib. To allow this deferring should only happen for aliases in non-root modules.
I think it a sane proposal and it will have a big impact on compile times.
Comment #1 by code — 2014-08-02T04:49:33Z
See issue 13232 for 2 slowdown examples in Phobos.
Comment #2 by bugzilla — 2014-08-02T19:55:20Z
I have long wanted the compiler to go "full lazy" on semantic analysis, meaning it only does semantic analysis on imported symbols on demand.
It does it now for enums, but not for other symbols.
Comment #3 by code — 2014-08-04T19:20:46Z
I (In reply to Walter Bright from comment #2)
> I have long wanted the compiler to go "full lazy" on semantic analysis,
> meaning it only does semantic analysis on imported symbols on demand.
>
> It does it now for enums, but not for other symbols.
Right, so aliases would make for a good second case :).
Comment #4 by k.hara.pg — 2014-08-05T06:00:12Z
(In reply to Martin Nowak from comment #0)
> The following problem is pretty frequent.
>
> lib.d
>
> alias apiSymbol = expensiveTemplate!SomeArgs;
> void cheapFunc() {}
>
> client.d
> import lib;
> void main() { cheapFunc(); }
>
> Although the client only uses cheapFunc the compiler will still run semantic
> on the expensive template instance. This is a major slowdown and it also
> makes it useless to localize additional imports in the template.
> The semantic of the aliased symbol should be deferred until the alias is
> actually used. Even if it's used we should not generate code for the
> template, because that was already done when compiling lib. To allow this
> deferring should only happen for aliases in non-root modules.
>
> I think it a sane proposal and it will have a big impact on compile times.
If the instantiation expensiveTemplate!SomeArgs contains some errors but apiSymbol is not used, the error won't be reported? It sounds not good.
Comment #5 by code — 2015-05-12T07:09:22Z
(In reply to Kenji Hara from comment #4)
> (In reply to Martin Nowak from comment #0)
> If the instantiation expensiveTemplate!SomeArgs contains some errors but
> apiSymbol is not used, the error won't be reported? It sounds not good.
It's fine, you'll get the error when compiling the library.