Skip to content

Commit 69fb641

Browse files
committed
Tidy up comments and function layout, should fix most of the review notes.
1 parent 2a40d9b commit 69fb641

20 files changed

+1005
-795
lines changed

src/bin/miri.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ fn main() {
195195
"-Zmiri-disable-stacked-borrows" => {
196196
miri_config.stacked_borrows = false;
197197
}
198+
"-Zmiri-disable-data-race-detector" => {
199+
miri_config.data_race_detector = false;
200+
}
198201
"-Zmiri-disable-alignment-check" => {
199202
miri_config.check_alignment = miri::AlignmentCheck::None;
200203
}

src/data_race.rs

Lines changed: 620 additions & 484 deletions
Large diffs are not rendered by default.

src/eval.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct MiriConfig {
4848
pub tracked_alloc_id: Option<AllocId>,
4949
/// Whether to track raw pointers in stacked borrows.
5050
pub track_raw: bool,
51+
/// Determine if data race detection should be enabled
52+
pub data_race_detector: bool,
5153
}
5254

5355
impl Default for MiriConfig {
@@ -65,6 +67,7 @@ impl Default for MiriConfig {
6567
tracked_call_id: None,
6668
tracked_alloc_id: None,
6769
track_raw: false,
70+
data_race_detector: true,
6871
}
6972
}
7073
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub use crate::shims::tls::{EvalContextExt as _, TlsData};
5555
pub use crate::shims::EvalContextExt as _;
5656

5757
pub use crate::data_race::{
58-
AtomicReadOp, AtomicWriteOp, AtomicRWOp, AtomicFenceOp, DataRaceLockHandle,
58+
AtomicReadOp, AtomicWriteOp, AtomicRwOp, AtomicFenceOp,
5959
EvalContextExt as DataRaceEvalContextExt
6060
};
6161
pub use crate::diagnostics::{
@@ -81,7 +81,7 @@ pub use crate::sync::{
8181
EvalContextExt as SyncEvalContextExt, CondvarId, MutexId, RwLockId
8282
};
8383
pub use crate::vector_clock::{
84-
VClock, VSmallClockSet, VectorIdx, VTimestamp
84+
VClock, VSmallClockMap, VectorIdx, VTimestamp
8585
};
8686

8787
/// Insert rustc arguments at the beginning of the argument list that Miri wants to be

src/machine.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,16 @@ impl fmt::Display for MiriMemoryKind {
109109
pub struct AllocExtra {
110110
/// Stacked Borrows state is only added if it is enabled.
111111
pub stacked_borrows: Option<stacked_borrows::AllocExtra>,
112-
/// Data race detection via the use of a vector-clock.
113-
pub data_race: data_race::AllocExtra,
112+
/// Data race detection via the use of a vector-clock,
113+
/// this is only added if it is enabled.
114+
pub data_race: Option<data_race::AllocExtra>,
114115
}
115116

116117
/// Extra global memory data
117118
#[derive(Clone, Debug)]
118119
pub struct MemoryExtra {
119120
pub stacked_borrows: Option<stacked_borrows::MemoryExtra>,
120-
pub data_race: data_race::MemoryExtra,
121+
pub data_race: Option<data_race::MemoryExtra>,
121122
pub intptrcast: intptrcast::MemoryExtra,
122123

123124
/// Mapping extern static names to their canonical allocation.
@@ -147,7 +148,11 @@ impl MemoryExtra {
147148
} else {
148149
None
149150
};
150-
let data_race = Rc::new(data_race::GlobalState::new());
151+
let data_race = if config.data_race_detector {
152+
Some(Rc::new(data_race::GlobalState::new()))
153+
}else{
154+
None
155+
};
151156
MemoryExtra {
152157
stacked_borrows,
153158
data_race,
@@ -472,7 +477,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
472477
// No stacks, no tag.
473478
(None, Tag::Untagged)
474479
};
475-
let race_alloc = data_race::AllocExtra::new_allocation(&memory_extra.data_race, alloc.size);
480+
let race_alloc = if let Some(data_race) = &memory_extra.data_race {
481+
Some(data_race::AllocExtra::new_allocation(&data_race, alloc.size))
482+
} else {
483+
None
484+
};
476485
let mut stacked_borrows = memory_extra.stacked_borrows.as_ref().map(|sb| sb.borrow_mut());
477486
let alloc: Allocation<Tag, Self::AllocExtra> = alloc.with_tags_and_extra(
478487
|alloc| {
@@ -590,7 +599,9 @@ impl AllocationExtra<Tag> for AllocExtra {
590599
ptr: Pointer<Tag>,
591600
size: Size,
592601
) -> InterpResult<'tcx> {
593-
alloc.extra.data_race.read(ptr, size)?;
602+
if let Some(data_race) = &alloc.extra.data_race {
603+
data_race.read(ptr, size)?;
604+
}
594605
if let Some(stacked_borrows) = &alloc.extra.stacked_borrows {
595606
stacked_borrows.memory_read(ptr, size)
596607
} else {
@@ -604,7 +615,9 @@ impl AllocationExtra<Tag> for AllocExtra {
604615
ptr: Pointer<Tag>,
605616
size: Size,
606617
) -> InterpResult<'tcx> {
607-
alloc.extra.data_race.write(ptr, size)?;
618+
if let Some(data_race) = &mut alloc.extra.data_race {
619+
data_race.write(ptr, size)?;
620+
}
608621
if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows {
609622
stacked_borrows.memory_written(ptr, size)
610623
} else {
@@ -618,7 +631,9 @@ impl AllocationExtra<Tag> for AllocExtra {
618631
ptr: Pointer<Tag>,
619632
size: Size,
620633
) -> InterpResult<'tcx> {
621-
alloc.extra.data_race.deallocate(ptr, size)?;
634+
if let Some(data_race) = &mut alloc.extra.data_race {
635+
data_race.deallocate(ptr, size)?;
636+
}
622637
if let Some(stacked_borrows) = &mut alloc.extra.stacked_borrows {
623638
stacked_borrows.memory_deallocated(ptr, size)
624639
} else {

0 commit comments

Comments
 (0)