@@ -112,15 +112,15 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
112
112
/// A reference to some allocation that was already bounds-checked for the given region
113
113
/// and had the on-access machine hooks run.
114
114
#[ derive( Copy , Clone ) ]
115
- pub struct AllocRef < ' a , ' tcx , Prov , Extra > {
115
+ pub struct AllocRef < ' a , ' tcx , Prov : Provenance , Extra > {
116
116
alloc : & ' a Allocation < Prov , Extra > ,
117
117
range : AllocRange ,
118
118
tcx : TyCtxt < ' tcx > ,
119
119
alloc_id : AllocId ,
120
120
}
121
121
/// A reference to some allocation that was already bounds-checked for the given region
122
122
/// and had the on-access machine hooks run.
123
- pub struct AllocRefMut < ' a , ' tcx , Prov , Extra > {
123
+ pub struct AllocRefMut < ' a , ' tcx , Prov : Provenance , Extra > {
124
124
alloc : & ' a mut Allocation < Prov , Extra > ,
125
125
range : AllocRange ,
126
126
tcx : TyCtxt < ' tcx > ,
@@ -302,8 +302,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
302
302
. into ( ) ) ;
303
303
} ;
304
304
305
- debug ! ( ?alloc) ;
306
-
307
305
if alloc. mutability == Mutability :: Not {
308
306
throw_ub_format ! ( "deallocating immutable allocation {alloc_id:?}" ) ;
309
307
}
@@ -797,7 +795,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
797
795
// This is a new allocation, add the allocation it points to `todo`.
798
796
if let Some ( ( _, alloc) ) = self . memory . alloc_map . get ( id) {
799
797
todo. extend (
800
- alloc. provenance ( ) . values ( ) . filter_map ( |prov| prov. get_alloc_id ( ) ) ,
798
+ alloc. provenance ( ) . provenances ( ) . filter_map ( |prov| prov. get_alloc_id ( ) ) ,
801
799
) ;
802
800
}
803
801
}
@@ -833,7 +831,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
833
831
allocs_to_print : & mut VecDeque < AllocId > ,
834
832
alloc : & Allocation < Prov , Extra > ,
835
833
) -> std:: fmt:: Result {
836
- for alloc_id in alloc. provenance ( ) . values ( ) . filter_map ( |prov| prov. get_alloc_id ( ) ) {
834
+ for alloc_id in alloc. provenance ( ) . provenances ( ) . filter_map ( |prov| prov. get_alloc_id ( ) )
835
+ {
837
836
allocs_to_print. push_back ( alloc_id) ;
838
837
}
839
838
write ! ( fmt, "{}" , display_allocation( tcx, alloc) )
@@ -962,7 +961,7 @@ impl<'tcx, 'a, Prov: Provenance, Extra> AllocRef<'a, 'tcx, Prov, Extra> {
962
961
963
962
/// Returns whether the allocation has provenance anywhere in the range of the `AllocRef`.
964
963
pub ( crate ) fn has_provenance ( & self ) -> bool {
965
- self . alloc . range_has_provenance ( & self . tcx , self . range )
964
+ ! self . alloc . provenance ( ) . range_empty ( self . range , & self . tcx )
966
965
}
967
966
}
968
967
@@ -1060,7 +1059,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1060
1059
1061
1060
// Source alloc preparations and access hooks.
1062
1061
let Some ( ( src_alloc_id, src_offset, src_prov) ) = src_parts else {
1063
- // Zero-sized *source*, that means dst is also zero-sized and we have nothing to do.
1062
+ // Zero-sized *source*, that means dest is also zero-sized and we have nothing to do.
1064
1063
return Ok ( ( ) ) ;
1065
1064
} ;
1066
1065
let src_alloc = self . get_alloc_raw ( src_alloc_id) ?;
@@ -1079,22 +1078,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1079
1078
return Ok ( ( ) ) ;
1080
1079
} ;
1081
1080
1082
- // Checks provenance edges on the src, which needs to happen before
1083
- // `prepare_provenance_copy`.
1084
- if src_alloc. range_has_provenance ( & tcx, alloc_range ( src_range. start , Size :: ZERO ) ) {
1085
- throw_unsup ! ( PartialPointerCopy ( Pointer :: new( src_alloc_id, src_range. start) ) ) ;
1086
- }
1087
- if src_alloc. range_has_provenance ( & tcx, alloc_range ( src_range. end ( ) , Size :: ZERO ) ) {
1088
- throw_unsup ! ( PartialPointerCopy ( Pointer :: new( src_alloc_id, src_range. end( ) ) ) ) ;
1089
- }
1081
+ // Prepare getting source provenance.
1090
1082
let src_bytes = src_alloc. get_bytes_unchecked ( src_range) . as_ptr ( ) ; // raw ptr, so we can also get a ptr to the destination allocation
1091
1083
// first copy the provenance to a temporary buffer, because
1092
1084
// `get_bytes_mut` will clear the provenance, which is correct,
1093
1085
// since we don't want to keep any provenance at the target.
1094
- let provenance =
1095
- src_alloc. prepare_provenance_copy ( self , src_range, dest_offset, num_copies) ;
1086
+ // This will also error if copying partial provenance is not supported.
1087
+ let provenance = src_alloc
1088
+ . provenance ( )
1089
+ . prepare_copy ( src_range, dest_offset, num_copies, self )
1090
+ . map_err ( |e| e. to_interp_error ( dest_alloc_id) ) ?;
1096
1091
// Prepare a copy of the initialization mask.
1097
- let compressed = src_alloc. compress_uninit_range ( src_range) ;
1092
+ let init = src_alloc. init_mask ( ) . prepare_copy ( src_range) ;
1098
1093
1099
1094
// Destination alloc preparations and access hooks.
1100
1095
let ( dest_alloc, extra) = self . get_alloc_raw_mut ( dest_alloc_id) ?;
@@ -1111,7 +1106,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1111
1106
. map_err ( |e| e. to_interp_error ( dest_alloc_id) ) ?
1112
1107
. as_mut_ptr ( ) ;
1113
1108
1114
- if compressed . no_bytes_init ( ) {
1109
+ if init . no_bytes_init ( ) {
1115
1110
// Fast path: If all bytes are `uninit` then there is nothing to copy. The target range
1116
1111
// is marked as uninitialized but we otherwise omit changing the byte representation which may
1117
1112
// be arbitrary for uninitialized bytes.
@@ -1160,13 +1155,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1160
1155
}
1161
1156
1162
1157
// now fill in all the "init" data
1163
- dest_alloc. mark_compressed_init_range (
1164
- & compressed ,
1158
+ dest_alloc. init_mask_apply_copy (
1159
+ init ,
1165
1160
alloc_range ( dest_offset, size) , // just a single copy (i.e., not full `dest_range`)
1166
1161
num_copies,
1167
1162
) ;
1168
1163
// copy the provenance to the destination
1169
- dest_alloc. mark_provenance_range ( provenance) ;
1164
+ dest_alloc. provenance_apply_copy ( provenance) ;
1170
1165
1171
1166
Ok ( ( ) )
1172
1167
}
0 commit comments