@@ -2,7 +2,6 @@ use rustc_abi::{BackendRepr, Size};
22use rustc_middle:: mir:: { Mutability , RetagKind } ;
33use rustc_middle:: ty:: layout:: HasTypingEnv ;
44use rustc_middle:: ty:: { self , Ty } ;
5- use rustc_span:: def_id:: DefId ;
65
76use crate :: borrow_tracker:: { GlobalState , GlobalStateInner , ProtectorKind } ;
87use crate :: concurrency:: data_race:: NaReadType ;
@@ -115,9 +114,6 @@ impl<'tcx> Tree {
115114/// Policy for a new borrow.
116115#[ derive( Debug , Clone , Copy ) ]
117116struct NewPermission {
118- /// Optionally ignore the actual size to do a zero-size reborrow.
119- /// If this is set then `dereferenceable` is not enforced.
120- zero_size : bool ,
121117 /// Which permission should the pointer start with.
122118 initial_state : Permission ,
123119 /// Whether this pointer is part of the arguments of a function call.
@@ -157,7 +153,7 @@ impl<'tcx> NewPermission {
157153 } ;
158154
159155 let protector = is_protected. then_some ( ProtectorKind :: StrongProtector ) ;
160- Some ( Self { zero_size : false , initial_state, protector, initial_read } )
156+ Some ( Self { initial_state, protector, initial_read } )
161157 }
162158
163159 /// Compute permission for `Box`-like type (`Box` always, and also `Unique` if enabled).
@@ -167,7 +163,6 @@ impl<'tcx> NewPermission {
167163 ty : Ty < ' tcx > ,
168164 kind : RetagKind ,
169165 cx : & crate :: MiriInterpCx < ' tcx > ,
170- zero_size : bool ,
171166 ) -> Option < Self > {
172167 let pointee = ty. builtin_deref ( true ) . unwrap ( ) ;
173168 pointee. is_unpin ( * cx. tcx , cx. typing_env ( ) ) . then_some ( ( ) ) . map ( |( ) | {
@@ -177,7 +172,6 @@ impl<'tcx> NewPermission {
177172 let protected = kind == RetagKind :: FnEntry ;
178173 let initial_state = Permission :: new_reserved ( ty_is_freeze, protected) ;
179174 Self {
180- zero_size,
181175 initial_state,
182176 protector : protected. then_some ( ProtectorKind :: WeakProtector ) ,
183177 initial_read : true ,
@@ -341,15 +335,12 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
341335 // Determine the size of the reborrow.
342336 // For most types this is the entire size of the place, however
343337 // - when `extern type` is involved we use the size of the known prefix,
344- // - if the pointer is not reborrowed (raw pointer) or if `zero_size` is set
345- // then we override the size to do a zero-length reborrow.
346- let reborrow_size = match new_perm {
347- NewPermission { zero_size : false , .. } =>
348- this. size_and_align_of_mplace ( place) ?
349- . map ( |( size, _) | size)
350- . unwrap_or ( place. layout . size ) ,
351- _ => Size :: from_bytes ( 0 ) ,
352- } ;
338+ // - if the pointer is not reborrowed (raw pointer) then we override the size
339+ // to do a zero-length reborrow.
340+ let reborrow_size = this
341+ . size_and_align_of_mplace ( place) ?
342+ . map ( |( size, _) | size)
343+ . unwrap_or ( place. layout . size ) ;
353344 trace ! ( "Creating new permission: {:?} with size {:?}" , new_perm, reborrow_size) ;
354345
355346 // This new tag is not guaranteed to actually be used.
@@ -413,17 +404,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
413404 let this = self . eval_context_mut ( ) ;
414405 let options = this. machine . borrow_tracker . as_mut ( ) . unwrap ( ) . get_mut ( ) ;
415406 let retag_fields = options. retag_fields ;
416- let unique_did =
417- options. unique_is_unique . then ( || this. tcx . lang_items ( ) . ptr_unique ( ) ) . flatten ( ) ;
418- let mut visitor = RetagVisitor { ecx : this, kind, retag_fields, unique_did } ;
407+ let mut visitor = RetagVisitor { ecx : this, kind, retag_fields } ;
419408 return visitor. visit_value ( place) ;
420409
421410 // The actual visitor.
422411 struct RetagVisitor < ' ecx , ' tcx > {
423412 ecx : & ' ecx mut MiriInterpCx < ' tcx > ,
424413 kind : RetagKind ,
425414 retag_fields : RetagFields ,
426- unique_did : Option < DefId > ,
427415 }
428416 impl < ' ecx , ' tcx > RetagVisitor < ' ecx , ' tcx > {
429417 #[ inline( always) ] // yes this helps in our benchmarks
@@ -454,12 +442,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
454442 fn visit_box ( & mut self , box_ty : Ty < ' tcx > , place : & PlaceTy < ' tcx > ) -> InterpResult < ' tcx > {
455443 // Only boxes for the global allocator get any special treatment.
456444 if box_ty. is_box_global ( * self . ecx . tcx ) {
457- let new_perm = NewPermission :: from_unique_ty (
458- place. layout . ty ,
459- self . kind ,
460- self . ecx ,
461- /* zero_size */ false ,
462- ) ;
445+ let new_perm =
446+ NewPermission :: from_unique_ty ( place. layout . ty , self . kind , self . ecx ) ;
463447 self . retag_ptr_inplace ( place, new_perm) ?;
464448 }
465449 interp_ok ( ( ) )
@@ -493,16 +477,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
493477 // even if field retagging is not enabled. *shrug*)
494478 self . walk_value ( place) ?;
495479 }
496- ty:: Adt ( adt, _) if self . unique_did == Some ( adt. did ( ) ) => {
497- let place = inner_ptr_of_unique ( self . ecx , place) ?;
498- let new_perm = NewPermission :: from_unique_ty (
499- place. layout . ty ,
500- self . kind ,
501- self . ecx ,
502- /* zero_size */ true ,
503- ) ;
504- self . retag_ptr_inplace ( & place, new_perm) ?;
505- }
506480 _ => {
507481 // Not a reference/pointer/box. Only recurse if configured appropriately.
508482 let recurse = match self . retag_fields {
@@ -541,7 +515,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
541515 // Retag it. With protection! That is the entire point.
542516 let new_perm = NewPermission {
543517 initial_state : Permission :: new_reserved ( ty_is_freeze, /* protected */ true ) ,
544- zero_size : false ,
545518 protector : Some ( ProtectorKind :: StrongProtector ) ,
546519 initial_read : true ,
547520 } ;
@@ -603,27 +576,3 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
603576 tree_borrows. give_pointer_debug_name ( tag, nth_parent, name)
604577 }
605578}
606-
607- /// Takes a place for a `Unique` and turns it into a place with the inner raw pointer.
608- /// I.e. input is what you get from the visitor upon encountering an `adt` that is `Unique`,
609- /// and output can be used by `retag_ptr_inplace`.
610- fn inner_ptr_of_unique < ' tcx > (
611- ecx : & MiriInterpCx < ' tcx > ,
612- place : & PlaceTy < ' tcx > ,
613- ) -> InterpResult < ' tcx , PlaceTy < ' tcx > > {
614- // Follows the same layout as `interpret/visitor.rs:walk_value` for `Box` in
615- // `rustc_const_eval`, just with one fewer layer.
616- // Here we have a `Unique(NonNull(*mut), PhantomData)`
617- assert_eq ! ( place. layout. fields. count( ) , 2 , "Unique must have exactly 2 fields" ) ;
618- let ( nonnull, phantom) = ( ecx. project_field ( place, 0 ) ?, ecx. project_field ( place, 1 ) ?) ;
619- assert ! (
620- phantom. layout. ty. ty_adt_def( ) . is_some_and( |adt| adt. is_phantom_data( ) ) ,
621- "2nd field of `Unique` should be `PhantomData` but is `{:?}`" ,
622- phantom. layout. ty,
623- ) ;
624- // Now down to `NonNull(*mut)`
625- assert_eq ! ( nonnull. layout. fields. count( ) , 1 , "NonNull must have exactly 1 field" ) ;
626- let ptr = ecx. project_field ( & nonnull, 0 ) ?;
627- // Finally a plain `*mut`
628- interp_ok ( ptr)
629- }
0 commit comments