@@ -25,7 +25,7 @@ use crate::ty;
25
25
/// module provides higher-level access.
26
26
#[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord , Hash , TyEncodable , TyDecodable ) ]
27
27
#[ derive( HashStable ) ]
28
- pub struct Allocation < Tag = ( ) , Extra = ( ) > {
28
+ pub struct Allocation < Tag = AllocId , Extra = ( ) > {
29
29
/// The actual bytes of the allocation.
30
30
/// Note that the bytes of a pointer represent the offset of the pointer.
31
31
bytes : Vec < u8 > ,
@@ -154,25 +154,17 @@ impl<Tag> Allocation<Tag> {
154
154
}
155
155
}
156
156
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 > (
160
160
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 > {
164
164
Allocation {
165
165
bytes : self . bytes ,
166
166
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 ( ) ,
176
168
) ,
177
169
init_mask : self . init_mask ,
178
170
align : self . align ,
@@ -339,8 +331,8 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
339
331
self . check_relocations ( cx, range) ?;
340
332
} else {
341
333
// 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) ) ;
344
336
return Ok ( ScalarMaybeUninit :: Scalar ( ptr. into ( ) ) ) ;
345
337
}
346
338
}
@@ -371,18 +363,21 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
371
363
}
372
364
} ;
373
365
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 ) ,
377
372
} ;
378
373
379
374
let endian = cx. data_layout ( ) . endian ;
380
375
let dst = self . get_bytes_mut ( cx, range) ;
381
376
write_target_uint ( endian, dst, bytes) . unwrap ( ) ;
382
377
383
378
// 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 ) ;
386
381
}
387
382
388
383
Ok ( ( ) )
@@ -392,11 +387,7 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
392
387
/// Relocations.
393
388
impl < Tag : Copy , Extra > Allocation < Tag , Extra > {
394
389
/// 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 ) ] {
400
391
// We have to go back `pointer_size - 1` bytes, as that one would still overlap with
401
392
// the beginning of this range.
402
393
let start = range. start . bytes ( ) . saturating_sub ( cx. data_layout ( ) . pointer_size . bytes ( ) - 1 ) ;
@@ -582,24 +573,24 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
582
573
}
583
574
}
584
575
585
- /// Relocations.
576
+ /// " Relocations" stores the provenance information of pointers stored in memory .
586
577
#[ 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 > ) ;
588
579
589
- impl < Tag , Id > Relocations < Tag , Id > {
580
+ impl < Tag > Relocations < Tag > {
590
581
pub fn new ( ) -> Self {
591
582
Relocations ( SortedMap :: new ( ) )
592
583
}
593
584
594
585
// The caller must guarantee that the given relocations are already sorted
595
586
// 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 {
597
588
Relocations ( SortedMap :: from_presorted_elements ( r) )
598
589
}
599
590
}
600
591
601
592
impl < Tag > Deref for Relocations < Tag > {
602
- type Target = SortedMap < Size , ( Tag , AllocId ) > ;
593
+ type Target = SortedMap < Size , Tag > ;
603
594
604
595
fn deref ( & self ) -> & Self :: Target {
605
596
& self . 0
@@ -614,7 +605,7 @@ impl<Tag> DerefMut for Relocations<Tag> {
614
605
615
606
/// A partial, owned list of relocations to transfer into another allocation.
616
607
pub struct AllocationRelocations < Tag > {
617
- relative_relocations : Vec < ( Size , ( Tag , AllocId ) ) > ,
608
+ relative_relocations : Vec < ( Size , Tag ) > ,
618
609
}
619
610
620
611
impl < Tag : Copy , Extra > Allocation < Tag , Extra > {
0 commit comments