Skip to content

Commit c73f8b1

Browse files
committed
fmt
1 parent 1bbd6e6 commit c73f8b1

File tree

4 files changed

+53
-28
lines changed

4 files changed

+53
-28
lines changed

src/data_race.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -883,21 +883,19 @@ impl VClockAlloc {
883883
/// being created or if it is temporarily disabled during a racy read or write
884884
/// operation for which data-race detection is handled separately, for example
885885
/// atomic read operations.
886-
pub fn read<'tcx>(&self, pointer: Pointer<Tag>, len: Size, global: &GlobalState) -> InterpResult<'tcx> {
886+
pub fn read<'tcx>(
887+
&self,
888+
pointer: Pointer<Tag>,
889+
len: Size,
890+
global: &GlobalState,
891+
) -> InterpResult<'tcx> {
887892
if global.multi_threaded.get() {
888893
let (index, clocks) = global.current_thread_state();
889894
let mut alloc_ranges = self.alloc_ranges.borrow_mut();
890895
for (_, range) in alloc_ranges.iter_mut(pointer.offset, len) {
891896
if let Err(DataRace) = range.read_race_detect(&*clocks, index) {
892897
// Report data-race.
893-
return Self::report_data_race(
894-
global,
895-
range,
896-
"Read",
897-
false,
898-
pointer,
899-
len,
900-
);
898+
return Self::report_data_race(global, range, "Read", false, pointer, len);
901899
}
902900
}
903901
Ok(())
@@ -939,15 +937,25 @@ impl VClockAlloc {
939937
/// data-race threads if `multi-threaded` is false, either due to no threads
940938
/// being created or if it is temporarily disabled during a racy read or write
941939
/// operation
942-
pub fn write<'tcx>(&mut self, pointer: Pointer<Tag>, len: Size, global: &mut GlobalState) -> InterpResult<'tcx> {
940+
pub fn write<'tcx>(
941+
&mut self,
942+
pointer: Pointer<Tag>,
943+
len: Size,
944+
global: &mut GlobalState,
945+
) -> InterpResult<'tcx> {
943946
self.unique_access(pointer, len, WriteType::Write, global)
944947
}
945948

946949
/// Detect data-races for an unsynchronized deallocate operation, will not perform
947950
/// data-race threads if `multi-threaded` is false, either due to no threads
948951
/// being created or if it is temporarily disabled during a racy read or write
949952
/// operation
950-
pub fn deallocate<'tcx>(&mut self, pointer: Pointer<Tag>, len: Size, global: &mut GlobalState) -> InterpResult<'tcx> {
953+
pub fn deallocate<'tcx>(
954+
&mut self,
955+
pointer: Pointer<Tag>,
956+
len: Size,
957+
global: &mut GlobalState,
958+
) -> InterpResult<'tcx> {
951959
self.unique_access(pointer, len, WriteType::Deallocate, global)
952960
}
953961
}

src/machine.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,8 @@ impl MemoryExtra {
151151
} else {
152152
None
153153
};
154-
let data_race = if config.data_race_detector {
155-
Some(data_race::GlobalState::new())
156-
} else {
157-
None
158-
};
154+
let data_race =
155+
if config.data_race_detector { Some(data_race::GlobalState::new()) } else { None };
159156
MemoryExtra {
160157
stacked_borrows,
161158
data_race,
@@ -532,7 +529,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
532529
data_race.write(ptr, size, memory_extra.data_race.as_mut().unwrap())?;
533530
}
534531
if let Some(stacked_borrows) = &mut alloc_extra.stacked_borrows {
535-
stacked_borrows.memory_written(ptr, size, memory_extra.stacked_borrows.as_mut().unwrap())
532+
stacked_borrows.memory_written(
533+
ptr,
534+
size,
535+
memory_extra.stacked_borrows.as_mut().unwrap(),
536+
)
536537
} else {
537538
Ok(())
538539
}
@@ -552,7 +553,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
552553
data_race.deallocate(ptr, size, memory_extra.data_race.as_mut().unwrap())?;
553554
}
554555
if let Some(stacked_borrows) = &mut alloc_extra.stacked_borrows {
555-
stacked_borrows.memory_deallocated(ptr, size, memory_extra.stacked_borrows.as_mut().unwrap())
556+
stacked_borrows.memory_deallocated(
557+
ptr,
558+
size,
559+
memory_extra.stacked_borrows.as_mut().unwrap(),
560+
)
556561
} else {
557562
Ok(())
558563
}

