@@ -104,6 +104,7 @@ enum AllocDiscriminant {
104104 VTable ,
105105 Static ,
106106 Type ,
107+ PartialHash ,
107108}
108109
109110pub fn specialized_encode_alloc_id < ' tcx , E : TyEncoder < ' tcx > > (
@@ -133,6 +134,11 @@ pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<'tcx>>(
133134 AllocDiscriminant :: Type . encode ( encoder) ;
134135 ty. encode ( encoder) ;
135136 }
137+ GlobalAlloc :: PartialHash ( ty) => {
138+ trace ! ( "encoding {alloc_id:?} with {ty:#?}" ) ;
139+ AllocDiscriminant :: PartialHash . encode ( encoder) ;
140+ ty. encode ( encoder) ;
141+ }
136142 GlobalAlloc :: Static ( did) => {
137143 assert ! ( !tcx. is_thread_local_static( did) ) ;
138144 // References to statics doesn't need to know about their allocations,
@@ -240,6 +246,12 @@ impl<'s> AllocDecodingSession<'s> {
240246 trace ! ( "decoded typid: {ty:?}" ) ;
241247 decoder. interner ( ) . reserve_and_set_type_id_alloc ( ty)
242248 }
249+ AllocDiscriminant :: PartialHash => {
250+ trace ! ( "creating typeid alloc ID" ) ;
251+ let ty = Decodable :: decode ( decoder) ;
252+ trace ! ( "decoded typid: {ty:?}" ) ;
253+ decoder. interner ( ) . reserve_and_set_type_id_partial_hash ( ty)
254+ }
243255 AllocDiscriminant :: Static => {
244256 trace ! ( "creating extern static alloc ID" ) ;
245257 let did = <DefId as Decodable < D > >:: decode ( decoder) ;
@@ -270,9 +282,10 @@ pub enum GlobalAlloc<'tcx> {
270282 Static ( DefId ) ,
271283 /// The alloc ID points to memory.
272284 Memory ( ConstAllocation < ' tcx > ) ,
273- /// A TypeId pointer. For now cannot be turned into a runtime value.
274- /// TODO: turn into actual TypeId?
285+ /// A pointer to be stored within a TypeId pointing to the full hash.
275286 Type ( Ty < ' tcx > ) ,
287+ /// A partial type hash (the first `size_of<usize>()` bytes of the hash).
288+ PartialHash ( Ty < ' tcx > ) ,
276289}
277290
278291impl < ' tcx > GlobalAlloc < ' tcx > {
@@ -312,6 +325,7 @@ impl<'tcx> GlobalAlloc<'tcx> {
312325 match self {
313326 GlobalAlloc :: Function { .. } => cx. data_layout ( ) . instruction_address_space ,
314327 GlobalAlloc :: Type ( _)
328+ | GlobalAlloc :: PartialHash ( _)
315329 | GlobalAlloc :: Static ( ..)
316330 | GlobalAlloc :: Memory ( ..)
317331 | GlobalAlloc :: VTable ( ..) => AddressSpace :: DATA ,
@@ -350,7 +364,10 @@ impl<'tcx> GlobalAlloc<'tcx> {
350364 }
351365 }
352366 GlobalAlloc :: Memory ( alloc) => alloc. inner ( ) . mutability ,
353- GlobalAlloc :: Type ( _) | GlobalAlloc :: Function { .. } | GlobalAlloc :: VTable ( ..) => {
367+ GlobalAlloc :: PartialHash ( _)
368+ | GlobalAlloc :: Type ( _)
369+ | GlobalAlloc :: Function { .. }
370+ | GlobalAlloc :: VTable ( ..) => {
354371 // These are immutable.
355372 Mutability :: Not
356373 }
@@ -398,8 +415,8 @@ impl<'tcx> GlobalAlloc<'tcx> {
398415 // No data to be accessed here. But vtables are pointer-aligned.
399416 ( Size :: ZERO , tcx. data_layout . pointer_align . abi )
400417 }
401- // TODO make this represent normal type ids somehow
402- GlobalAlloc :: Type ( _) => ( Size :: from_bytes ( 16 ) , Align :: from_bytes ( 8 ) . unwrap ( ) ) ,
418+ GlobalAlloc :: Type ( _ ) => ( Size :: from_bytes ( 16 ) , Align :: ONE ) ,
419+ GlobalAlloc :: PartialHash ( _) => ( Size :: ZERO , Align :: ONE ) ,
403420 }
404421 }
405422}
@@ -505,11 +522,17 @@ impl<'tcx> TyCtxt<'tcx> {
505522 self . reserve_and_set_dedup ( GlobalAlloc :: VTable ( ty, dyn_ty) , salt)
506523 }
507524
508- /// Generates an [AllocId] for a [core::mem::type_info::TypeId ]. Will get deduplicated.
525+ /// Generates an [AllocId] for a [core::mem::type_info::TypeIdData ]. Will get deduplicated.
509526 pub fn reserve_and_set_type_id_alloc ( self , ty : Ty < ' tcx > ) -> AllocId {
510527 self . reserve_and_set_dedup ( GlobalAlloc :: Type ( ty) , 0 )
511528 }
512529
530+ /// Generates an [AllocId] that will get replaced by a partial hash of a type.
531+ /// See [core::mem::type_info::TypeId] for more information.
532+ pub fn reserve_and_set_type_id_partial_hash ( self , ty : Ty < ' tcx > ) -> AllocId {
533+ self . reserve_and_set_dedup ( GlobalAlloc :: PartialHash ( ty) , 0 )
534+ }
535+
513536 /// Interns the `Allocation` and return a new `AllocId`, even if there's already an identical
514537 /// `Allocation` with a different `AllocId`.
515538 /// Statics with identical content will still point to the same `Allocation`, i.e.,
0 commit comments