Skip to main content

Module flat

Module flat 

Source
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Β§

FlatTree
IdentRepr πŸ”’
LiteralRepr πŸ”’
PunctRepr πŸ”’
Reader πŸ”’
SubtreeRepr πŸ”’
Writer πŸ”’

EnumsΒ§

SubtreeOrLeafRef πŸ”’

TraitsΒ§

ReaderTrait πŸ”’
SpanTransformer
WriterTrait πŸ”’

FunctionsΒ§

deserialize_span_data_index_map
read_vec πŸ”’
serialize_span_data_index_map
write_vec πŸ”’

Type AliasesΒ§

SpanDataIndexMap