Open overlookmotel opened 3 months ago
@Boshen Are you aware of Rolldown ever retaining only ScopeTree
or SymbolTable
by itself? Or is it a case of "where there is one, there is the other"? I suspect the latter, but just checking...
@Boshen Are you aware of Rolldown ever retaining only
ScopeTree
orSymbolTable
by itself? Or is it a case of "where there is one, there is the other"? I suspect the latter, but just checking...
Yeah they always come in pairs.
To my knowledge, there is nowhere where we need either
ScopeTree
orSymbolTable
by itself.There are various methods on
TraverseCtx
which need access to bothScopeTree
andSymbolTable
. These would be better located inoxc_semantic
so that they can be used more widely beyond the transformer. But we can't implement them onSemantic
, asTraverse
does not have access to a fullSemantic
, onlyScopeTree
andSymbolTable
.2 possible solutions:
1. New struct
Semantic
to storeScopeTree
+SymbolTable
in a single structScopes
.ScopeTree
+SymbolTable
ontoScopes
.TraverseCtx
toScopes
too.We should probably also move
references
field out ofSymbolTable
and put it in its own structReferences
. It seems arbitrary that symbols and references are stored separately.2. New trait
Add a trait
Scopes
which can be implemented on any struct which has access to bothScopeTree
andSymbolTable
. Then implement all the methods fromScopeTree
,SymbolTable
andTraverseCtx
on this trait.Could also implement another trait for any object which has access to
ScopeTree
,SymbolTable
andAstBuilder
, which could contain methods which use scoping info to create AST nodes. e.g. generate a UIDExpression::Identifier
(that requiresAstBuilder
to allocate it into arena).Which?
Personally I prefer the struct approach. That'd be a large breaking change, but it will also greatly simplify (a) passing
ScopeTree
+SymbolTable
around and (b) method calls - they're all onScopes
.I think we'll need to change
ScopeTree
andSymbolTable
APIs quite a bit anyway to optimize them (#32, #11), so we're likely to have to make breaking changes anyway.