@@ -25,12 +25,12 @@ use rustc::hir::def_id::{CrateNum, DefId, DefIndex,
25
25
use rustc:: ich:: Fingerprint ;
26
26
use rustc:: middle:: lang_items;
27
27
use rustc:: mir:: { self , interpret} ;
28
+ use rustc:: mir:: interpret:: AllocDecodingSession ;
28
29
use rustc:: session:: Session ;
29
30
use rustc:: ty:: { self , Ty , TyCtxt } ;
30
31
use rustc:: ty:: codec:: TyDecoder ;
31
32
use rustc:: mir:: Mir ;
32
33
use rustc:: util:: captures:: Captures ;
33
- use rustc:: util:: nodemap:: FxHashMap ;
34
34
35
35
use std:: io;
36
36
use std:: mem;
@@ -55,11 +55,8 @@ pub struct DecodeContext<'a, 'tcx: 'a> {
55
55
56
56
lazy_state : LazyState ,
57
57
58
- // interpreter allocation cache
59
- interpret_alloc_cache : FxHashMap < usize , interpret:: AllocId > ,
60
-
61
- // Read from the LazySeq CrateRoot::inpterpret_alloc_index on demand
62
- interpret_alloc_index : Option < Vec < u32 > > ,
58
+ // Used for decoding interpret::AllocIds in a cached & thread-safe manner.
59
+ alloc_decoding_session : Option < AllocDecodingSession < ' a > > ,
63
60
}
64
61
65
62
/// Abstract over the various ways one can create metadata decoders.
@@ -78,8 +75,9 @@ pub trait Metadata<'a, 'tcx>: Copy {
78
75
tcx,
79
76
last_filemap_index : 0 ,
80
77
lazy_state : LazyState :: NoNode ,
81
- interpret_alloc_cache : FxHashMap :: default ( ) ,
82
- interpret_alloc_index : None ,
78
+ alloc_decoding_session : self . cdata ( ) . map ( |cdata| {
79
+ cdata. alloc_decoding_state . new_decoding_session ( )
80
+ } ) ,
83
81
}
84
82
}
85
83
}
@@ -178,17 +176,6 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
178
176
self . lazy_state = LazyState :: Previous ( position + min_size) ;
179
177
Ok ( position)
180
178
}
181
-
182
- fn interpret_alloc ( & mut self , idx : usize ) -> usize {
183
- if let Some ( index) = self . interpret_alloc_index . as_mut ( ) {
184
- return index[ idx] as usize ;
185
- }
186
- let cdata = self . cdata ( ) ;
187
- let index: Vec < u32 > = cdata. root . interpret_alloc_index . decode ( cdata) . collect ( ) ;
188
- let pos = index[ idx] ;
189
- self . interpret_alloc_index = Some ( index) ;
190
- pos as usize
191
- }
192
179
}
193
180
194
181
impl < ' a , ' tcx : ' a > TyDecoder < ' a , ' tcx > for DecodeContext < ' a , ' tcx > {
@@ -299,22 +286,11 @@ impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for DecodeContext<'a, 'tcx> {
299
286
300
287
impl < ' a , ' tcx > SpecializedDecoder < interpret:: AllocId > for DecodeContext < ' a , ' tcx > {
301
288
fn specialized_decode ( & mut self ) -> Result < interpret:: AllocId , Self :: Error > {
302
- let tcx = self . tcx . unwrap ( ) ;
303
- let idx = usize:: decode ( self ) ?;
304
-
305
- if let Some ( cached) = self . interpret_alloc_cache . get ( & idx) . cloned ( ) {
306
- return Ok ( cached) ;
289
+ if let Some ( alloc_decoding_session) = self . alloc_decoding_session {
290
+ alloc_decoding_session. decode_alloc_id ( self )
291
+ } else {
292
+ bug ! ( "Attempting to decode interpret::AllocId without CrateMetadata" )
307
293
}
308
- let pos = self . interpret_alloc ( idx) ;
309
- self . with_position ( pos, |this| {
310
- interpret:: specialized_decode_alloc_id (
311
- this,
312
- tcx,
313
- |this, alloc_id| {
314
- assert ! ( this. interpret_alloc_cache. insert( idx, alloc_id) . is_none( ) ) ;
315
- } ,
316
- )
317
- } )
318
294
}
319
295
}
320
296
0 commit comments