Skip to content

Commit ecaab58

Browse files
committed
move our data structures into a central location
1 parent 6acaee8 commit ecaab58

File tree

11 files changed

+26
-25
lines changed

11 files changed

+26
-25
lines changed

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub type AllocState = Stacks;
3030
#[derive(Clone, Debug)]
3131
pub struct Stacks {
3232
// Even reading memory can have effects on the stack, so we need a `RefCell` here.
33-
stacks: RangeMap<Stack>,
33+
stacks: DedupRangeMap<Stack>,
3434
/// Stores past operations on this allocation
3535
history: AllocHistory,
3636
/// The set of tags that have been exposed inside this allocation.
@@ -468,7 +468,7 @@ impl<'tcx> Stacks {
468468
let stack = Stack::new(item);
469469

470470
Stacks {
471-
stacks: RangeMap::new(size, stack),
471+
stacks: DedupRangeMap::new(size, stack),
472472
history: AllocHistory::new(id, item, machine),
473473
exposed_tags: FxHashSet::default(),
474474
}

src/borrow_tracker/tree_borrows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
314314
let span = this.machine.current_span();
315315

316316
// Store initial permissions and their corresponding range.
317-
let mut perms_map: RangeMap<LocationState> = RangeMap::new(
317+
let mut perms_map: DedupRangeMap<LocationState> = DedupRangeMap::new(
318318
ptr_size,
319319
LocationState::new_accessed(Permission::new_disabled(), IdempotentForeignAccess::None), // this will be overwritten
320320
);

src/borrow_tracker/tree_borrows/tree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub struct Tree {
247247
/// `unwrap` any `perm.get(key)`.
248248
///
249249
/// We do uphold the fact that `keys(perms)` is a subset of `keys(nodes)`
250-
pub(super) rperms: RangeMap<UniValMap<LocationState>>,
250+
pub(super) rperms: DedupRangeMap<UniValMap<LocationState>>,
251251
/// The index of the root node.
252252
pub(super) root: UniIndex,
253253
}
@@ -609,7 +609,7 @@ impl Tree {
609609
IdempotentForeignAccess::None,
610610
),
611611
);
612-
RangeMap::new(size, perms)
612+
DedupRangeMap::new(size, perms)
613613
};
614614
Self { root: root_idx, nodes, rperms, tag_mapping }
615615
}
@@ -631,7 +631,7 @@ impl<'tcx> Tree {
631631
base_offset: Size,
632632
parent_tag: BorTag,
633633
new_tag: BorTag,
634-
initial_perms: RangeMap<LocationState>,
634+
initial_perms: DedupRangeMap<LocationState>,
635635
default_perm: Permission,
636636
protected: bool,
637637
span: Span,

