@@ -305,7 +305,7 @@ pub struct AllocMap<'tcx> {
305
305
/// Lets you know what an AllocId refers to
306
306
id_to_type : FxHashMap < AllocId , AllocType < ' tcx > > ,
307
307
308
- /// Used to ensure that functions and statics only get one associated AllocId
308
+ /// Used to ensure that statics only get one associated AllocId
309
309
type_interner : FxHashMap < AllocType < ' tcx > , AllocId > ,
310
310
311
311
/// The AllocId to assign to the next requested id.
@@ -347,11 +347,14 @@ impl<'tcx> AllocMap<'tcx> {
347
347
id
348
348
}
349
349
350
- // FIXME: Check if functions have identity. If not, we should not intern these,
351
- // but instead create a new id per use.
352
- // Alternatively we could just make comparing function pointers an error.
350
+ /// Functions cannot be identified by pointers, as asm-equal functions can get deduplicated
351
+ /// by the linker and functions can be duplicated across crates.
352
+ /// We thus generate a new `AllocId` for every mention of a function. This means that
353
+ /// `main as fn() == main as fn()` is false, while `let x = main as fn(); x == x` is true.
353
354
pub fn create_fn_alloc ( & mut self , instance : Instance < ' tcx > ) -> AllocId {
354
- self . intern ( AllocType :: Function ( instance) )
355
+ let id = self . reserve ( ) ;
356
+ self . id_to_type . insert ( id, AllocType :: Function ( instance) ) ;
357
+ id
355
358
}
356
359
357
360
pub fn get ( & self , id : AllocId ) -> Option < AllocType < ' tcx > > {
0 commit comments