@@ -16,14 +16,14 @@ use hir::def_id::{CrateNum, DefIndex, DefId, LocalDefId,
16
16
use hir:: map:: definitions:: DefPathHash ;
17
17
use ich:: { CachingCodemapView , Fingerprint } ;
18
18
use mir:: { self , interpret} ;
19
+ use mir:: interpret:: { AllocDecodingSession , AllocDecodingState } ;
19
20
use rustc_data_structures:: fx:: FxHashMap ;
20
21
use rustc_data_structures:: sync:: { Lrc , Lock , HashMapExt , Once } ;
21
22
use rustc_data_structures:: indexed_vec:: { IndexVec , Idx } ;
22
23
use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder , opaque,
23
24
SpecializedDecoder , SpecializedEncoder ,
24
25
UseSpecializedDecodable , UseSpecializedEncodable } ;
25
26
use session:: { CrateDisambiguator , Session } ;
26
- use std:: cell:: RefCell ;
27
27
use std:: mem;
28
28
use syntax:: ast:: NodeId ;
29
29
use syntax:: codemap:: { CodeMap , StableFilemapId } ;
@@ -77,11 +77,7 @@ pub struct OnDiskCache<'sess> {
77
77
// `serialized_data`.
78
78
prev_diagnostics_index : FxHashMap < SerializedDepNodeIndex , AbsoluteBytePos > ,
79
79
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 ,
85
81
}
86
82
87
83
// This type is used only for (de-)serialization.
@@ -92,7 +88,7 @@ struct Footer {
92
88
query_result_index : EncodedQueryResultIndex ,
93
89
diagnostics_index : EncodedQueryResultIndex ,
94
90
// the location of all allocations
95
- interpret_alloc_index : Vec < AbsoluteBytePos > ,
91
+ interpret_alloc_index : Vec < u32 > ,
96
92
}
97
93
98
94
type EncodedQueryResultIndex = Vec < ( SerializedDepNodeIndex , AbsoluteBytePos ) > ;
@@ -149,8 +145,7 @@ impl<'sess> OnDiskCache<'sess> {
149
145
query_result_index : footer. query_result_index . into_iter ( ) . collect ( ) ,
150
146
prev_diagnostics_index : footer. diagnostics_index . into_iter ( ) . collect ( ) ,
151
147
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 ) ,
154
149
}
155
150
}
156
151
@@ -166,8 +161,7 @@ impl<'sess> OnDiskCache<'sess> {
166
161
query_result_index : FxHashMap ( ) ,
167
162
prev_diagnostics_index : FxHashMap ( ) ,
168
163
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 ( ) ) ,
171
165
}
172
166
}
173
167
@@ -291,7 +285,7 @@ impl<'sess> OnDiskCache<'sess> {
291
285
}
292
286
for idx in n..new_n {
293
287
let id = encoder. interpret_allocs_inverse [ idx] ;
294
- let pos = AbsoluteBytePos :: new ( encoder. position ( ) ) ;
288
+ let pos = encoder. position ( ) as u32 ;
295
289
interpret_alloc_index. push ( pos) ;
296
290
interpret:: specialized_encode_alloc_id (
297
291
& mut encoder,
@@ -424,8 +418,7 @@ impl<'sess> OnDiskCache<'sess> {
424
418
file_index_to_file : & self . file_index_to_file ,
425
419
file_index_to_stable_id : & self . file_index_to_stable_id ,
426
420
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 ( ) ,
429
422
} ;
430
423
431
424
match decode_tagged ( & mut decoder, dep_node_index) {
@@ -487,9 +480,7 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
487
480
synthetic_expansion_infos : & ' x Lock < FxHashMap < AbsoluteBytePos , SyntaxContext > > ,
488
481
file_index_to_file : & ' x Lock < FxHashMap < FileMapIndex , Lrc < FileMap > > > ,
489
482
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 > ,
493
484
}
494
485
495
486
impl < ' a , ' tcx , ' x > CacheDecoder < ' a , ' tcx , ' x > {
@@ -612,30 +603,8 @@ implement_ty_decoder!( CacheDecoder<'a, 'tcx, 'x> );
612
603
613
604
impl < ' a , ' tcx , ' x > SpecializedDecoder < interpret:: AllocId > for CacheDecoder < ' a , ' tcx , ' x > {
614
605
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 )
639
608
}
640
609
}
641
610
impl < ' a , ' tcx , ' x > SpecializedDecoder < Span > for CacheDecoder < ' a , ' tcx , ' x > {
0 commit comments