@@ -21,6 +21,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
21
21
use rustc_session:: Session ;
22
22
use rustc_span:: hygiene:: {
23
23
ExpnId , HygieneDecodeContext , HygieneEncodeContext , SyntaxContext , SyntaxContextData ,
24
+ SyntaxContextKey ,
24
25
} ;
25
26
use rustc_span:: source_map:: SourceMap ;
26
27
use rustc_span:: {
@@ -36,8 +37,9 @@ const TAG_FULL_SPAN: u8 = 0;
36
37
const TAG_PARTIAL_SPAN : u8 = 1 ;
37
38
const TAG_RELATIVE_SPAN : u8 = 2 ;
38
39
39
- const TAG_SYNTAX_CONTEXT : u8 = 0 ;
40
- const TAG_EXPN_DATA : u8 = 1 ;
40
+ const TAG_SYNTAX_CONTEXT_KEY : u8 = 0 ;
41
+ const TAG_SYNTAX_CONTEXT_DATA : u8 = 1 ;
42
+ const TAG_EXPN_DATA : u8 = 2 ;
41
43
42
44
// Tags for encoding Symbol's
43
45
const SYMBOL_STR : u8 = 0 ;
@@ -77,7 +79,8 @@ pub struct OnDiskCache<'sess> {
77
79
// to represent the fact that we are storing *encoded* ids. When we decode
78
80
// a `SyntaxContext`, a new id will be allocated from the global `HygieneData`,
79
81
// which will almost certainly be different than the serialized id.
80
- syntax_contexts : FxHashMap < u32 , AbsoluteBytePos > ,
82
+ syntax_context_keys : FxHashMap < u32 , AbsoluteBytePos > ,
83
+ syntax_context_data : FxHashMap < u32 , AbsoluteBytePos > ,
81
84
// A map from the `DefPathHash` of an `ExpnId` to the position
82
85
// of their associated `ExpnData`. Ideally, we would store a `DefId`,
83
86
// but we need to decode this before we've constructed a `TyCtxt` (which
@@ -108,7 +111,8 @@ struct Footer {
108
111
// without measurable overhead. This permits larger const allocations without ICEing.
109
112
interpret_alloc_index : Vec < u64 > ,
110
113
// See `OnDiskCache.syntax_contexts`
111
- syntax_contexts : FxHashMap < u32 , AbsoluteBytePos > ,
114
+ syntax_context_keys : FxHashMap < u32 , AbsoluteBytePos > ,
115
+ syntax_context_data : FxHashMap < u32 , AbsoluteBytePos > ,
112
116
// See `OnDiskCache.expn_data`
113
117
expn_data : UnhashMap < ExpnHash , AbsoluteBytePos > ,
114
118
foreign_expn_data : UnhashMap < ExpnHash , u32 > ,
@@ -179,7 +183,8 @@ impl<'sess> OnDiskCache<'sess> {
179
183
query_result_index : footer. query_result_index . into_iter ( ) . collect ( ) ,
180
184
prev_side_effects_index : footer. side_effects_index . into_iter ( ) . collect ( ) ,
181
185
alloc_decoding_state : AllocDecodingState :: new ( footer. interpret_alloc_index ) ,
182
- syntax_contexts : footer. syntax_contexts ,
186
+ syntax_context_keys : footer. syntax_context_keys ,
187
+ syntax_context_data : footer. syntax_context_data ,
183
188
expn_data : footer. expn_data ,
184
189
foreign_expn_data : footer. foreign_expn_data ,
185
190
hygiene_context : Default :: default ( ) ,
@@ -196,7 +201,8 @@ impl<'sess> OnDiskCache<'sess> {
196
201
query_result_index : Default :: default ( ) ,
197
202
prev_side_effects_index : Default :: default ( ) ,
198
203
alloc_decoding_state : AllocDecodingState :: new ( Vec :: new ( ) ) ,
199
- syntax_contexts : FxHashMap :: default ( ) ,
204
+ syntax_context_keys : FxHashMap :: default ( ) ,
205
+ syntax_context_data : FxHashMap :: default ( ) ,
200
206
expn_data : UnhashMap :: default ( ) ,
201
207
foreign_expn_data : UnhashMap :: default ( ) ,
202
208
hygiene_context : Default :: default ( ) ,
@@ -301,7 +307,8 @@ impl<'sess> OnDiskCache<'sess> {
301
307
interpret_alloc_index
302
308
} ;
303
309
304
- let mut syntax_contexts = FxHashMap :: default ( ) ;
310
+ let mut syntax_context_keys = FxHashMap :: default ( ) ;
311
+ let mut syntax_context_data = FxHashMap :: default ( ) ;
305
312
let mut expn_data = UnhashMap :: default ( ) ;
306
313
let mut foreign_expn_data = UnhashMap :: default ( ) ;
307
314
@@ -312,8 +319,12 @@ impl<'sess> OnDiskCache<'sess> {
312
319
& mut encoder,
313
320
|encoder, index, ctxt_data| {
314
321
let pos = AbsoluteBytePos :: new ( encoder. position ( ) ) ;
315
- encoder. encode_tagged ( TAG_SYNTAX_CONTEXT , ctxt_data) ;
316
- syntax_contexts. insert ( index, pos) ;
322
+ encoder. encode_tagged ( TAG_SYNTAX_CONTEXT_KEY , & ctxt_data. 0 ) ;
323
+ syntax_context_keys. insert ( index, pos) ;
324
+
325
+ let pos = AbsoluteBytePos :: new ( encoder. position ( ) ) ;
326
+ encoder. encode_tagged ( TAG_SYNTAX_CONTEXT_DATA , & ctxt_data. 1 ) ;
327
+ syntax_context_data. insert ( index, pos) ;
317
328
} ,
318
329
|encoder, expn_id, data, hash| {
319
330
if expn_id. krate == LOCAL_CRATE {
@@ -335,7 +346,8 @@ impl<'sess> OnDiskCache<'sess> {
335
346
query_result_index,
336
347
side_effects_index,
337
348
interpret_alloc_index,
338
- syntax_contexts,
349
+ syntax_context_keys,
350
+ syntax_context_data,
339
351
expn_data,
340
352
foreign_expn_data,
341
353
} ,
@@ -442,7 +454,8 @@ impl<'sess> OnDiskCache<'sess> {
442
454
file_index_to_file : & self . file_index_to_file ,
443
455
file_index_to_stable_id : & self . file_index_to_stable_id ,
444
456
alloc_decoding_session : self . alloc_decoding_state . new_decoding_session ( ) ,
445
- syntax_contexts : & self . syntax_contexts ,
457
+ syntax_context_keys : & self . syntax_context_keys ,
458
+ syntax_context_data : & self . syntax_context_data ,
446
459
expn_data : & self . expn_data ,
447
460
foreign_expn_data : & self . foreign_expn_data ,
448
461
hygiene_context : & self . hygiene_context ,
@@ -463,7 +476,8 @@ pub struct CacheDecoder<'a, 'tcx> {
463
476
file_index_to_file : & ' a Lock < FxHashMap < SourceFileIndex , Lrc < SourceFile > > > ,
464
477
file_index_to_stable_id : & ' a FxHashMap < SourceFileIndex , EncodedSourceFileId > ,
465
478
alloc_decoding_session : AllocDecodingSession < ' a > ,
466
- syntax_contexts : & ' a FxHashMap < u32 , AbsoluteBytePos > ,
479
+ syntax_context_keys : & ' a FxHashMap < u32 , AbsoluteBytePos > ,
480
+ syntax_context_data : & ' a FxHashMap < u32 , AbsoluteBytePos > ,
467
481
expn_data : & ' a UnhashMap < ExpnHash , AbsoluteBytePos > ,
468
482
foreign_expn_data : & ' a UnhashMap < ExpnHash , u32 > ,
469
483
hygiene_context : & ' a HygieneDecodeContext ,
@@ -584,16 +598,26 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Vec<u8> {
584
598
585
599
impl < ' a , ' tcx > SpanDecoder for CacheDecoder < ' a , ' tcx > {
586
600
fn decode_syntax_context ( & mut self ) -> SyntaxContext {
587
- let syntax_contexts = self . syntax_contexts ;
588
- rustc_span:: hygiene:: decode_syntax_context ( self , self . hygiene_context , |this, id| {
589
- // This closure is invoked if we haven't already decoded the data for the `SyntaxContext` we are deserializing.
590
- // We look up the position of the associated `SyntaxData` and decode it.
591
- let pos = syntax_contexts. get ( & id) . unwrap ( ) ;
592
- this. with_position ( pos. to_usize ( ) , |decoder| {
593
- let data: SyntaxContextData = decode_tagged ( decoder, TAG_SYNTAX_CONTEXT ) ;
594
- data
595
- } )
596
- } )
601
+ rustc_span:: hygiene:: decode_syntax_context (
602
+ self ,
603
+ self . hygiene_context ,
604
+ |this, id| {
605
+ // This closure is invoked if we haven't already decoded the data for the `SyntaxContext` we are deserializing.
606
+ // We look up the position of the associated `SyntaxData` and decode it.
607
+ let pos = this. syntax_context_keys . get ( & id) . unwrap ( ) ;
608
+ this. with_position ( pos. to_usize ( ) , |decoder| {
609
+ let data: SyntaxContextKey = decode_tagged ( decoder, TAG_SYNTAX_CONTEXT_KEY ) ;
610
+ data
611
+ } )
612
+ } ,
613
+ |this, id| {
614
+ let pos = this. syntax_context_data . get ( & id) . unwrap ( ) ;
615
+ this. with_position ( pos. to_usize ( ) , |decoder| {
616
+ let data: SyntaxContextData = decode_tagged ( decoder, TAG_SYNTAX_CONTEXT_DATA ) ;
617
+ data
618
+ } )
619
+ } ,
620
+ )
597
621
}
598
622
599
623
fn decode_expn_id ( & mut self ) -> ExpnId {
0 commit comments