Skip to content

Commit 98a3ac9

Browse files
committed
also add type aliases for the pointer types
1 parent fcb4cf5 commit 98a3ac9

File tree

19 files changed

+105
-148
lines changed

19 files changed

+105
-148
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
324324

325325
fn give_pointer_debug_name(
326326
&mut self,
327-
ptr: Pointer<Option<Provenance>>,
327+
ptr: Pointer,
328328
nth_parent: u8,
329329
name: &str,
330330
) -> InterpResult<'tcx> {

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

Lines changed: 3 additions & 3 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);
@@ -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

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

Lines changed: 3 additions & 3 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
@@ -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

@@ -574,7 +574,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
574574
/// of `ptr` (with 0 representing `ptr` itself)
575575
fn tb_give_pointer_debug_name(
576576
&mut self,
577-
ptr: Pointer<Option<Provenance>>,
577+
ptr: Pointer,
578578
nth_parent: u8,
579579
name: &str,
580580
) -> InterpResult<'tcx> {

src/tools/miri/src/concurrency/data_race.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ impl VClockAlloc {
948948
mem_clocks: &MemoryCellClocks,
949949
access: AccessType,
950950
access_size: Size,
951-
ptr_dbg: Pointer<AllocId>,
951+
ptr_dbg: interpret::Pointer<AllocId>,
952952
ty: Option<Ty<'_>>,
953953
) -> InterpResult<'tcx> {
954954
let (active_index, active_clocks) = global.active_thread_state(thread_mgr);
@@ -1063,7 +1063,7 @@ impl VClockAlloc {
10631063
mem_clocks,
10641064
AccessType::NaRead(read_type),
10651065
access_range.size,
1066-
Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)),
1066+
interpret::Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)),
10671067
ty,
10681068
);
10691069
}
@@ -1108,7 +1108,7 @@ impl VClockAlloc {
11081108
mem_clocks,
11091109
AccessType::NaWrite(write_type),
11101110
access_range.size,
1111-
Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)),
1111+
interpret::Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)),
11121112
ty,
11131113
);
11141114
}
@@ -1337,7 +1337,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
13371337
mem_clocks,
13381338
access,
13391339
place.layout.size,
1340-
Pointer::new(
1340+
interpret::Pointer::new(
13411341
alloc_id,
13421342
Size::from_bytes(mem_clocks_range.start),
13431343
),

src/tools/miri/src/concurrency/thread.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,8 @@ pub struct ThreadManager<'tcx> {
432432
///
433433
/// Note that this vector also contains terminated threads.
434434
threads: IndexVec<ThreadId, Thread<'tcx>>,
435-
/// A mapping from a thread-local static to an allocation id of a thread
436-
/// specific allocation.
437-
thread_local_alloc_ids: FxHashMap<(DefId, ThreadId), Pointer<Provenance>>,
435+
/// A mapping from a thread-local static to the thread specific allocation.
436+
thread_local_allocs: FxHashMap<(DefId, ThreadId), StrictPointer>,
438437
/// A flag that indicates that we should change the active thread.
439438
yield_active_thread: bool,
440439
}
@@ -443,15 +442,15 @@ impl VisitProvenance for ThreadManager<'_> {
443442
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
444443
let ThreadManager {
445444
threads,
446-
thread_local_alloc_ids,
445+
thread_local_allocs,
447446
active_thread: _,
448447
yield_active_thread: _,
449448
} = self;
450449

