Expand description
Serialization-friendly representation of tt::TopSubtree.
It is possible to serialize TopSubtree recursively, as a tree, but using
arbitrary-nested trees in JSON is problematic, as they can cause the JSON
parser to overflow the stack.
Additionally, such implementation would be pretty verbose, and we do care about performance here a bit.
So what this module does is dumping a tt::TopSubtree into a bunch of flat
array of numbers.
{
// Array of subtrees, each subtree is represented by 4 numbers:
// id of delimiter, delimiter kind, index of first child in `token_tree`,
// index of last child in `token_tree`
"subtree":[4294967295,0,0,5,2,2,5,5],
// 2 ints per literal: [token id, index into `text`]
"literal":[4294967295,1],
// 3 ints per punct: [token id, char, spacing]
"punct":[4294967295,64,1],
// 2 ints per ident: [token id, index into `text`]
"ident": [0,0,1,1],
// children of all subtrees, concatenated. Each child is represented as `index << shift_indices_by | tag`
// where tag denotes one of subtree, literal, punct or ident.
"token_tree":[3,7,1,4],
// Strings shared by idents and literals
"text": ["struct","Foo"]
}We probably should replace most of the code here with bincode someday, but, as we donβt have bincode in Cargo.toml yet, letβs stick with serde_json for the time being.
ModulesΒ§
- proc_
macro_ πsrv_ side - Conversion from/to the flat tree for the proc macro server.
- ra_side π
- Conversion from/to the flat tree for rust-analyzer.
StructsΒ§
- Flat
Tree - Ident
Repr π - Literal
Repr π - Punct
Repr π - Reader π
- Subtree
Repr π - Writer π
EnumsΒ§
- Subtree
OrLeaf πRef
TraitsΒ§
- Reader
Trait π - Span
Transformer - Writer
Trait π