@@ -41,7 +41,6 @@ use ty::{self, TyCtxt, Instance};
41
41
use ty:: layout:: { self , Size } ;
42
42
use middle:: region;
43
43
use std:: io;
44
- use std:: hash:: Hash ;
45
44
use rustc_serialize:: { Encoder , Decodable , Encodable } ;
46
45
use rustc_data_structures:: fx:: FxHashMap ;
47
46
use rustc_data_structures:: sync:: { Lock as Mutex , HashMapExt } ;
@@ -302,19 +301,19 @@ pub enum AllocType<'tcx, M> {
302
301
Memory ( M )
303
302
}
304
303
305
- pub struct AllocMap < ' tcx , M > {
304
+ pub struct AllocMap < ' tcx > {
306
305
/// Lets you know what an AllocId refers to
307
- id_to_type : FxHashMap < AllocId , AllocType < ' tcx , M > > ,
306
+ id_to_type : FxHashMap < AllocId , AllocType < ' tcx , & ' tcx Allocation > > ,
308
307
309
308
/// Used to ensure that functions and statics only get one associated AllocId
310
- type_interner : FxHashMap < AllocType < ' tcx , M > , AllocId > ,
309
+ type_interner : FxHashMap < AllocType < ' tcx , & ' tcx Allocation > , AllocId > ,
311
310
312
311
/// The AllocId to assign to the next requested id.
313
312
/// Always incremented, never gets smaller.
314
313
next_id : AllocId ,
315
314
}
316
315
317
- impl < ' tcx , M : fmt :: Debug + Eq + Hash + Clone > AllocMap < ' tcx , M > {
316
+ impl < ' tcx > AllocMap < ' tcx > {
318
317
pub fn new ( ) -> Self {
319
318
AllocMap {
320
319
id_to_type : Default :: default ( ) ,
@@ -337,7 +336,7 @@ impl<'tcx, M: fmt::Debug + Eq + Hash + Clone> AllocMap<'tcx, M> {
337
336
next
338
337
}
339
338
340
- fn intern ( & mut self , alloc_type : AllocType < ' tcx , M > ) -> AllocId {
339
+ fn intern ( & mut self , alloc_type : AllocType < ' tcx , & ' tcx Allocation > ) -> AllocId {
341
340
if let Some ( & alloc_id) = self . type_interner . get ( & alloc_type) {
342
341
return alloc_id;
343
342
}
@@ -355,11 +354,11 @@ impl<'tcx, M: fmt::Debug + Eq + Hash + Clone> AllocMap<'tcx, M> {
355
354
self . intern ( AllocType :: Function ( instance) )
356
355
}
357
356
358
- pub fn get ( & self , id : AllocId ) -> Option < AllocType < ' tcx , M > > {
357
+ pub fn get ( & self , id : AllocId ) -> Option < AllocType < ' tcx , & ' tcx Allocation > > {
359
358
self . id_to_type . get ( & id) . cloned ( )
360
359
}
361
360
362
- pub fn unwrap_memory ( & self , id : AllocId ) -> M {
361
+ pub fn unwrap_memory ( & self , id : AllocId ) -> & ' tcx Allocation {
363
362
match self . get ( id) {
364
363
Some ( AllocType :: Memory ( mem) ) => mem,
365
364
_ => bug ! ( "expected allocation id {} to point to memory" , id) ,
@@ -370,19 +369,19 @@ impl<'tcx, M: fmt::Debug + Eq + Hash + Clone> AllocMap<'tcx, M> {
370
369
self . intern ( AllocType :: Static ( static_id) )
371
370
}
372
371
373
- pub fn allocate ( & mut self , mem : M ) -> AllocId {
372
+ pub fn allocate ( & mut self , mem : & ' tcx Allocation ) -> AllocId {
374
373
let id = self . reserve ( ) ;
375
374
self . set_id_memory ( id, mem) ;
376
375
id
377
376
}
378
377
379
- pub fn set_id_memory ( & mut self , id : AllocId , mem : M ) {
378
+ pub fn set_id_memory ( & mut self , id : AllocId , mem : & ' tcx Allocation ) {
380
379
if let Some ( old) = self . id_to_type . insert ( id, AllocType :: Memory ( mem) ) {
381
380
bug ! ( "tried to set allocation id {}, but it was already existing as {:#?}" , id, old) ;
382
381
}
383
382
}
384
383
385
- pub fn set_id_same_memory ( & mut self , id : AllocId , mem : M ) {
384
+ pub fn set_id_same_memory ( & mut self , id : AllocId , mem : & ' tcx Allocation ) {
386
385
self . id_to_type . insert_same ( id, AllocType :: Memory ( mem) ) ;
387
386
}
388
387
}
0 commit comments