451450
for thread in threads {
452451
thread.visit_provenance(visit);
453452
}
454-
for ptr in thread_local_alloc_ids.values() {
453+
for ptr in thread_local_allocs.values() {
455454
ptr.visit_provenance(visit);
456455
}
457456
}
@@ -465,7 +464,7 @@ impl<'tcx> Default for ThreadManager<'tcx> {
465464
Self {
466465
active_thread: ThreadId::MAIN_THREAD,
467466
threads,
468-
thread_local_alloc_ids: Default::default(),
467+
thread_local_allocs: Default::default(),
469468
yield_active_thread: false,
470469
}
471470
}
@@ -487,16 +486,16 @@ impl<'tcx> ThreadManager<'tcx> {
487486

488487
/// Check if we have an allocation for the given thread local static for the
489488
/// active thread.
490-
fn get_thread_local_alloc_id(&self, def_id: DefId) -> Option<Pointer<Provenance>> {
491-
self.thread_local_alloc_ids.get(&(def_id, self.active_thread)).cloned()
489+
fn get_thread_local_alloc_id(&self, def_id: DefId) -> Option<StrictPointer> {
490+
self.thread_local_allocs.get(&(def_id, self.active_thread)).cloned()
492491
}
493492

494493
/// Set the pointer for the allocation of the given thread local
495494
/// static for the active thread.
496495
///
497496
/// Panics if a thread local is initialized twice for the same thread.
498-
fn set_thread_local_alloc(&mut self, def_id: DefId, ptr: Pointer<Provenance>) {
499-
self.thread_local_alloc_ids.try_insert((def_id, self.active_thread), ptr).unwrap();
497+
fn set_thread_local_alloc(&mut self, def_id: DefId, ptr: StrictPointer) {
498+
self.thread_local_allocs.try_insert((def_id, self.active_thread), ptr).unwrap();
500499
}
501500

502501
/// Borrow the stack of the active thread.
@@ -848,7 +847,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
848847
fn get_or_create_thread_local_alloc(
849848
&mut self,
850849
def_id: DefId,
851-
) -> InterpResult<'tcx, Pointer<Provenance>> {
850+
) -> InterpResult<'tcx, StrictPointer> {
852851
let this = self.eval_context_mut();
853852
let tcx = this.tcx;
854853
if let Some(old_alloc) = this.machine.threads.get_thread_local_alloc_id(def_id) {
@@ -878,7 +877,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
878877
fn start_regular_thread(
879878
&mut self,
880879
thread: Option<MPlaceTy<'tcx>>,
881-
start_routine: Pointer<Option<Provenance>>,
880+
start_routine: Pointer,
882881
start_abi: Abi,
883882
func_arg: ImmTy<'tcx>,
884883
ret_layout: TyAndLayout<'tcx>,
@@ -947,18 +946,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
947946
let gone_thread = this.active_thread();
948947
{
949948
let mut free_tls_statics = Vec::new();
950-
this.machine.threads.thread_local_alloc_ids.retain(
951-
|&(_def_id, thread), &mut alloc_id| {
952-
if thread != gone_thread {
953-
// A different thread, keep this static around.
954-
return true;
955-
}
956-
// Delete this static from the map and from memory.
957-
// We cannot free directly here as we cannot use `?` in this context.
958-
free_tls_statics.push(alloc_id);
959-
false
960-
},
961-
);
949+
this.machine.threads.thread_local_allocs.retain(|&(_def_id, thread), &mut alloc_id| {
950+
if thread != gone_thread {
951+
// A different thread, keep this static around.
952+
return true;
953+
}
954+
// Delete this static from the map and from memory.
955+
// We cannot free directly here as we cannot use `?` in this context.
956+
free_tls_statics.push(alloc_id);
957+
false
958+
});
962959
// Now free the TLS statics.
963960
for ptr in free_tls_statics {
964961
match tls_alloc_action {

src/tools/miri/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum TerminationInfo {
4242
},
4343
DataRace {
4444
involves_non_atomic: bool,
45-
ptr: Pointer<AllocId>,
45+
ptr: interpret::Pointer<AllocId>,
4646
op1: RacingOp,
4747
op2: RacingOp,
4848
extra: Option<&'static str>,
@@ -128,7 +128,7 @@ pub enum NonHaltingDiagnostic {
128128
details: bool,
129129
},
130130
WeakMemoryOutdatedLoad {
131-
ptr: Pointer<Option<Provenance>>,
131+
ptr: Pointer,
132132
},
133133
}
134134

src/tools/miri/src/helpers.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
413413
}
414414

415415
/// Test if this pointer equals 0.
416-
fn ptr_is_null(&self, ptr: Pointer<Option<Provenance>>) -> InterpResult<'tcx, bool> {
416+
fn ptr_is_null(&self, ptr: Pointer) -> InterpResult<'tcx, bool> {
417417
Ok(ptr.addr().bytes() == 0)
418418
}
419419

420420
/// Generate some random bytes, and write them to `dest`.
421-
fn gen_random(&mut self, ptr: Pointer<Option<Provenance>>, len: u64) -> InterpResult<'tcx> {
421+
fn gen_random(&mut self, ptr: Pointer, len: u64) -> InterpResult<'tcx> {
422422
// Some programs pass in a null pointer and a length of 0
423423
// to their platform's random-generation function (e.g. getrandom())
424424
// on Linux. For compatibility with these programs, we don't perform
@@ -520,8 +520,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
520520
let mut cur_addr = start_addr;
521521
// Called when we detected an `UnsafeCell` at the given offset and size.
522522
// Calls `action` and advances `cur_ptr`.
523-
let mut unsafe_cell_action = |unsafe_cell_ptr: &Pointer<Option<Provenance>>,
524-
unsafe_cell_size: Size| {
523+
let mut unsafe_cell_action = |unsafe_cell_ptr: &Pointer, unsafe_cell_size: Size| {
525524
// We assume that we are given the fields in increasing offset order,
526525
// and nothing else changes.
527526
let unsafe_cell_addr = unsafe_cell_ptr.addr();
@@ -924,7 +923,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
924923
}
925924

926925
/// Read a sequence of bytes until the first null terminator.
927-
fn read_c_str<'a>(&'a self, ptr: Pointer<Option<Provenance>>) -> InterpResult<'tcx, &'a [u8]>
926+
fn read_c_str<'a>(&'a self, ptr: Pointer) -> InterpResult<'tcx, &'a [u8]>
928927
where
929928
'tcx: 'a,
930929
{
@@ -957,7 +956,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
957956
fn write_c_str(
958957
&mut self,
959958
c_str: &[u8],
960-
ptr: Pointer<Option<Provenance>>,
959+
ptr: Pointer,
961960
size: u64,
962961
) -> InterpResult<'tcx, (bool, u64)> {
963962
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
@@ -976,7 +975,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
976975
/// until the first null terminator.
977976
fn read_c_str_with_char_size<T>(
978977
&self,
979-
mut ptr: Pointer<Option<Provenance>>,
978+
mut ptr: Pointer,
980979
size: Size,
981980
align: Align,
982981
) -> InterpResult<'tcx, Vec<T>>
@@ -1008,7 +1007,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10081007
}
10091008

10101009
/// Read a sequence of u16 until the first null terminator.
1011-
fn read_wide_str(&self, ptr: Pointer<Option<Provenance>>) -> InterpResult<'tcx, Vec<u16>> {
1010+
fn read_wide_str(&self, ptr: Pointer) -> InterpResult<'tcx, Vec<u16>> {
10121011
self.read_c_str_with_char_size(ptr, Size::from_bytes(2), Align::from_bytes(2).unwrap())
10131012
}
10141013

@@ -1021,7 +1020,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10211020
fn write_wide_str(
10221021
&mut self,
10231022
wide_str: &[u16],
1024-
ptr: Pointer<Option<Provenance>>,
1023+
ptr: Pointer,
10251024
size: u64,
10261025
) -> InterpResult<'tcx, (bool, u64)> {
10271026
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required
@@ -1046,7 +1045,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10461045

10471046
/// Read a sequence of wchar_t until the first null terminator.
10481047
/// Always returns a `Vec<u32>` no matter the size of `wchar_t`.
1049-
fn read_wchar_t_str(&self, ptr: Pointer<Option<Provenance>>) -> InterpResult<'tcx, Vec<u32>> {
1048+
fn read_wchar_t_str(&self, ptr: Pointer) -> InterpResult<'tcx, Vec<u32>> {
10501049
let this = self.eval_context_ref();
10511050
let wchar_t = this.libc_ty_layout("wchar_t");
10521051
self.read_c_str_with_char_size(ptr, wchar_t.size, wchar_t.align.abi)

src/tools/miri/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub use rustc_const_eval::interpret::*;
100100
pub use rustc_const_eval::interpret::{self, AllocMap, Provenance as _};
101101

102102
// Type aliases that set the provenance parameter.
103+
pub type Pointer = interpret::Pointer<Option<machine::Provenance>>;
104+
pub type StrictPointer = interpret::Pointer<machine::Provenance>;
103105
pub type Scalar = interpret::Scalar<machine::Provenance>;
104106
pub type ImmTy<'tcx> = interpret::ImmTy<'tcx, machine::Provenance>;
105107
pub type OpTy<'tcx> = interpret::OpTy<'tcx, machine::Provenance>;

0 commit comments

Comments
 (0)