Bug 13242 – imported aliases should be analyzed lazily

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-02T04:43:00Z
Last change time
2017-05-24T12:09:28Z
Keywords
pull
Assigned to
nobody
Creator
code
See also
https://issues.dlang.org/show_bug.cgi?id=13255

Comments

Comment #0 by code — 2014-08-02T04:43:05Z
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.
Comment #6 by k.hara.pg — 2016-04-22T03:13:59Z
Comment #7 by github-bugzilla — 2016-04-22T08:13:33Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/a0e89b14eadb295b8578df7f49c193bca1525526 fix Issue 13242 - imported aliases should be analyzed lazily https://github.com/dlang/dmd/commit/e2dfb4a3d87dd6e4e4dc006064ddf4ac5b6880a4 Merge pull request #5690 from 9rnsr/fix13242 Issue 13242 - imported aliases should be analyzed lazily
Comment #8 by github-bugzilla — 2016-10-01T11:46:17Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/a0e89b14eadb295b8578df7f49c193bca1525526 fix Issue 13242 - imported aliases should be analyzed lazily https://github.com/dlang/dmd/commit/e2dfb4a3d87dd6e4e4dc006064ddf4ac5b6880a4 Merge pull request #5690 from 9rnsr/fix13242
Comment #9 by dlang-bugzilla — 2017-05-23T07:16:02Z
*** Issue 15318 has been marked as a duplicate of this issue. ***