@@ -19,8 +19,8 @@ use rustc_serialize::{
19
19
} ;
20
20
use rustc_session:: StableCrateId ;
21
21
use rustc_span:: {
22
- hygiene:: { ExpnIndex , Transparency } ,
23
- ExpnId , Span , SpanDecoder , SpanEncoder , Symbol , SyntaxContext , DUMMY_SP ,
22
+ hygiene:: ExpnIndex , BytePos , ExpnId , FileName , RealFileName , Span , SpanData , SpanDecoder ,
23
+ SpanEncoder , StableSourceFileId , Symbol , SyntaxContext , DUMMY_SP ,
24
24
} ;
25
25
use rustc_type_ir:: { TyDecoder , TyEncoder } ;
26
26
43
43
predicate_shorthands : FxHashMap :: default ( ) ,
44
44
} ;
45
45
46
+ // Encode set of source files to preload for span generation
47
+ for file in tcx. sess . source_map ( ) . files ( ) . iter ( ) {
48
+ let FileName :: Real ( RealFileName :: LocalPath ( path) ) = & file. name else {
49
+ continue ;
50
+ } ;
51
+
52
+ let Some ( path) = path. to_str ( ) else {
53
+ continue ;
54
+ } ;
55
+
56
+ if path. is_empty ( ) {
57
+ continue ;
58
+ }
59
+
60
+ encoder. emit_str ( path) ;
61
+ }
62
+
63
+ encoder. emit_str ( "" ) ;
64
+
65
+ // Encode item
46
66
item. encode ( & mut encoder) ;
47
67
48
68
if let Err ( ( _, err) ) = encoder. encoder . finish ( ) {
72
92
ty_cache : FxHashMap :: default ( ) ,
73
93
} ;
74
94
95
+ // Load preloaded source files
96
+ loop {
97
+ let preload_path = decoder. read_str ( ) ;
98
+ if preload_path. is_empty ( ) {
99
+ break ;
100
+ }
101
+
102
+ let _ = tcx. sess . source_map ( ) . load_file ( Path :: new ( & preload_path) ) ;
103
+ }
104
+
105
+ // Load decoded value
75
106
Some ( T :: decode ( & mut decoder) )
76
107
}
77
108
@@ -112,12 +143,21 @@ impl<'tcx, 'a> TyEncoder for AutokenEncoder<'tcx, 'a> {
112
143
}
113
144
114
145
fn encode_alloc_id ( & mut self , alloc_id : & AllocId ) {
115
- todo ! ( ) ;
146
+ let _ = alloc_id;
147
+ unimplemented ! ( "not used by analyzer" ) ;
116
148
}
117
149
}
118
150
119
151
impl < ' tcx , ' a > SpanEncoder for AutokenEncoder < ' tcx , ' a > {
120
- fn encode_span ( & mut self , _span : Span ) { }
152
+ fn encode_span ( & mut self , span : Span ) {
153
+ let src_file = self . tcx . sess . source_map ( ) . lookup_source_file ( span. lo ( ) ) ;
154
+ let src_offset = src_file. start_pos ;
155
+
156
+ src_file. stable_id . encode ( self ) ;
157
+ ( span. lo ( ) - src_offset) . encode ( self ) ;
158
+ ( span. hi ( ) - src_offset) . encode ( self ) ;
159
+ span. data ( ) . ctxt . encode ( self ) ;
160
+ }
121
161
122
162
fn encode_symbol ( & mut self , symbol : Symbol ) {
123
163
self . emit_str ( symbol. as_str ( ) ) ;
@@ -129,7 +169,8 @@ impl<'tcx, 'a> SpanEncoder for AutokenEncoder<'tcx, 'a> {
129
169
}
130
170
131
171
fn encode_syntax_context ( & mut self , syntax_context : SyntaxContext ) {
132
- syntax_context. marks ( ) . encode ( self ) ;
172
+ // Unimplemented: not used by our analyzer
173
+ let _ = syntax_context;
133
174
}
134
175
135
176
fn encode_crate_num ( & mut self , crate_num : CrateNum ) {
@@ -238,13 +279,35 @@ impl<'tcx, 'a> TyDecoder for AutokenDecoder<'tcx, 'a> {
238
279
}
239
280
240
281
fn decode_alloc_id ( & mut self ) -> AllocId {
241
- todo ! ( )
282
+ unimplemented ! ( "not used by analyzer" ) ;
242
283
}
243
284
}
244
285
245
286
impl < ' tcx , ' a > SpanDecoder for AutokenDecoder < ' tcx , ' a > {
246
287
fn decode_span ( & mut self ) -> Span {
247
- DUMMY_SP
288
+ let src_file = StableSourceFileId :: decode ( self ) ;
289
+ let rel_lo = BytePos :: decode ( self ) ;
290
+ let rel_hi = BytePos :: decode ( self ) ;
291
+ let ctxt = SyntaxContext :: decode ( self ) ;
292
+
293
+ let Some ( src_file) = self
294
+ . tcx
295
+ . sess
296
+ . source_map ( )
297
+ . source_file_by_stable_id ( src_file)
298
+ else {
299
+ return DUMMY_SP ;
300
+ } ;
301
+
302
+ let file_offset = src_file. start_pos ;
303
+
304
+ SpanData {
305
+ lo : file_offset + rel_lo,
306
+ hi : file_offset + rel_hi,
307
+ ctxt,
308
+ parent : None ,
309
+ }
310
+ . span ( )
248
311
}
249
312
250
313
fn decode_symbol ( & mut self ) -> Symbol {
@@ -258,13 +321,8 @@ impl<'tcx, 'a> SpanDecoder for AutokenDecoder<'tcx, 'a> {
258
321
}
259
322
260
323
fn decode_syntax_context ( & mut self ) -> SyntaxContext {
261
- let mut cx = SyntaxContext :: root ( ) ;
262
-
263
- for ( expn, trans) in Vec :: < ( ExpnId , Transparency ) > :: decode ( self ) {
264
- cx = cx. apply_mark ( expn, trans) ;
265
- }
266
-
267
- cx
324
+ // Unimplemented: not used by our analyzer
325
+ SyntaxContext :: root ( )
268
326
}
269
327
270
328
fn decode_crate_num ( & mut self ) -> CrateNum {
@@ -286,7 +344,7 @@ impl<'tcx, 'a> SpanDecoder for AutokenDecoder<'tcx, 'a> {
286
344
}
287
345
288
346
fn decode_attr_id ( & mut self ) -> AttrId {
289
- todo ! ( )
347
+ unimplemented ! ( "not used by analyzer" ) ;
290
348
}
291
349
}
292
350
0 commit comments