@@ -21,6 +21,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2121use rustc_session:: Session ;
2222use rustc_span:: hygiene:: {
2323 ExpnId , HygieneDecodeContext , HygieneEncodeContext , SyntaxContext , SyntaxContextData ,
24+ SyntaxContextKey ,
2425} ;
2526use rustc_span:: source_map:: SourceMap ;
2627use rustc_span:: {
@@ -36,8 +37,9 @@ const TAG_FULL_SPAN: u8 = 0;
3637const TAG_PARTIAL_SPAN : u8 = 1 ;
3738const TAG_RELATIVE_SPAN : u8 = 2 ;
3839
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 ;
4143
4244// Tags for encoding Symbol's
4345const SYMBOL_STR : u8 = 0 ;
@@ -77,7 +79,8 @@ pub struct OnDiskCache<'sess> {
7779 // to represent the fact that we are storing *encoded* ids. When we decode
7880 // a `SyntaxContext`, a new id will be allocated from the global `HygieneData`,
7981 // 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 > ,
8184 // A map from the `DefPathHash` of an `ExpnId` to the position
8285 // of their associated `ExpnData`. Ideally, we would store a `DefId`,
8386 // but we need to decode this before we've constructed a `TyCtxt` (which
@@ -108,7 +111,8 @@ struct Footer {
108111 // without measurable overhead. This permits larger const allocations without ICEing.
109112 interpret_alloc_index : Vec < u64 > ,
110113 // See `OnDiskCache.syntax_contexts`
111- syntax_contexts : FxHashMap < u32 , AbsoluteBytePos > ,
114+ syntax_context_keys : FxHashMap < u32 , AbsoluteBytePos > ,
115+ syntax_context_data : FxHashMap < u32 , AbsoluteBytePos > ,
112116 // See `OnDiskCache.expn_data`
113117 expn_data : UnhashMap < ExpnHash , AbsoluteBytePos > ,
114118 foreign_expn_data : UnhashMap < ExpnHash , u32 > ,
@@ -179,7 +183,8 @@ impl<'sess> OnDiskCache<'sess> {
179183 query_result_index : footer. query_result_index . into_iter ( ) . collect ( ) ,
180184 prev_side_effects_index : footer. side_effects_index . into_iter ( ) . collect ( ) ,
181185 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 ,
183188 expn_data : footer. expn_data ,
184189 foreign_expn_data : footer. foreign_expn_data ,
185190 hygiene_context : Default :: default ( ) ,
@@ -196,7 +201,8 @@ impl<'sess> OnDiskCache<'sess> {
196201 query_result_index : Default :: default ( ) ,
197202 prev_side_effects_index : Default :: default ( ) ,
198203 alloc_decoding_state : AllocDecodingState :: new ( Vec :: new ( ) ) ,
199- syntax_contexts : FxHashMap :: default ( ) ,
204+ syntax_context_keys : FxHashMap :: default ( ) ,
205+ syntax_context_data : FxHashMap :: default ( ) ,
200206 expn_data : UnhashMap :: default ( ) ,
201207 foreign_expn_data : UnhashMap :: default ( ) ,
202208 hygiene_context : Default :: default ( ) ,
@@ -301,7 +307,8 @@ impl<'sess> OnDiskCache<'sess> {
301307 interpret_alloc_index
302308 } ;
303309
304- let mut syntax_contexts = FxHashMap :: default ( ) ;
310+ let mut syntax_context_keys = FxHashMap :: default ( ) ;
311+ let mut syntax_context_data = FxHashMap :: default ( ) ;
305312 let mut expn_data = UnhashMap :: default ( ) ;
306313 let mut foreign_expn_data = UnhashMap :: default ( ) ;
307314
@@ -312,8 +319,12 @@ impl<'sess> OnDiskCache<'sess> {
312319 & mut encoder,
313320 |encoder, index, ctxt_data| {
314321 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) ;
317328 } ,
318329 |encoder, expn_id, data, hash| {
319330 if expn_id. krate == LOCAL_CRATE {
@@ -335,7 +346,8 @@ impl<'sess> OnDiskCache<'sess> {
335346 query_result_index,
336347 side_effects_index,
337348 interpret_alloc_index,
338- syntax_contexts,
349+ syntax_context_keys,
350+ syntax_context_data,
339351 expn_data,
340352 foreign_expn_data,
341353 } ,
@@ -442,7 +454,8 @@ impl<'sess> OnDiskCache<'sess> {
442454 file_index_to_file : & self . file_index_to_file ,
443455 file_index_to_stable_id : & self . file_index_to_stable_id ,
444456 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 ,
446459 expn_data : & self . expn_data ,
447460 foreign_expn_data : & self . foreign_expn_data ,
448461 hygiene_context : & self . hygiene_context ,
@@ -463,7 +476,8 @@ pub struct CacheDecoder<'a, 'tcx> {
463476 file_index_to_file : & ' a Lock < FxHashMap < SourceFileIndex , Lrc < SourceFile > > > ,
464477 file_index_to_stable_id : & ' a FxHashMap < SourceFileIndex , EncodedSourceFileId > ,
465478 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 > ,
467481 expn_data : & ' a UnhashMap < ExpnHash , AbsoluteBytePos > ,
468482 foreign_expn_data : & ' a UnhashMap < ExpnHash , u32 > ,
469483 hygiene_context : & ' a HygieneDecodeContext ,
@@ -584,16 +598,26 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Vec<u8> {
584598
585599impl < ' a , ' tcx > SpanDecoder for CacheDecoder < ' a , ' tcx > {
586600 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+ )
597621 }
598622
599623 fn decode_expn_id ( & mut self ) -> ExpnId {
0 commit comments