@@ -16,14 +16,14 @@ use hir::def_id::{CrateNum, DefIndex, DefId, LocalDefId,
1616use hir:: map:: definitions:: DefPathHash ;
1717use ich:: { CachingCodemapView , Fingerprint } ;
1818use mir:: { self , interpret} ;
19+ use mir:: interpret:: { AllocDecodingSession , AllocDecodingState } ;
1920use rustc_data_structures:: fx:: FxHashMap ;
2021use rustc_data_structures:: sync:: { Lrc , Lock , HashMapExt , Once } ;
2122use rustc_data_structures:: indexed_vec:: { IndexVec , Idx } ;
2223use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder , opaque,
2324 SpecializedDecoder , SpecializedEncoder ,
2425 UseSpecializedDecodable , UseSpecializedEncodable } ;
2526use session:: { CrateDisambiguator , Session } ;
26- use std:: cell:: RefCell ;
2727use std:: mem;
2828use syntax:: ast:: NodeId ;
2929use syntax:: codemap:: { CodeMap , StableFilemapId } ;
@@ -77,11 +77,7 @@ pub struct OnDiskCache<'sess> {
7777 // `serialized_data`.
7878 prev_diagnostics_index : FxHashMap < SerializedDepNodeIndex , AbsoluteBytePos > ,
7979
80- // Alloc indices to memory location map
81- prev_interpret_alloc_index : Vec < AbsoluteBytePos > ,
82-
83- /// Deserialization: A cache to ensure we don't read allocations twice
84- interpret_alloc_cache : RefCell < FxHashMap < usize , interpret:: AllocId > > ,
80+ alloc_decoding_state : AllocDecodingState ,
8581}
8682
8783// This type is used only for (de-)serialization.
@@ -92,7 +88,7 @@ struct Footer {
9288 query_result_index : EncodedQueryResultIndex ,
9389 diagnostics_index : EncodedQueryResultIndex ,
9490 // the location of all allocations
95- interpret_alloc_index : Vec < AbsoluteBytePos > ,
91+ interpret_alloc_index : Vec < u32 > ,
9692}
9793
9894type EncodedQueryResultIndex = Vec < ( SerializedDepNodeIndex , AbsoluteBytePos ) > ;
@@ -149,8 +145,7 @@ impl<'sess> OnDiskCache<'sess> {
149145 query_result_index : footer. query_result_index . into_iter ( ) . collect ( ) ,
150146 prev_diagnostics_index : footer. diagnostics_index . into_iter ( ) . collect ( ) ,
151147 synthetic_expansion_infos : Lock :: new ( FxHashMap ( ) ) ,
152- prev_interpret_alloc_index : footer. interpret_alloc_index ,
153- interpret_alloc_cache : RefCell :: new ( FxHashMap :: default ( ) ) ,
148+ alloc_decoding_state : AllocDecodingState :: new ( footer. interpret_alloc_index ) ,
154149 }
155150 }
156151
@@ -166,8 +161,7 @@ impl<'sess> OnDiskCache<'sess> {
166161 query_result_index : FxHashMap ( ) ,
167162 prev_diagnostics_index : FxHashMap ( ) ,
168163 synthetic_expansion_infos : Lock :: new ( FxHashMap ( ) ) ,
169- prev_interpret_alloc_index : Vec :: new ( ) ,
170- interpret_alloc_cache : RefCell :: new ( FxHashMap :: default ( ) ) ,
164+ alloc_decoding_state : AllocDecodingState :: new ( Vec :: new ( ) ) ,
171165 }
172166 }
173167
@@ -291,7 +285,7 @@ impl<'sess> OnDiskCache<'sess> {
291285 }
292286 for idx in n..new_n {
293287 let id = encoder. interpret_allocs_inverse [ idx] ;
294- let pos = AbsoluteBytePos :: new ( encoder. position ( ) ) ;
288+ let pos = encoder. position ( ) as u32 ;
295289 interpret_alloc_index. push ( pos) ;
296290 interpret:: specialized_encode_alloc_id (
297291 & mut encoder,
@@ -424,8 +418,7 @@ impl<'sess> OnDiskCache<'sess> {
424418 file_index_to_file : & self . file_index_to_file ,
425419 file_index_to_stable_id : & self . file_index_to_stable_id ,
426420 synthetic_expansion_infos : & self . synthetic_expansion_infos ,
427- prev_interpret_alloc_index : & self . prev_interpret_alloc_index ,
428- interpret_alloc_cache : & self . interpret_alloc_cache ,
421+ alloc_decoding_session : self . alloc_decoding_state . new_decoding_session ( ) ,
429422 } ;
430423
431424 match decode_tagged ( & mut decoder, dep_node_index) {
@@ -487,9 +480,7 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
487480 synthetic_expansion_infos : & ' x Lock < FxHashMap < AbsoluteBytePos , SyntaxContext > > ,
488481 file_index_to_file : & ' x Lock < FxHashMap < FileMapIndex , Lrc < FileMap > > > ,
489482 file_index_to_stable_id : & ' x FxHashMap < FileMapIndex , StableFilemapId > ,
490- interpret_alloc_cache : & ' x RefCell < FxHashMap < usize , interpret:: AllocId > > ,
491- /// maps from index in the cache file to location in the cache file
492- prev_interpret_alloc_index : & ' x [ AbsoluteBytePos ] ,
483+ alloc_decoding_session : AllocDecodingSession < ' x > ,
493484}
494485
495486impl < ' a , ' tcx , ' x > CacheDecoder < ' a , ' tcx , ' x > {
@@ -612,30 +603,8 @@ implement_ty_decoder!( CacheDecoder<'a, 'tcx, 'x> );
612603
613604impl < ' a , ' tcx , ' x > SpecializedDecoder < interpret:: AllocId > for CacheDecoder < ' a , ' tcx , ' x > {
614605 fn specialized_decode ( & mut self ) -> Result < interpret:: AllocId , Self :: Error > {
615- let tcx = self . tcx ;
616- let idx = usize:: decode ( self ) ?;
617- trace ! ( "loading index {}" , idx) ;
618-
619- if let Some ( cached) = self . interpret_alloc_cache . borrow ( ) . get ( & idx) . cloned ( ) {
620- trace ! ( "loading alloc id {:?} from alloc_cache" , cached) ;
621- return Ok ( cached) ;
622- }
623- let pos = self . prev_interpret_alloc_index [ idx] . to_usize ( ) ;
624- trace ! ( "loading position {}" , pos) ;
625- self . with_position ( pos, |this| {
626- interpret:: specialized_decode_alloc_id (
627- this,
628- tcx,
629- |this, alloc_id| {
630- trace ! ( "caching idx {} for alloc id {} at position {}" , idx, alloc_id, pos) ;
631- assert ! ( this
632- . interpret_alloc_cache
633- . borrow_mut( )
634- . insert( idx, alloc_id)
635- . is_none( ) ) ;
636- } ,
637- )
638- } )
606+ let alloc_decoding_session = self . alloc_decoding_session ;
607+ alloc_decoding_session. decode_alloc_id ( self )
639608 }
640609}
641610impl < ' a , ' tcx , ' x > SpecializedDecoder < Span > for CacheDecoder < ' a , ' tcx , ' x > {
0 commit comments