@@ -23,7 +23,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque,
23
23
SpecializedDecoder , SpecializedEncoder ,
24
24
UseSpecializedDecodable , UseSpecializedEncodable } ;
25
25
use session:: { CrateDisambiguator , Session } ;
26
- use std:: cell:: RefCell ;
27
26
use std:: mem;
28
27
use syntax:: ast:: NodeId ;
29
28
use syntax:: codemap:: { CodeMap , StableFilemapId } ;
@@ -77,11 +76,8 @@ pub struct OnDiskCache<'sess> {
77
76
// `serialized_data`.
78
77
prev_diagnostics_index : FxHashMap < SerializedDepNodeIndex , AbsoluteBytePos > ,
79
78
80
- // Alloc indices to memory location map
81
- prev_interpret_alloc_index : Vec < AbsoluteBytePos > ,
82
-
83
79
/// Deserialization: A cache to ensure we don't read allocations twice
84
- interpret_alloc_cache : RefCell < FxHashMap < usize , interpret:: AllocId > > ,
80
+ interpret_alloc_cache : Lock < FxHashMap < usize , interpret:: AllocId > > ,
85
81
}
86
82
87
83
// This type is used only for (de-)serialization.
@@ -91,8 +87,6 @@ struct Footer {
91
87
prev_cnums : Vec < ( u32 , String , CrateDisambiguator ) > ,
92
88
query_result_index : EncodedQueryResultIndex ,
93
89
diagnostics_index : EncodedQueryResultIndex ,
94
- // the location of all allocations
95
- interpret_alloc_index : Vec < AbsoluteBytePos > ,
96
90
}
97
91
98
92
type EncodedQueryResultIndex = Vec < ( SerializedDepNodeIndex , AbsoluteBytePos ) > ;
@@ -149,8 +143,7 @@ impl<'sess> OnDiskCache<'sess> {
149
143
query_result_index : footer. query_result_index . into_iter ( ) . collect ( ) ,
150
144
prev_diagnostics_index : footer. diagnostics_index . into_iter ( ) . collect ( ) ,
151
145
synthetic_expansion_infos : Lock :: new ( FxHashMap ( ) ) ,
152
- prev_interpret_alloc_index : footer. interpret_alloc_index ,
153
- interpret_alloc_cache : RefCell :: new ( FxHashMap :: default ( ) ) ,
146
+ interpret_alloc_cache : Lock :: new ( FxHashMap :: default ( ) ) ,
154
147
}
155
148
}
156
149
@@ -166,8 +159,7 @@ impl<'sess> OnDiskCache<'sess> {
166
159
query_result_index : FxHashMap ( ) ,
167
160
prev_diagnostics_index : FxHashMap ( ) ,
168
161
synthetic_expansion_infos : Lock :: new ( FxHashMap ( ) ) ,
169
- prev_interpret_alloc_index : Vec :: new ( ) ,
170
- interpret_alloc_cache : RefCell :: new ( FxHashMap :: default ( ) ) ,
162
+ interpret_alloc_cache : Lock :: new ( FxHashMap :: default ( ) ) ,
171
163
}
172
164
}
173
165
@@ -201,7 +193,6 @@ impl<'sess> OnDiskCache<'sess> {
201
193
predicate_shorthands : FxHashMap ( ) ,
202
194
expn_info_shorthands : FxHashMap ( ) ,
203
195
interpret_allocs : FxHashMap ( ) ,
204
- interpret_allocs_inverse : Vec :: new ( ) ,
205
196
codemap : CachingCodemapView :: new ( tcx. sess . codemap ( ) ) ,
206
197
file_to_file_index,
207
198
} ;
@@ -279,31 +270,6 @@ impl<'sess> OnDiskCache<'sess> {
279
270
diagnostics_index
280
271
} ;
281
272
282
- let interpret_alloc_index = {
283
- let mut interpret_alloc_index = Vec :: new ( ) ;
284
- let mut n = 0 ;
285
- loop {
286
- let new_n = encoder. interpret_allocs_inverse . len ( ) ;
287
- // if we have found new ids, serialize those, too
288
- if n == new_n {
289
- // otherwise, abort
290
- break ;
291
- }
292
- for idx in n..new_n {
293
- let id = encoder. interpret_allocs_inverse [ idx] ;
294
- let pos = AbsoluteBytePos :: new ( encoder. position ( ) ) ;
295
- interpret_alloc_index. push ( pos) ;
296
- interpret:: specialized_encode_alloc_id (
297
- & mut encoder,
298
- tcx,
299
- id,
300
- ) ?;
301
- }
302
- n = new_n;
303
- }
304
- interpret_alloc_index
305
- } ;
306
-
307
273
let sorted_cnums = sorted_cnums_including_local_crate ( tcx) ;
308
274
let prev_cnums: Vec < _ > = sorted_cnums. iter ( ) . map ( |& cnum| {
309
275
let crate_name = tcx. original_crate_name ( cnum) . as_str ( ) . to_string ( ) ;
@@ -318,7 +284,6 @@ impl<'sess> OnDiskCache<'sess> {
318
284
prev_cnums,
319
285
query_result_index,
320
286
diagnostics_index,
321
- interpret_alloc_index,
322
287
} ) ?;
323
288
324
289
// Encode the position of the footer as the last 8 bytes of the
@@ -424,7 +389,6 @@ impl<'sess> OnDiskCache<'sess> {
424
389
file_index_to_file : & self . file_index_to_file ,
425
390
file_index_to_stable_id : & self . file_index_to_stable_id ,
426
391
synthetic_expansion_infos : & self . synthetic_expansion_infos ,
427
- prev_interpret_alloc_index : & self . prev_interpret_alloc_index ,
428
392
interpret_alloc_cache : & self . interpret_alloc_cache ,
429
393
} ;
430
394
@@ -487,9 +451,7 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
487
451
synthetic_expansion_infos : & ' x Lock < FxHashMap < AbsoluteBytePos , SyntaxContext > > ,
488
452
file_index_to_file : & ' x Lock < FxHashMap < FileMapIndex , Lrc < FileMap > > > ,
489
453
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 ] ,
454
+ interpret_alloc_cache : & ' x Lock < FxHashMap < usize , interpret:: AllocId > > ,
493
455
}
494
456
495
457
impl < ' a , ' tcx , ' x > CacheDecoder < ' a , ' tcx , ' x > {
@@ -613,31 +575,14 @@ implement_ty_decoder!( CacheDecoder<'a, 'tcx, 'x> );
613
575
impl < ' a , ' tcx , ' x > SpecializedDecoder < interpret:: AllocId > for CacheDecoder < ' a , ' tcx , ' x > {
614
576
fn specialized_decode ( & mut self ) -> Result < interpret:: AllocId , Self :: Error > {
615
577
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
- } )
578
+ interpret:: specialized_decode_alloc_id (
579
+ self ,
580
+ tcx,
581
+ |this| this. interpret_alloc_cache . lock ( ) ,
582
+ )
639
583
}
640
584
}
585
+
641
586
impl < ' a , ' tcx , ' x > SpecializedDecoder < Span > for CacheDecoder < ' a , ' tcx , ' x > {
642
587
fn specialized_decode ( & mut self ) -> Result < Span , Self :: Error > {
643
588
let tag: u8 = Decodable :: decode ( self ) ?;
@@ -800,7 +745,6 @@ struct CacheEncoder<'enc, 'a, 'tcx, E>
800
745
predicate_shorthands : FxHashMap < ty:: Predicate < ' tcx > , usize > ,
801
746
expn_info_shorthands : FxHashMap < Mark , AbsoluteBytePos > ,
802
747
interpret_allocs : FxHashMap < interpret:: AllocId , usize > ,
803
- interpret_allocs_inverse : Vec < interpret:: AllocId > ,
804
748
codemap : CachingCodemapView < ' tcx > ,
805
749
file_to_file_index : FxHashMap < * const FileMap , FileMapIndex > ,
806
750
}
@@ -837,18 +781,13 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<interpret::AllocId> for CacheEncoder<
837
781
where E : ' enc + ty_codec:: TyEncoder
838
782
{
839
783
fn specialized_encode ( & mut self , alloc_id : & interpret:: AllocId ) -> Result < ( ) , Self :: Error > {
840
- use std:: collections:: hash_map:: Entry ;
841
- let index = match self . interpret_allocs . entry ( * alloc_id) {
842
- Entry :: Occupied ( e) => * e. get ( ) ,
843
- Entry :: Vacant ( e) => {
844
- let idx = self . interpret_allocs_inverse . len ( ) ;
845
- self . interpret_allocs_inverse . push ( * alloc_id) ;
846
- e. insert ( idx) ;
847
- idx
848
- } ,
849
- } ;
850
-
851
- index. encode ( self )
784
+ let tcx = self . tcx ;
785
+ interpret:: specialized_encode_alloc_id (
786
+ self ,
787
+ tcx,
788
+ |this| & mut this. interpret_allocs ,
789
+ * alloc_id,
790
+ )
852
791
}
853
792
}
854
793
0 commit comments