@@ -16,8 +16,15 @@ pub use crate::msg::flat::FlatTree;
16
16
pub const NO_VERSION_CHECK_VERSION : u32 = 0 ;
17
17
pub const VERSION_CHECK_VERSION : u32 = 1 ;
18
18
pub const ENCODE_CLOSE_SPAN_VERSION : u32 = 2 ;
19
+ /// This version changes how spans are encoded, kind of. Prior to this version,
20
+ /// spans were represented as a single u32 which effectively forced spans to be
21
+ /// token ids. Starting with this version, the span fields are still u32,
22
+ /// but if the size of the span is greater than 1 then the span data is encoded in
23
+ /// an additional vector where the span represents the offset into that vector.
24
+ /// This allows encoding bigger spans while supporting the previous versions.
25
+ pub const VARIABLE_SIZED_SPANS : u32 = 2 ;
19
26
20
- pub const CURRENT_API_VERSION : u32 = ENCODE_CLOSE_SPAN_VERSION ;
27
+ pub const CURRENT_API_VERSION : u32 = VARIABLE_SIZED_SPANS ;
21
28
22
29
#[ derive( Debug , Serialize , Deserialize ) ]
23
30
pub enum Request {
@@ -115,10 +122,14 @@ fn write_json(out: &mut impl Write, msg: &str) -> io::Result<()> {
115
122
116
123
#[ cfg( test) ]
117
124
mod tests {
125
+ use tt:: {
126
+ Delimiter , DelimiterKind , Ident , Leaf , Literal , Punct , Spacing , Span , Subtree , TokenId ,
127
+ TokenTree ,
128
+ } ;
129
+
118
130
use super :: * ;
119
- use crate :: tt:: * ;
120
131
121
- fn fixture_token_tree ( ) -> Subtree {
132
+ fn fixture_token_tree ( ) -> Subtree < TokenId > {
122
133
let mut subtree = Subtree { delimiter : Delimiter :: unspecified ( ) , token_trees : Vec :: new ( ) } ;
123
134
subtree
124
135
. token_trees
@@ -128,17 +139,17 @@ mod tests {
128
139
. push ( TokenTree :: Leaf ( Ident { text : "Foo" . into ( ) , span : TokenId ( 1 ) } . into ( ) ) ) ;
129
140
subtree. token_trees . push ( TokenTree :: Leaf ( Leaf :: Literal ( Literal {
130
141
text : "Foo" . into ( ) ,
131
- span : TokenId :: unspecified ( ) ,
142
+ span : TokenId :: DUMMY ,
132
143
} ) ) ) ;
133
144
subtree. token_trees . push ( TokenTree :: Leaf ( Leaf :: Punct ( Punct {
134
145
char : '@' ,
135
- span : TokenId :: unspecified ( ) ,
146
+ span : TokenId :: DUMMY ,
136
147
spacing : Spacing :: Joint ,
137
148
} ) ) ) ;
138
149
subtree. token_trees . push ( TokenTree :: Subtree ( Subtree {
139
150
delimiter : Delimiter {
140
151
open : TokenId ( 2 ) ,
141
- close : TokenId :: UNSPECIFIED ,
152
+ close : TokenId :: DUMMY ,
142
153
kind : DelimiterKind :: Brace ,
143
154
} ,
144
155
token_trees : vec ! [ ] ,
0 commit comments