Design: syntax trees vs identity #3129
Labels
C-Architecture
Big architectural things which we need to figure up-front (or suggestions for rewrites :0) )
E-unknown
It's unclear if the issue is E-hard or E-easy without digging in
fun
A technically challenging issue with high impact
In #3120 (comment), I've once again noticed that working with syntax trees when you want to get semantic information is annoying. This issue is just a brain dump of the things we might do here.
The problem we have is that it's difficult to "index" semantic info by current syntax trees.
For example, here's how one gets a type of expression in Roslyn (with some details ommited):
Note how at
*
we only pass the tree to the model to get the type.In contrast, with the current API in Rust syntax trees are value types which don't remember the context they originated from. So, to get a type of an expression syntax, you also need to specify the identity of the file this syntax originates from.
The current way to specify identity is mostly the
InFile<T>
type, which is a pair ofT
and a (real or macro) file id. There are two problems with this approach:s: InFile<ast::StructDef>
, you can't get anOption<InFile<ast::Name>>
by calling ans.name()
, instead you need tos.map(|it| it.name()).transpose()
, which is a lot.It also has it's benefits:
InFile<ast::SomeNod>
,InFile<TextRange>
,InFile<Token>
.What can we do here:
InFile<T>
's.InFile<T>
. Ie, generate something likeimpl InFile<ast::StructDef> { fn name(&self) -> Option<InFile<ast::StructDef>> }
FIleId(u32)
field to each syntax node, such that nodes always come with a strong identity.The text was updated successfully, but these errors were encountered: