Skip to content

Commit 2c1a5a7

Browse files
committed
Auto merge of #3636 - RalfJung:provenance-type-aliases, r=RalfJung
avoid repeating the Provenance parameter everywhere
2 parents 79c30b6 + 98a3ac9 commit 2c1a5a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+687
-854
lines changed

src/tools/miri/src/alloc_addresses/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
257257
Ok(())
258258
}
259259

260-
fn ptr_from_addr_cast(&self, addr: u64) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
260+
fn ptr_from_addr_cast(&self, addr: u64) -> InterpResult<'tcx, Pointer> {
261261
trace!("Casting {:#x} to a pointer", addr);
262262

263263
let ecx = self.eval_context_ref();
@@ -297,10 +297,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
297297
/// Convert a relative (tcx) pointer to a Miri pointer.
298298
fn adjust_alloc_root_pointer(
299299
&self,
300-
ptr: Pointer<CtfeProvenance>,
300+
ptr: interpret::Pointer<CtfeProvenance>,
301301
tag: BorTag,
302302
kind: MemoryKind,
303-
) -> InterpResult<'tcx, Pointer<Provenance>> {
303+
) -> InterpResult<'tcx, interpret::Pointer<Provenance>> {
304304
let ecx = self.eval_context_ref();
305305

306306
let (prov, offset) = ptr.into_parts(); // offset is relative (AllocId provenance)
@@ -310,12 +310,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
310310
// Add offset with the right kind of pointer-overflowing arithmetic.
311311
let dl = ecx.data_layout();
312312
let absolute_addr = dl.overflowing_offset(base_addr, offset.bytes()).0;
313-
Ok(Pointer::new(Provenance::Concrete { alloc_id, tag }, Size::from_bytes(absolute_addr)))
313+
Ok(interpret::Pointer::new(
314+
Provenance::Concrete { alloc_id, tag },
315+
Size::from_bytes(absolute_addr),
316+
))
314317
}
315318

316319
/// When a pointer is used for a memory access, this computes where in which allocation the
317320
/// access is going.
318-
fn ptr_get_alloc(&self, ptr: Pointer<Provenance>) -> Option<(AllocId, Size)> {
321+
fn ptr_get_alloc(&self, ptr: interpret::Pointer<Provenance>) -> Option<(AllocId, Size)> {
319322
let ecx = self.eval_context_ref();
320323

321324
let (tag, addr) = ptr.into_parts(); // addr is absolute (Tag provenance)

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
281281
fn retag_ptr_value(
282282
&mut self,
283283
kind: RetagKind,
284-
val: &ImmTy<'tcx, Provenance>,
285-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
284+
val: &ImmTy<'tcx>,
285+
) -> InterpResult<'tcx, ImmTy<'tcx>> {
286286
let this = self.eval_context_mut();
287287
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
288288
match method {
@@ -294,7 +294,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
294294
fn retag_place_contents(
295295
&mut self,
296296
kind: RetagKind,
297-
place: &PlaceTy<'tcx, Provenance>,
297+
place: &PlaceTy<'tcx>,
298298
) -> InterpResult<'tcx> {
299299
let this = self.eval_context_mut();
300300
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
@@ -304,10 +304,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
304304
}
305305
}
306306

307-
fn protect_place(
308-
&mut self,
309-
place: &MPlaceTy<'tcx, Provenance>,
310-
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
307+
fn protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
311308
let this = self.eval_context_mut();
312309
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
313310
match method {
@@ -327,7 +324,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
327324

328325
fn give_pointer_debug_name(
329326
&mut self,
330-
ptr: Pointer<Option<Provenance>>,
327+
ptr: Pointer,
331328
nth_parent: u8,
332329
name: &str,
333330
) -> InterpResult<'tcx> {

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl Stacks {
531531
trace!(
532532
"read access with tag {:?}: {:?}, size {}",
533533
tag,
534-
Pointer::new(alloc_id, range.start),
534+
interpret::Pointer::new(alloc_id, range.start),
535535
range.size.bytes()
536536
);
537537
let dcx = DiagnosticCxBuilder::read(machine, tag, range);
@@ -552,7 +552,7 @@ impl Stacks {
552552
trace!(
553553
"write access with tag {:?}: {:?}, size {}",
554554
tag,
555-
Pointer::new(alloc_id, range.start),
555+
interpret::Pointer::new(alloc_id, range.start),
556556
range.size.bytes()
557557
);
558558
let dcx = DiagnosticCxBuilder::write(machine, tag, range);
@@ -587,7 +587,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
587587
/// Returns the provenance that should be used henceforth.
588588
fn sb_reborrow(
589589
&mut self,
590-
place: &MPlaceTy<'tcx, Provenance>,
590+
place: &MPlaceTy<'tcx>,
591591
size: Size,
592592
new_perm: NewPermission,
593593
new_tag: BorTag,
@@ -692,7 +692,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
692692
new_tag,
693693
orig_tag,
694694
place.layout.ty,
695-
Pointer::new(alloc_id, base_offset),
695+
interpret::Pointer::new(alloc_id, base_offset),
696696
size.bytes()
697697
);
698698

@@ -809,10 +809,10 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
809809

810810
fn sb_retag_place(
811811
&mut self,
812-
place: &MPlaceTy<'tcx, Provenance>,
812+
place: &MPlaceTy<'tcx>,
813813
new_perm: NewPermission,
814814
info: RetagInfo, // diagnostics info about this retag
815-
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
815+
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
816816
let this = self.eval_context_mut();
817817
let size = this.size_and_align_of_mplace(place)?.map(|(size, _)| size);
818818
// FIXME: If we cannot determine the size (because the unsized tail is an `extern type`),
@@ -839,10 +839,10 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
839839
/// `kind` indicates what kind of reference is being created.
840840
fn sb_retag_reference(
841841
&mut self,
842-
val: &ImmTy<'tcx, Provenance>,
842+
val: &ImmTy<'tcx>,
843843
new_perm: NewPermission,
844844
info: RetagInfo, // diagnostics info about this retag
845-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
845+
) -> InterpResult<'tcx, ImmTy<'tcx>> {
846846
let this = self.eval_context_mut();
847847
let place = this.ref_to_mplace(val)?;
848848
let new_place = this.sb_retag_place(&place, new_perm, info)?;
@@ -855,8 +855,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
855855
fn sb_retag_ptr_value(
856856
&mut self,
857857
kind: RetagKind,
858-
val: &ImmTy<'tcx, Provenance>,
859-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
858+
val: &ImmTy<'tcx>,
859+
) -> InterpResult<'tcx, ImmTy<'tcx>> {
860860
let this = self.eval_context_mut();
861861
let new_perm = NewPermission::from_ref_ty(val.layout.ty, kind, this);
862862
let cause = match kind {
@@ -870,7 +870,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
870870
fn sb_retag_place_contents(
871871
&mut self,
872872
kind: RetagKind,
873-
place: &PlaceTy<'tcx, Provenance>,
873+
place: &PlaceTy<'tcx>,
874874
) -> InterpResult<'tcx> {
875875
let this = self.eval_context_mut();
876876
let retag_fields = this.machine.borrow_tracker.as_mut().unwrap().get_mut().retag_fields;
@@ -895,7 +895,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
895895
#[inline(always)] // yes this helps in our benchmarks
896896
fn retag_ptr_inplace(
897897
&mut self,
898-
place: &PlaceTy<'tcx, Provenance>,
898+
place: &PlaceTy<'tcx>,
899899
new_perm: NewPermission,
900900
) -> InterpResult<'tcx> {
901901
let val = self.ecx.read_immediate(&self.ecx.place_to_op(place)?)?;
@@ -909,18 +909,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
909909
}
910910
}
911911
impl<'ecx, 'tcx> ValueVisitor<'tcx, MiriMachine<'tcx>> for RetagVisitor<'ecx, 'tcx> {
912-
type V = PlaceTy<'tcx, Provenance>;
912+
type V = PlaceTy<'tcx>;
913913

914914
#[inline(always)]
915915
fn ecx(&self) -> &MiriInterpCx<'tcx> {
916916
self.ecx
917917
}
918918

919-
fn visit_box(
920-
&mut self,
921-
box_ty: Ty<'tcx>,
922-
place: &PlaceTy<'tcx, Provenance>,
923-
) -> InterpResult<'tcx> {
919+
fn visit_box(&mut self, box_ty: Ty<'tcx>, place: &PlaceTy<'tcx>) -> InterpResult<'tcx> {
924920
// Only boxes for the global allocator get any special treatment.
925921
if box_ty.is_box_global(*self.ecx.tcx) {
926922
// Boxes get a weak protectors, since they may be deallocated.
@@ -930,7 +926,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
930926
Ok(())
931927
}
932928

933-
fn visit_value(&mut self, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
929+
fn visit_value(&mut self, place: &PlaceTy<'tcx>) -> InterpResult<'tcx> {
934930
// If this place is smaller than a pointer, we know that it can't contain any
935931
// pointers we need to retag, so we can stop recursion early.
936932
// This optimization is crucial for ZSTs, because they can contain way more fields
@@ -984,10 +980,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
984980
/// call.
985981
///
986982
/// This is used to ensure soundness of in-place function argument/return passing.
987-
fn sb_protect_place(
988-
&mut self,
989-
place: &MPlaceTy<'tcx, Provenance>,
990-
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
983+
fn sb_protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
991984
let this = self.eval_context_mut();
992985

993986
// Retag it. With protection! That is the entire point.

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'tcx> Tree {
5656
"{} with tag {:?}: {:?}, size {}",
5757
access_kind,
5858
prov,
59-
Pointer::new(alloc_id, range.start),
59+
interpret::Pointer::new(alloc_id, range.start),
6060
range.size.bytes(),
6161
);
6262
// TODO: for now we bail out on wildcard pointers. Eventually we should
@@ -195,7 +195,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
195195
/// Returns the provenance that should be used henceforth.
196196
fn tb_reborrow(
197197
&mut self,
198-
place: &MPlaceTy<'tcx, Provenance>, // parent tag extracted from here
198+
place: &MPlaceTy<'tcx>, // parent tag extracted from here
199199
ptr_size: Size,
200200
new_perm: NewPermission,
201201
new_tag: BorTag,
@@ -258,7 +258,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
258258
new_tag,
259259
orig_tag,
260260
place.layout.ty,
261-
Pointer::new(alloc_id, base_offset),
261+
interpret::Pointer::new(alloc_id, base_offset),
262262
ptr_size.bytes()
263263
);
264264

@@ -327,9 +327,9 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
327327

328328
fn tb_retag_place(
329329
&mut self,
330-
place: &MPlaceTy<'tcx, Provenance>,
330+
place: &MPlaceTy<'tcx>,
331331
new_perm: NewPermission,
332-
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
332+
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
333333
let this = self.eval_context_mut();
334334

335335
// Determine the size of the reborrow.
@@ -366,9 +366,9 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
366366
/// Retags an individual pointer, returning the retagged version.
367367
fn tb_retag_reference(
368368
&mut self,
369-
val: &ImmTy<'tcx, Provenance>,
369+
val: &ImmTy<'tcx>,
370370
new_perm: NewPermission,
371-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
371+
) -> InterpResult<'tcx, ImmTy<'tcx>> {
372372
let this = self.eval_context_mut();
373373
let place = this.ref_to_mplace(val)?;
374374
let new_place = this.tb_retag_place(&place, new_perm)?;
@@ -383,8 +383,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
383383
fn tb_retag_ptr_value(
384384
&mut self,
385385
kind: RetagKind,
386-
val: &ImmTy<'tcx, Provenance>,
387-
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
386+
val: &ImmTy<'tcx>,
387+
) -> InterpResult<'tcx, ImmTy<'tcx>> {
388388
let this = self.eval_context_mut();
389389
let new_perm = match val.layout.ty.kind() {
390390
&ty::Ref(_, pointee, mutability) =>
@@ -402,7 +402,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
402402
fn tb_retag_place_contents(
403403
&mut self,
404404
kind: RetagKind,
405-
place: &PlaceTy<'tcx, Provenance>,
405+
place: &PlaceTy<'tcx>,
406406
) -> InterpResult<'tcx> {
407407
let this = self.eval_context_mut();
408408
let options = this.machine.borrow_tracker.as_mut().unwrap().get_mut();
@@ -423,7 +423,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
423423
#[inline(always)] // yes this helps in our benchmarks
424424
fn retag_ptr_inplace(
425425
&mut self,
426-
place: &PlaceTy<'tcx, Provenance>,
426+
place: &PlaceTy<'tcx>,
427427
new_perm: Option<NewPermission>,
428428
) -> InterpResult<'tcx> {
429429
if let Some(new_perm) = new_perm {
@@ -435,7 +435,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
435435
}
436436
}
437437
impl<'ecx, 'tcx> ValueVisitor<'tcx, MiriMachine<'tcx>> for RetagVisitor<'ecx, 'tcx> {
438-
type V = PlaceTy<'tcx, Provenance>;
438+
type V = PlaceTy<'tcx>;
439439

440440
#[inline(always)]
441441
fn ecx(&self) -> &MiriInterpCx<'tcx> {
@@ -445,11 +445,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
445445
/// Regardless of how `Unique` is handled, Boxes are always reborrowed.
446446
/// When `Unique` is also reborrowed, then it behaves exactly like `Box`
447447
/// except for the fact that `Box` has a non-zero-sized reborrow.
448-
fn visit_box(
449-
&mut self,
450-
box_ty: Ty<'tcx>,
451-
place: &PlaceTy<'tcx, Provenance>,
452-
) -> InterpResult<'tcx> {
448+
fn visit_box(&mut self, box_ty: Ty<'tcx>, place: &PlaceTy<'tcx>) -> InterpResult<'tcx> {
453449
// Only boxes for the global allocator get any special treatment.
454450
if box_ty.is_box_global(*self.ecx.tcx) {
455451
let new_perm = NewPermission::from_unique_ty(
@@ -463,7 +459,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
463459
Ok(())
464460
}
465461

466-
fn visit_value(&mut self, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
462+
fn visit_value(&mut self, place: &PlaceTy<'tcx>) -> InterpResult<'tcx> {
467463
// If this place is smaller than a pointer, we know that it can't contain any
468464
// pointers we need to retag, so we can stop recursion early.
469465
// This optimization is crucial for ZSTs, because they can contain way more fields
@@ -526,10 +522,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
526522
/// call.
527523
///
528524
/// This is used to ensure soundness of in-place function argument/return passing.
529-
fn tb_protect_place(
530-
&mut self,
531-
place: &MPlaceTy<'tcx, Provenance>,
532-
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
525+
fn tb_protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
533526
let this = self.eval_context_mut();
534527

535528
// Retag it. With protection! That is the entire point.
@@ -581,7 +574,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
581574
/// of `ptr` (with 0 representing `ptr` itself)
582575
fn tb_give_pointer_debug_name(
583576
&mut self,
584-
ptr: Pointer<Option<Provenance>>,
577+
ptr: Pointer,
585578
nth_parent: u8,
586579
name: &str,
587580
) -> InterpResult<'tcx> {
@@ -604,8 +597,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
604597
/// and output can be used by `retag_ptr_inplace`.
605598
fn inner_ptr_of_unique<'tcx>(
606599
ecx: &MiriInterpCx<'tcx>,
607-
place: &PlaceTy<'tcx, Provenance>,
608-
) -> InterpResult<'tcx, PlaceTy<'tcx, Provenance>> {
600+
place: &PlaceTy<'tcx>,
601+
) -> InterpResult<'tcx, PlaceTy<'tcx>> {
609602
// Follows the same layout as `interpret/visitor.rs:walk_value` for `Box` in
610603
// `rustc_const_eval`, just with one fewer layer.
611604
// Here we have a `Unique(NonNull(*mut), PhantomData)`

0 commit comments

Comments
 (0)