On Wednesday, 10 June 2015 at 17:28:54 UTC, Walter Bright wrote:
But also, dmd doesn't quite have a proper mechanism for
resolving forward references - it's a series of hacks, which is
why it's been such a source of bugs.
The right way to do it is to go full lazy on running semantic()
on imported symbols. I did this with enums a while back, and
it's been working well.
Yes, I've continuously improved the hacky code in dmd, and
finally it's almost completed to realize lazy semantic analysis.
List of current implementation details in dmd code:
- before than all, an imported symbol will be set its 'scope' for
its lazy semantic analysis.
Dsymbol::setScope()
- variable types are determined lazily, and it detects 'circular
reference' in its initializer.
v->semantic(v->scope); in DsymbolExp::semantic(), and etc
v->inuse
- forward reference for functions and on-demand return type
inference is done:
FuncDeclaration::functionSemantic()
Determine function signatures (parameter types and
returnt types)
If return type is inferred, it will invoke
functionSemantic3().
FuncDeclaration::functionSemantic3()
Determine function full signature (includind deduced
attributes and inferred return types)
- an alias for the symbols comes from instantiations will be
resolve lazily
AliasDeclaration::toAlias()
- an aggregate size (all of field variable types) is analyzed
independently from other member semantic (member functions and so
on)
VarDeclaration::setFieldOffset()
AggregateDeclaration::finalizeSize()
- tangled class template definitions is analyzed correctly.
ClassDeclaration::baseok
- declarations in static if is lazily resolved
StaticIfDeclaration::include()
It will run addMembers() and setScope() for the members,
after the condition is correctly evaluated.
- the types and symbols on UDA is lazily resolved
UserAttributeDeclaration::getAttributes()
It's called by __traits(getAttributes) to invoke
on-demand semantic analysis.
UserAttributeDeclaration::semantic2()
UDA does not affect the semantic of annotated symbol, so
it's normally deferred until semantic2() stage.
Anymore I cannot say they're just hacks.
While doing them, unfortunately I've introduced not a few numbers
of regression issues, but they have been fixed properly.
Remaining issues in HEAD:
https://github.com/D-Programming-Language/dmd/pull/4731
https://github.com/D-Programming-Language/dmd/pull/4738
I'll be happy when you prioritize the PRs.
Kenji Hara