src/concurrency/data_race.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> {
997997
#[derive(Debug, Clone)]
998998
pub struct VClockAlloc {
999999
/// Assigning each byte a MemoryCellClocks.
1000-
alloc_ranges: RefCell<RangeMap<MemoryCellClocks>>,
1000+
alloc_ranges: RefCell<DedupRangeMap<MemoryCellClocks>>,
10011001
}
10021002

10031003
impl VisitProvenance for VClockAlloc {
@@ -1045,7 +1045,7 @@ impl VClockAlloc {
10451045
(VTimestamp::ZERO, global.thread_index(ThreadId::MAIN_THREAD)),
10461046
};
10471047
VClockAlloc {
1048-
alloc_ranges: RefCell::new(RangeMap::new(
1048+
alloc_ranges: RefCell::new(DedupRangeMap::new(
10491049
len,
10501050
MemoryCellClocks::new(alloc_timestamp, alloc_index),
10511051
)),

src/concurrency/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pub mod cpu_affinity;
22
pub mod data_race;
33
mod data_race_handler;
44
pub mod init_once;
5-
mod range_object_map;
65
pub mod sync;
76
pub mod thread;
87
mod vector_clock;

src/concurrency/weak_memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ use rustc_data_structures::fx::FxHashMap;
9090

9191
use super::AllocDataRaceHandler;
9292
use super::data_race::{GlobalState as DataRaceState, ThreadClockSet};
93-
use super::range_object_map::{AccessType, RangeObjectMap};
9493
use super::vector_clock::{VClock, VTimestamp, VectorIdx};
9594
use crate::concurrency::GlobalDataRaceHandler;
95+
use crate::data_structures::range_object_map::{AccessType, RangeObjectMap};
9696
use crate::*;
9797

9898
pub type AllocState = StoreBufferAlloc;

src/range_map.rs renamed to src/data_structures/dedup_range_map.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ struct Elem<T> {
1717
data: T,
1818
}
1919
#[derive(Clone, Debug)]
20-
pub struct RangeMap<T> {
20+
pub struct DedupRangeMap<T> {
2121
v: Vec<Elem<T>>,
2222
}
2323

24-
impl<T> RangeMap<T> {
24+
impl<T> DedupRangeMap<T> {
2525
/// Creates a new `RangeMap` for the given size, and with the given initial value used for
2626
/// the entire range.
2727
#[inline(always)]
28-
pub fn new(size: Size, init: T) -> RangeMap<T> {
28+
pub fn new(size: Size, init: T) -> DedupRangeMap<T> {
2929
let size = size.bytes();
3030
let v = if size > 0 { vec![Elem { range: 0..size, data: init }] } else { Vec::new() };
31-
RangeMap { v }
31+
DedupRangeMap { v }
3232
}
3333

3434
pub fn size(&self) -> Size {
@@ -246,7 +246,7 @@ mod tests {
246246
use super::*;
247247

248248
/// Query the map at every offset in the range and collect the results.
249-
fn to_vec<T: Copy>(map: &RangeMap<T>, offset: u64, len: u64) -> Vec<T> {
249+
fn to_vec<T: Copy>(map: &DedupRangeMap<T>, offset: u64, len: u64) -> Vec<T> {
250250
(offset..offset + len)
251251
.map(|i| {
252252
map.iter(Size::from_bytes(i), Size::from_bytes(1)).next().map(|(_, &t)| t).unwrap()
@@ -256,7 +256,7 @@ mod tests {
256256

257257
#[test]
258258
fn basic_insert() {
259-
let mut map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
259+
let mut map = DedupRangeMap::<i32>::new(Size::from_bytes(20), -1);
260260
// Insert.
261261
for (_, x) in map.iter_mut(Size::from_bytes(10), Size::from_bytes(1)) {
262262
*x = 42;
@@ -278,7 +278,7 @@ mod tests {
278278

279279
#[test]
280280
fn gaps() {
281-
let mut map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
281+
let mut map = DedupRangeMap::<i32>::new(Size::from_bytes(20), -1);
282282
for (_, x) in map.iter_mut(Size::from_bytes(11), Size::from_bytes(1)) {
283283
*x = 42;
284284
}
@@ -319,26 +319,26 @@ mod tests {
319319
#[test]
320320
#[should_panic]
321321
fn out_of_range_iter_mut() {
322-
let mut map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
322+
let mut map = DedupRangeMap::<i32>::new(Size::from_bytes(20), -1);
323323
let _ = map.iter_mut(Size::from_bytes(11), Size::from_bytes(11));
324324
}
325325

326326
#[test]
327327
#[should_panic]
328328
fn out_of_range_iter() {
329-
let map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
329+
let map = DedupRangeMap::<i32>::new(Size::from_bytes(20), -1);
330330
let _ = map.iter(Size::from_bytes(11), Size::from_bytes(11));
331331
}
332332

333333
#[test]
334334
fn empty_map_iter() {
335-
let map = RangeMap::<i32>::new(Size::from_bytes(0), -1);
335+
let map = DedupRangeMap::<i32>::new(Size::from_bytes(0), -1);
336336
let _ = map.iter(Size::from_bytes(0), Size::from_bytes(0));
337337
}
338338

339339
#[test]
340340
fn empty_map_iter_mut() {
341-
let mut map = RangeMap::<i32>::new(Size::from_bytes(0), -1);
341+
let mut map = DedupRangeMap::<i32>::new(Size::from_bytes(0), -1);
342342
let _ = map.iter_mut(Size::from_bytes(0), Size::from_bytes(0));
343343
}
344344
}

src/data_structures/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod dedup_range_map;
2+
pub mod mono_hash_map;
3+
pub mod range_object_map;
File renamed without changes.

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,15 @@ mod alloc_addresses;
7575
mod borrow_tracker;
7676
mod clock;
7777
mod concurrency;
78+
mod data_structures;
7879
mod diagnostics;
7980
mod eval;
8081
mod helpers;
8182
mod intrinsics;
8283
mod machine;
8384
mod math;
84-
mod mono_hash_map;
8585
mod operator;
8686
mod provenance_gc;
87-
mod range_map;
8887
mod shims;
8988

9089
// Establish a "crate-wide prelude": we often import `crate::*`.
@@ -132,6 +131,8 @@ pub use crate::concurrency::thread::{
132131
ThreadManager, TimeoutAnchor, TimeoutClock, UnblockKind,
133132
};
134133
pub use crate::concurrency::{GenmcConfig, GenmcCtx};
134+
pub use crate::data_structures::dedup_range_map::DedupRangeMap;
135+
pub use crate::data_structures::mono_hash_map::MonoHashMap;
135136
pub use crate::diagnostics::{
136137
EvalContextExt as _, NonHaltingDiagnostic, TerminationInfo, report_error,
137138
};
@@ -145,10 +146,8 @@ pub use crate::machine::{
145146
AllocExtra, DynMachineCallback, FrameExtra, MachineCallback, MemoryKind, MiriInterpCx,
146147
MiriInterpCxExt, MiriMachine, MiriMemoryKind, PrimitiveLayouts, Provenance, ProvenanceExtra,
147148
};
148-
pub use crate::mono_hash_map::MonoHashMap;
149149
pub use crate::operator::EvalContextExt as _;
150150
pub use crate::provenance_gc::{EvalContextExt as _, LiveAllocs, VisitProvenance, VisitWith};
151-
pub use crate::range_map::RangeMap;
152151
pub use crate::shims::EmulateItemResult;
153152
pub use crate::shims::env::{EnvVars, EvalContextExt as _};
154153
pub use crate::shims::foreign_items::{DynSym, EvalContextExt as _};

0 commit comments

Comments
 (0)