@@ -25,7 +25,7 @@ use crate::ty;
2525/// module provides higher-level access.
2626#[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord , Hash , TyEncodable , TyDecodable ) ]
2727#[ derive( HashStable ) ]
28- pub struct Allocation < Tag = ( ) , Extra = ( ) > {
28+ pub struct Allocation < Tag = AllocId , Extra = ( ) > {
2929 /// The actual bytes of the allocation.
3030 /// Note that the bytes of a pointer represent the offset of the pointer.
3131 bytes : Vec < u8 > ,
@@ -154,25 +154,17 @@ impl<Tag> Allocation<Tag> {
154154 }
155155}
156156
157- impl Allocation < ( ) > {
158- /// Add Tag and Extra fields
159- pub fn with_tags_and_extra < T , E > (
157+ impl Allocation {
158+ /// Convert Tag and add Extra fields
159+ pub fn with_prov_and_extra < Tag , Extra > (
160160 self ,
161- mut tagger : impl FnMut ( AllocId ) -> T ,
162- extra : E ,
163- ) -> Allocation < T , E > {
161+ mut tagger : impl FnMut ( AllocId ) -> Tag ,
162+ extra : Extra ,
163+ ) -> Allocation < Tag , Extra > {
164164 Allocation {
165165 bytes : self . bytes ,
166166 relocations : Relocations :: from_presorted (
167- self . relocations
168- . iter ( )
169- // The allocations in the relocations (pointers stored *inside* this allocation)
170- // all get the base pointer tag.
171- . map ( |& ( offset, ( ( ) , alloc) ) | {
172- let tag = tagger ( alloc) ;
173- ( offset, ( tag, alloc) )
174- } )
175- . collect ( ) ,
167+ self . relocations . iter ( ) . map ( |& ( offset, tag) | ( offset, tagger ( tag) ) ) . collect ( ) ,
176168 ) ,
177169 init_mask : self . init_mask ,
178170 align : self . align ,
@@ -339,8 +331,8 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
339331 self . check_relocations ( cx, range) ?;
340332 } else {
341333 // Maybe a pointer.
342- if let Some ( & ( tag , alloc_id ) ) = self . relocations . get ( & range. start ) {
343- let ptr = Pointer :: new_with_tag ( alloc_id , Size :: from_bytes ( bits) , tag ) ;
334+ if let Some ( & prov ) = self . relocations . get ( & range. start ) {
335+ let ptr = Pointer :: new ( prov , Size :: from_bytes ( bits) ) ;
344336 return Ok ( ScalarMaybeUninit :: Scalar ( ptr. into ( ) ) ) ;
345337 }
346338 }
@@ -371,18 +363,21 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
371363 }
372364 } ;
373365
374- let bytes = match val. to_bits_or_ptr ( range. size , cx) {
375- Err ( val) => u128:: from ( val. offset . bytes ( ) ) ,
376- Ok ( data) => data,
366+ let ( bytes, provenance) = match val. to_bits_or_ptr ( range. size , cx) {
367+ Err ( val) => {
368+ let ( provenance, offset) = val. into_parts ( ) ;
369+ ( u128:: from ( offset. bytes ( ) ) , Some ( provenance) )
370+ }
371+ Ok ( data) => ( data, None ) ,
377372 } ;
378373
379374 let endian = cx. data_layout ( ) . endian ;
380375 let dst = self . get_bytes_mut ( cx, range) ;
381376 write_target_uint ( endian, dst, bytes) . unwrap ( ) ;
382377
383378 // See if we have to also write a relocation.
384- if let Scalar :: Ptr ( val ) = val {
385- self . relocations . insert ( range. start , ( val . tag , val . alloc_id ) ) ;
379+ if let Some ( provenance ) = provenance {
380+ self . relocations . insert ( range. start , provenance ) ;
386381 }
387382
388383 Ok ( ( ) )
@@ -392,11 +387,7 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
392387/// Relocations.
393388impl < Tag : Copy , Extra > Allocation < Tag , Extra > {
394389 /// Returns all relocations overlapping with the given pointer-offset pair.
395- pub fn get_relocations (
396- & self ,
397- cx : & impl HasDataLayout ,
398- range : AllocRange ,
399- ) -> & [ ( Size , ( Tag , AllocId ) ) ] {
390+ pub fn get_relocations ( & self , cx : & impl HasDataLayout , range : AllocRange ) -> & [ ( Size , Tag ) ] {
400391 // We have to go back `pointer_size - 1` bytes, as that one would still overlap with
401392 // the beginning of this range.
402393 let start = range. start . bytes ( ) . saturating_sub ( cx. data_layout ( ) . pointer_size . bytes ( ) - 1 ) ;
@@ -582,24 +573,24 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
582573 }
583574}
584575
585- /// Relocations.
576+ /// " Relocations" stores the provenance information of pointers stored in memory .
586577#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , TyEncodable , TyDecodable ) ]
587- pub struct Relocations < Tag = ( ) , Id = AllocId > ( SortedMap < Size , ( Tag , Id ) > ) ;
578+ pub struct Relocations < Tag = AllocId > ( SortedMap < Size , Tag > ) ;
588579
589- impl < Tag , Id > Relocations < Tag , Id > {
580+ impl < Tag > Relocations < Tag > {
590581 pub fn new ( ) -> Self {
591582 Relocations ( SortedMap :: new ( ) )
592583 }
593584
594585 // The caller must guarantee that the given relocations are already sorted
595586 // by address and contain no duplicates.
596- pub fn from_presorted ( r : Vec < ( Size , ( Tag , Id ) ) > ) -> Self {
587+ pub fn from_presorted ( r : Vec < ( Size , Tag ) > ) -> Self {
597588 Relocations ( SortedMap :: from_presorted_elements ( r) )
598589 }
599590}
600591
601592impl < Tag > Deref for Relocations < Tag > {
602- type Target = SortedMap < Size , ( Tag , AllocId ) > ;
593+ type Target = SortedMap < Size , Tag > ;
603594
604595 fn deref ( & self ) -> & Self :: Target {
605596 & self . 0
@@ -614,7 +605,7 @@ impl<Tag> DerefMut for Relocations<Tag> {
614605
615606/// A partial, owned list of relocations to transfer into another allocation.
616607pub struct AllocationRelocations < Tag > {
617- relative_relocations : Vec < ( Size , ( Tag , AllocId ) ) > ,
608+ relative_relocations : Vec < ( Size , Tag ) > ,
618609}
619610
620611impl < Tag : Copy , Extra > Allocation < Tag , Extra > {
0 commit comments