src/stacked_borrows.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Implements "Stacked Borrows". See <https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md>
22
//! for further information.
33
4+
use log::trace;
45
use std::cell::RefCell;
56
use std::fmt;
67
use std::num::NonZeroU64;
7-
use log::trace;
88

99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_hir::Mutability;
@@ -509,15 +509,29 @@ impl Stacks {
509509
}
510510

511511
#[inline(always)]
512-
pub fn memory_read<'tcx>(&self, ptr: Pointer<Tag>, size: Size, extra: &MemoryExtra) -> InterpResult<'tcx> {
512+
pub fn memory_read<'tcx>(
513+
&self,
514+
ptr: Pointer<Tag>,
515+
size: Size,
516+
extra: &MemoryExtra,
517+
) -> InterpResult<'tcx> {
513518
trace!("read access with tag {:?}: {:?}, size {}", ptr.tag, ptr.erase_tag(), size.bytes());
514-
self.for_each(ptr, size, &*extra.borrow(), |ptr, stack, global| stack.access(AccessKind::Read, ptr, global))
519+
self.for_each(ptr, size, &*extra.borrow(), |ptr, stack, global| {
520+
stack.access(AccessKind::Read, ptr, global)
521+
})
515522
}
516523

517524
#[inline(always)]
518-
pub fn memory_written<'tcx>(&mut self, ptr: Pointer<Tag>, size: Size, extra: &mut MemoryExtra) -> InterpResult<'tcx> {
525+
pub fn memory_written<'tcx>(
526+
&mut self,
527+
ptr: Pointer<Tag>,
528+
size: Size,
529+
extra: &mut MemoryExtra,
530+
) -> InterpResult<'tcx> {
519531
trace!("write access with tag {:?}: {:?}, size {}", ptr.tag, ptr.erase_tag(), size.bytes());
520-
self.for_each(ptr, size, extra.get_mut(), |ptr, stack, global| stack.access(AccessKind::Write, ptr, global))
532+
self.for_each(ptr, size, extra.get_mut(), |ptr, stack, global| {
533+
stack.access(AccessKind::Write, ptr, global)
534+
})
521535
}
522536

523537
#[inline(always)]
@@ -589,7 +603,8 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
589603
}
590604
};
591605
let item = Item { perm, tag: new_tag, protector };
592-
stacked_borrows.for_each(ptr, size, &*global, |ptr, stack, global| stack.grant(ptr, item, global))
606+
stacked_borrows
607+
.for_each(ptr, size, &*global, |ptr, stack, global| stack.grant(ptr, item, global))
593608
}
594609

595610
/// Retags an indidual pointer, returning the retagged version.

src/thread.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,7 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
436436

437437
/// Wakes up threads joining on the active one and deallocates thread-local statics.
438438
/// The `AllocId` that can now be freed is returned.
439-
fn thread_terminated(
440-
&mut self,
441-
data_race: &Option<data_race::GlobalState>,
442-
) -> Vec<AllocId> {
439+
fn thread_terminated(&mut self, data_race: &Option<data_race::GlobalState>) -> Vec<AllocId> {
443440
let mut free_tls_statics = Vec::new();
444441
{
445442
let mut thread_local_statics = self.thread_local_alloc_ids.borrow_mut();

0 commit comments

Comments
 (0)