@@ -2,7 +2,6 @@ use rustc_abi::{BackendRepr, Size};
2
2
use rustc_middle:: mir:: { Mutability , RetagKind } ;
3
3
use rustc_middle:: ty:: layout:: HasTypingEnv ;
4
4
use rustc_middle:: ty:: { self , Ty } ;
5
- use rustc_span:: def_id:: DefId ;
6
5
7
6
use crate :: borrow_tracker:: { GlobalState , GlobalStateInner , ProtectorKind } ;
8
7
use crate :: concurrency:: data_race:: NaReadType ;
@@ -115,9 +114,6 @@ impl<'tcx> Tree {
115
114
/// Policy for a new borrow.
116
115
#[ derive( Debug , Clone , Copy ) ]
117
116
struct 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 ,
121
117
/// Which permission should the pointer start with.
122
118
initial_state : Permission ,
123
119
/// Whether this pointer is part of the arguments of a function call.
@@ -157,7 +153,7 @@ impl<'tcx> NewPermission {
157
153
} ;
158
154
159
155
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 } )
161
157
}
162
158
163
159
/// Compute permission for `Box`-like type (`Box` always, and also `Unique` if enabled).
@@ -167,7 +163,6 @@ impl<'tcx> NewPermission {
167
163
ty : Ty < ' tcx > ,
168
164
kind : RetagKind ,
169
165
cx : & crate :: MiriInterpCx < ' tcx > ,
170
- zero_size : bool ,
171
166
) -> Option < Self > {
172
167
let pointee = ty. builtin_deref ( true ) . unwrap ( ) ;
173
168
pointee. is_unpin ( * cx. tcx , cx. typing_env ( ) ) . then_some ( ( ) ) . map ( |( ) | {
@@ -177,7 +172,6 @@ impl<'tcx> NewPermission {
177
172
let protected = kind == RetagKind :: FnEntry ;
178
173
let initial_state = Permission :: new_reserved ( ty_is_freeze, protected) ;
179
174
Self {
180
- zero_size,
181
175
initial_state,
182
176
protector : protected. then_some ( ProtectorKind :: WeakProtector ) ,
183
177
initial_read : true ,
@@ -341,15 +335,12 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
341
335
// Determine the size of the reborrow.
342
336
// For most types this is the entire size of the place, however
343
337
// - 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 ) ;
353
344
trace ! ( "Creating new permission: {:?} with size {:?}" , new_perm, reborrow_size) ;
354
345
355
346
// This new tag is not guaranteed to actually be used.
@@ -413,17 +404,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
413
404
let this = self . eval_context_mut ( ) ;
414
405
let options = this. machine . borrow_tracker . as_mut ( ) . unwrap ( ) . get_mut ( ) ;
415
406
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 } ;
419
408
return visitor. visit_value ( place) ;
420
409
421
410
// The actual visitor.
422
411
struct RetagVisitor < ' ecx , ' tcx > {
423
412
ecx : & ' ecx mut MiriInterpCx < ' tcx > ,
424
413
kind : RetagKind ,
425
414
retag_fields : RetagFields ,
426
- unique_did : Option < DefId > ,
427
415
}
428
416
impl < ' ecx , ' tcx > RetagVisitor < ' ecx , ' tcx > {
429
417
#[ inline( always) ] // yes this helps in our benchmarks
@@ -454,12 +442,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
454
442
fn visit_box ( & mut self , box_ty : Ty < ' tcx > , place : & PlaceTy < ' tcx > ) -> InterpResult < ' tcx > {
455
443
// Only boxes for the global allocator get any special treatment.
456
444
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 ) ;
463
447
self . retag_ptr_inplace ( place, new_perm) ?;
464
448
}
465
449
interp_ok ( ( ) )
@@ -493,16 +477,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
493
477
// even if field retagging is not enabled. *shrug*)
494
478
self . walk_value ( place) ?;
495
479
}
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
- }
506
480
_ => {
507
481
// Not a reference/pointer/box. Only recurse if configured appropriately.
508
482
let recurse = match self . retag_fields {
@@ -541,7 +515,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
541
515
// Retag it. With protection! That is the entire point.
542
516
let new_perm = NewPermission {
543
517
initial_state : Permission :: new_reserved ( ty_is_freeze, /* protected */ true ) ,
544
- zero_size : false ,
545
518
protector : Some ( ProtectorKind :: StrongProtector ) ,
546
519
initial_read : true ,
547
520
} ;
@@ -603,27 +576,3 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
603
576
tree_borrows. give_pointer_debug_name ( tag, nth_parent, name)
604
577
}
605
578
}
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