Merge pull request #4454 from RalfJung/data_structure
move our data structures into a central location
This commit is contained in:
commit
5058f90402
11 changed files with 26 additions and 25 deletions
|
|
@ -30,7 +30,7 @@ pub type AllocState = Stacks;
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct Stacks {
|
||||
// Even reading memory can have effects on the stack, so we need a `RefCell` here.
|
||||
stacks: RangeMap<Stack>,
|
||||
stacks: DedupRangeMap<Stack>,
|
||||
/// Stores past operations on this allocation
|
||||
history: AllocHistory,
|
||||
/// The set of tags that have been exposed inside this allocation.
|
||||
|
|
@ -468,7 +468,7 @@ impl<'tcx> Stacks {
|
|||
let stack = Stack::new(item);
|
||||
|
||||
Stacks {
|
||||
stacks: RangeMap::new(size, stack),
|
||||
stacks: DedupRangeMap::new(size, stack),
|
||||
history: AllocHistory::new(id, item, machine),
|
||||
exposed_tags: FxHashSet::default(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||
let span = this.machine.current_span();
|
||||
|
||||
// Store initial permissions and their corresponding range.
|
||||
let mut perms_map: RangeMap<LocationState> = RangeMap::new(
|
||||
let mut perms_map: DedupRangeMap<LocationState> = DedupRangeMap::new(
|
||||
ptr_size,
|
||||
LocationState::new_accessed(Permission::new_disabled(), IdempotentForeignAccess::None), // this will be overwritten
|
||||
);
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ pub struct Tree {
|
|||
/// `unwrap` any `perm.get(key)`.
|
||||
///
|
||||
/// We do uphold the fact that `keys(perms)` is a subset of `keys(nodes)`
|
||||
pub(super) rperms: RangeMap<UniValMap<LocationState>>,
|
||||
pub(super) rperms: DedupRangeMap<UniValMap<LocationState>>,
|
||||
/// The index of the root node.
|
||||
pub(super) root: UniIndex,
|
||||
}
|
||||
|
|
@ -609,7 +609,7 @@ impl Tree {
|
|||
IdempotentForeignAccess::None,
|
||||
),
|
||||
);
|
||||
RangeMap::new(size, perms)
|
||||
DedupRangeMap::new(size, perms)
|
||||
};
|
||||
Self { root: root_idx, nodes, rperms, tag_mapping }
|
||||
}
|
||||
|
|
@ -631,7 +631,7 @@ impl<'tcx> Tree {
|
|||
base_offset: Size,
|
||||
parent_tag: BorTag,
|
||||
new_tag: BorTag,
|
||||
initial_perms: RangeMap<LocationState>,
|
||||
initial_perms: DedupRangeMap<LocationState>,
|
||||
default_perm: Permission,
|
||||
protected: bool,
|
||||
span: Span,
|
||||
|
|
|
|||
|
|
@ -997,7 +997,7 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct VClockAlloc {
|
||||
/// Assigning each byte a MemoryCellClocks.
|
||||
alloc_ranges: RefCell<RangeMap<MemoryCellClocks>>,
|
||||
alloc_ranges: RefCell<DedupRangeMap<MemoryCellClocks>>,
|
||||
}
|
||||
|
||||
impl VisitProvenance for VClockAlloc {
|
||||
|
|
@ -1045,7 +1045,7 @@ impl VClockAlloc {
|
|||
(VTimestamp::ZERO, global.thread_index(ThreadId::MAIN_THREAD)),
|
||||
};
|
||||
VClockAlloc {
|
||||
alloc_ranges: RefCell::new(RangeMap::new(
|
||||
alloc_ranges: RefCell::new(DedupRangeMap::new(
|
||||
len,
|
||||
MemoryCellClocks::new(alloc_timestamp, alloc_index),
|
||||
)),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ pub mod cpu_affinity;
|
|||
pub mod data_race;
|
||||
mod data_race_handler;
|
||||
pub mod init_once;
|
||||
mod range_object_map;
|
||||
pub mod sync;
|
||||
pub mod thread;
|
||||
mod vector_clock;
|
||||
|
|
|
|||
|
|
@ -90,9 +90,9 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
|
||||
use super::AllocDataRaceHandler;
|
||||
use super::data_race::{GlobalState as DataRaceState, ThreadClockSet};
|
||||
use super::range_object_map::{AccessType, RangeObjectMap};
|
||||
use super::vector_clock::{VClock, VTimestamp, VectorIdx};
|
||||
use crate::concurrency::GlobalDataRaceHandler;
|
||||
use crate::data_structures::range_object_map::{AccessType, RangeObjectMap};
|
||||
use crate::*;
|
||||
|
||||
pub type AllocState = StoreBufferAlloc;
|
||||
|
|
|
|||
|
|
@ -17,18 +17,18 @@ struct Elem<T> {
|
|||
data: T,
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RangeMap<T> {
|
||||
pub struct DedupRangeMap<T> {
|
||||
v: Vec<Elem<T>>,
|
||||
}
|
||||
|
||||
impl<T> RangeMap<T> {
|
||||
impl<T> DedupRangeMap<T> {
|
||||
/// Creates a new `RangeMap` for the given size, and with the given initial value used for
|
||||
/// the entire range.
|
||||
#[inline(always)]
|
||||
pub fn new(size: Size, init: T) -> RangeMap<T> {
|
||||
pub fn new(size: Size, init: T) -> DedupRangeMap<T> {
|
||||
let size = size.bytes();
|
||||
let v = if size > 0 { vec![Elem { range: 0..size, data: init }] } else { Vec::new() };
|
||||
RangeMap { v }
|
||||
DedupRangeMap { v }
|
||||
}
|
||||
|
||||
pub fn size(&self) -> Size {
|
||||
|
|
@ -246,7 +246,7 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
/// Query the map at every offset in the range and collect the results.
|
||||
fn to_vec<T: Copy>(map: &RangeMap<T>, offset: u64, len: u64) -> Vec<T> {
|
||||
fn to_vec<T: Copy>(map: &DedupRangeMap<T>, offset: u64, len: u64) -> Vec<T> {
|
||||
(offset..offset + len)
|
||||
.map(|i| {
|
||||
map.iter(Size::from_bytes(i), Size::from_bytes(1)).next().map(|(_, &t)| t).unwrap()
|
||||
|
|
@ -256,7 +256,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn basic_insert() {
|
||||
let mut map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
|
||||
let mut map = DedupRangeMap::<i32>::new(Size::from_bytes(20), -1);
|
||||
// Insert.
|
||||
for (_, x) in map.iter_mut(Size::from_bytes(10), Size::from_bytes(1)) {
|
||||
*x = 42;
|
||||
|
|
@ -278,7 +278,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn gaps() {
|
||||
let mut map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
|
||||
let mut map = DedupRangeMap::<i32>::new(Size::from_bytes(20), -1);
|
||||
for (_, x) in map.iter_mut(Size::from_bytes(11), Size::from_bytes(1)) {
|
||||
*x = 42;
|
||||
}
|
||||
|
|
@ -319,26 +319,26 @@ mod tests {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn out_of_range_iter_mut() {
|
||||
let mut map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
|
||||
let mut map = DedupRangeMap::<i32>::new(Size::from_bytes(20), -1);
|
||||
let _ = map.iter_mut(Size::from_bytes(11), Size::from_bytes(11));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn out_of_range_iter() {
|
||||
let map = RangeMap::<i32>::new(Size::from_bytes(20), -1);
|
||||
let map = DedupRangeMap::<i32>::new(Size::from_bytes(20), -1);
|
||||
let _ = map.iter(Size::from_bytes(11), Size::from_bytes(11));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_map_iter() {
|
||||
let map = RangeMap::<i32>::new(Size::from_bytes(0), -1);
|
||||
let map = DedupRangeMap::<i32>::new(Size::from_bytes(0), -1);
|
||||
let _ = map.iter(Size::from_bytes(0), Size::from_bytes(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_map_iter_mut() {
|
||||
let mut map = RangeMap::<i32>::new(Size::from_bytes(0), -1);
|
||||
let mut map = DedupRangeMap::<i32>::new(Size::from_bytes(0), -1);
|
||||
let _ = map.iter_mut(Size::from_bytes(0), Size::from_bytes(0));
|
||||
}
|
||||
}
|
||||
3
src/tools/miri/src/data_structures/mod.rs
Normal file
3
src/tools/miri/src/data_structures/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod dedup_range_map;
|
||||
pub mod mono_hash_map;
|
||||
pub mod range_object_map;
|
||||
|
|
@ -75,16 +75,15 @@ mod alloc_addresses;
|
|||
mod borrow_tracker;
|
||||
mod clock;
|
||||
mod concurrency;
|
||||
mod data_structures;
|
||||
mod diagnostics;
|
||||
mod eval;
|
||||
mod helpers;
|
||||
mod intrinsics;
|
||||
mod machine;
|
||||
mod math;
|
||||
mod mono_hash_map;
|
||||
mod operator;
|
||||
mod provenance_gc;
|
||||
mod range_map;
|
||||
mod shims;
|
||||
|
||||
// Establish a "crate-wide prelude": we often import `crate::*`.
|
||||
|
|
@ -132,6 +131,8 @@ pub use crate::concurrency::thread::{
|
|||
ThreadManager, TimeoutAnchor, TimeoutClock, UnblockKind,
|
||||
};
|
||||
pub use crate::concurrency::{GenmcConfig, GenmcCtx};
|
||||
pub use crate::data_structures::dedup_range_map::DedupRangeMap;
|
||||
pub use crate::data_structures::mono_hash_map::MonoHashMap;
|
||||
pub use crate::diagnostics::{
|
||||
EvalContextExt as _, NonHaltingDiagnostic, TerminationInfo, report_error,
|
||||
};
|
||||
|
|
@ -145,10 +146,8 @@ pub use crate::machine::{
|
|||
AllocExtra, DynMachineCallback, FrameExtra, MachineCallback, MemoryKind, MiriInterpCx,
|
||||
MiriInterpCxExt, MiriMachine, MiriMemoryKind, PrimitiveLayouts, Provenance, ProvenanceExtra,
|
||||
};
|
||||
pub use crate::mono_hash_map::MonoHashMap;
|
||||
pub use crate::operator::EvalContextExt as _;
|
||||
pub use crate::provenance_gc::{EvalContextExt as _, LiveAllocs, VisitProvenance, VisitWith};
|
||||
pub use crate::range_map::RangeMap;
|
||||
pub use crate::shims::EmulateItemResult;
|
||||
pub use crate::shims::env::{EnvVars, EvalContextExt as _};
|
||||
pub use crate::shims::foreign_items::{DynSym, EvalContextExt as _};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue