Skip to content

Commit f8a8bbd

Browse files
authored
Merge pull request #4307 from JoJoDeveloping/remove-unique-is-unique
Remove -Zunique-is-unique
2 parents d313405 + 30ecac8 commit f8a8bbd

19 files changed

+12
-451
lines changed

src/tools/miri/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,6 @@ to Miri failing to detect cases of undefined behavior in a program.
457457
casts are not supported in this mode, but that may change in the future.
458458
* `-Zmiri-force-page-size=<num>` overrides the default page size for an architecture, in multiples of 1k.
459459
`4` is default for most targets. This value should always be a power of 2 and nonzero.
460-
* `-Zmiri-unique-is-unique` performs additional aliasing checks for `core::ptr::Unique` to ensure
461-
that it could theoretically be considered `noalias`. This flag is experimental and has
462-
an effect only when used with `-Zmiri-tree-borrows`.
463460

464461
[function ABI]: https://doc.rust-lang.org/reference/items/functions.html#extern-function-qualifier
465462

src/tools/miri/src/bin/miri.rs

-10
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,6 @@ fn main() {
554554
} else if arg == "-Zmiri-tree-borrows" {
555555
miri_config.borrow_tracker = Some(BorrowTrackerMethod::TreeBorrows);
556556
miri_config.provenance_mode = ProvenanceMode::Strict;
557-
} else if arg == "-Zmiri-unique-is-unique" {
558-
miri_config.unique_is_unique = true;
559557
} else if arg == "-Zmiri-disable-data-race-detector" {
560558
miri_config.data_race_detector = false;
561559
miri_config.weak_memory_emulation = false;
@@ -722,14 +720,6 @@ fn main() {
722720
rustc_args.push(arg);
723721
}
724722
}
725-
// `-Zmiri-unique-is-unique` should only be used with `-Zmiri-tree-borrows`.
726-
if miri_config.unique_is_unique
727-
&& !matches!(miri_config.borrow_tracker, Some(BorrowTrackerMethod::TreeBorrows))
728-
{
729-
show_error!(
730-
"-Zmiri-unique-is-unique only has an effect when -Zmiri-tree-borrows is also used"
731-
);
732-
}
733723
// Tree Borrows implies strict provenance, and is not compatible with native calls.
734724
if matches!(miri_config.borrow_tracker, Some(BorrowTrackerMethod::TreeBorrows)) {
735725
if miri_config.provenance_mode != ProvenanceMode::Strict {

src/tools/miri/src/borrow_tracker/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ pub struct GlobalStateInner {
102102
tracked_pointer_tags: FxHashSet<BorTag>,
103103
/// Whether to recurse into datatypes when searching for pointers to retag.
104104
retag_fields: RetagFields,
105-
/// Whether `core::ptr::Unique` gets special (`Box`-like) handling.
106-
unique_is_unique: bool,
107105
}
108106

109107
impl VisitProvenance for GlobalStateInner {
@@ -164,7 +162,6 @@ impl GlobalStateInner {
164162
borrow_tracker_method: BorrowTrackerMethod,
165163
tracked_pointer_tags: FxHashSet<BorTag>,
166164
retag_fields: RetagFields,
167-
unique_is_unique: bool,
168165
) -> Self {
169166
GlobalStateInner {
170167
borrow_tracker_method,
@@ -173,7 +170,6 @@ impl GlobalStateInner {
173170
protected_tags: FxHashMap::default(),
174171
tracked_pointer_tags,
175172
retag_fields,
176-
unique_is_unique,
177173
}
178174
}
179175

@@ -239,7 +235,6 @@ impl BorrowTrackerMethod {
239235
self,
240236
config.tracked_pointer_tags.clone(),
241237
config.retag_fields,
242-
config.unique_is_unique,
243238
))
244239
}
245240
}

src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs

+10-61
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustc_abi::{BackendRepr, Size};
22
use rustc_middle::mir::{Mutability, RetagKind};
33
use rustc_middle::ty::layout::HasTypingEnv;
44
use rustc_middle::ty::{self, Ty};
5-
use rustc_span::def_id::DefId;
65

76
use crate::borrow_tracker::{GlobalState, GlobalStateInner, ProtectorKind};
87
use crate::concurrency::data_race::NaReadType;
@@ -115,9 +114,6 @@ impl<'tcx> Tree {
115114
/// Policy for a new borrow.
116115
#[derive(Debug, Clone, Copy)]
117116
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,
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-
}

src/tools/miri/src/eval.rs

-5
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ pub struct MiriConfig {
101101
pub validation: ValidationMode,
102102
/// Determines if Stacked Borrows or Tree Borrows is enabled.
103103
pub borrow_tracker: Option<BorrowTrackerMethod>,
104-
/// Whether `core::ptr::Unique` receives special treatment.
105-
/// If `true` then `Unique` is reborrowed with its own new tag and permission,
106-
/// otherwise `Unique` is just another raw pointer.
107-
pub unique_is_unique: bool,
108104
/// Controls alignment checking.
109105
pub check_alignment: AlignmentCheck,
110106
/// Action for an op requiring communication with the host.
@@ -177,7 +173,6 @@ impl Default for MiriConfig {
177173
env: vec![],
178174
validation: ValidationMode::Shallow,
179175
borrow_tracker: Some(BorrowTrackerMethod::StackedBorrows),
180-
unique_is_unique: false,
181176
check_alignment: AlignmentCheck::Int,
182177
isolated_op: IsolatedOp::Reject(RejectOpWith::Abort),
183178
ignore_leaks: false,

src/tools/miri/tests/fail/tree_borrows/children-can-alias.default.stderr

-15
This file was deleted.

src/tools/miri/tests/fail/tree_borrows/children-can-alias.rs

-58
This file was deleted.

src/tools/miri/tests/fail/tree_borrows/children-can-alias.uniq.stderr

-31
This file was deleted.

src/tools/miri/tests/fail/tree_borrows/unique.rs

-27
This file was deleted.

0 commit comments

Comments
 (0)