From c73f8b1097e9e5d01baa56df9bb4cd93f3828fd4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 22 May 2021 14:55:33 +0200 Subject: [PATCH] fmt --- src/data_race.rs | 30 +++++++++++++++++++----------- src/machine.rs | 19 ++++++++++++------- src/stacked_borrows.rs | 27 +++++++++++++++++++++------ src/thread.rs | 5 +---- 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/data_race.rs b/src/data_race.rs index ff6c720740a1..16ab03ace222 100644 --- a/src/data_race.rs +++ b/src/data_race.rs @@ -883,21 +883,19 @@ impl VClockAlloc { /// being created or if it is temporarily disabled during a racy read or write /// operation for which data-race detection is handled separately, for example /// atomic read operations. - pub fn read<'tcx>(&self, pointer: Pointer, len: Size, global: &GlobalState) -> InterpResult<'tcx> { + pub fn read<'tcx>( + &self, + pointer: Pointer, + len: Size, + global: &GlobalState, + ) -> InterpResult<'tcx> { if global.multi_threaded.get() { let (index, clocks) = global.current_thread_state(); let mut alloc_ranges = self.alloc_ranges.borrow_mut(); for (_, range) in alloc_ranges.iter_mut(pointer.offset, len) { if let Err(DataRace) = range.read_race_detect(&*clocks, index) { // Report data-race. - return Self::report_data_race( - global, - range, - "Read", - false, - pointer, - len, - ); + return Self::report_data_race(global, range, "Read", false, pointer, len); } } Ok(()) @@ -939,7 +937,12 @@ impl VClockAlloc { /// data-race threads if `multi-threaded` is false, either due to no threads /// being created or if it is temporarily disabled during a racy read or write /// operation - pub fn write<'tcx>(&mut self, pointer: Pointer, len: Size, global: &mut GlobalState) -> InterpResult<'tcx> { + pub fn write<'tcx>( + &mut self, + pointer: Pointer, + len: Size, + global: &mut GlobalState, + ) -> InterpResult<'tcx> { self.unique_access(pointer, len, WriteType::Write, global) } @@ -947,7 +950,12 @@ impl VClockAlloc { /// data-race threads if `multi-threaded` is false, either due to no threads /// being created or if it is temporarily disabled during a racy read or write /// operation - pub fn deallocate<'tcx>(&mut self, pointer: Pointer, len: Size, global: &mut GlobalState) -> InterpResult<'tcx> { + pub fn deallocate<'tcx>( + &mut self, + pointer: Pointer, + len: Size, + global: &mut GlobalState, + ) -> InterpResult<'tcx> { self.unique_access(pointer, len, WriteType::Deallocate, global) } } diff --git a/src/machine.rs b/src/machine.rs index ce4b96ad4a46..fb2d877c3803 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -151,11 +151,8 @@ impl MemoryExtra { } else { None }; - let data_race = if config.data_race_detector { - Some(data_race::GlobalState::new()) - } else { - None - }; + let data_race = + if config.data_race_detector { Some(data_race::GlobalState::new()) } else { None }; MemoryExtra { stacked_borrows, data_race, @@ -532,7 +529,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { data_race.write(ptr, size, memory_extra.data_race.as_mut().unwrap())?; } if let Some(stacked_borrows) = &mut alloc_extra.stacked_borrows { - stacked_borrows.memory_written(ptr, size, memory_extra.stacked_borrows.as_mut().unwrap()) + stacked_borrows.memory_written( + ptr, + size, + memory_extra.stacked_borrows.as_mut().unwrap(), + ) } else { Ok(()) } @@ -552,7 +553,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { data_race.deallocate(ptr, size, memory_extra.data_race.as_mut().unwrap())?; } if let Some(stacked_borrows) = &mut alloc_extra.stacked_borrows { - stacked_borrows.memory_deallocated(ptr, size, memory_extra.stacked_borrows.as_mut().unwrap()) + stacked_borrows.memory_deallocated( + ptr, + size, + memory_extra.stacked_borrows.as_mut().unwrap(), + ) } else { Ok(()) } diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index 87f8e4886933..a9c030c87de4 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -1,10 +1,10 @@ //! Implements "Stacked Borrows". See //! for further information. +use log::trace; use std::cell::RefCell; use std::fmt; use std::num::NonZeroU64; -use log::trace; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::Mutability; @@ -509,15 +509,29 @@ impl Stacks { } #[inline(always)] - pub fn memory_read<'tcx>(&self, ptr: Pointer, size: Size, extra: &MemoryExtra) -> InterpResult<'tcx> { + pub fn memory_read<'tcx>( + &self, + ptr: Pointer, + size: Size, + extra: &MemoryExtra, + ) -> InterpResult<'tcx> { trace!("read access with tag {:?}: {:?}, size {}", ptr.tag, ptr.erase_tag(), size.bytes()); - self.for_each(ptr, size, &*extra.borrow(), |ptr, stack, global| stack.access(AccessKind::Read, ptr, global)) + self.for_each(ptr, size, &*extra.borrow(), |ptr, stack, global| { + stack.access(AccessKind::Read, ptr, global) + }) } #[inline(always)] - pub fn memory_written<'tcx>(&mut self, ptr: Pointer, size: Size, extra: &mut MemoryExtra) -> InterpResult<'tcx> { + pub fn memory_written<'tcx>( + &mut self, + ptr: Pointer, + size: Size, + extra: &mut MemoryExtra, + ) -> InterpResult<'tcx> { trace!("write access with tag {:?}: {:?}, size {}", ptr.tag, ptr.erase_tag(), size.bytes()); - self.for_each(ptr, size, extra.get_mut(), |ptr, stack, global| stack.access(AccessKind::Write, ptr, global)) + self.for_each(ptr, size, extra.get_mut(), |ptr, stack, global| { + stack.access(AccessKind::Write, ptr, global) + }) } #[inline(always)] @@ -589,7 +603,8 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } }; let item = Item { perm, tag: new_tag, protector }; - stacked_borrows.for_each(ptr, size, &*global, |ptr, stack, global| stack.grant(ptr, item, global)) + stacked_borrows + .for_each(ptr, size, &*global, |ptr, stack, global| stack.grant(ptr, item, global)) } /// Retags an indidual pointer, returning the retagged version. diff --git a/src/thread.rs b/src/thread.rs index 8aaeb7e349c6..3418e8c7d2bf 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -436,10 +436,7 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> { /// Wakes up threads joining on the active one and deallocates thread-local statics. /// The `AllocId` that can now be freed is returned. - fn thread_terminated( - &mut self, - data_race: &Option, - ) -> Vec { + fn thread_terminated(&mut self, data_race: &Option) -> Vec { let mut free_tls_statics = Vec::new(); { let mut thread_local_statics = self.thread_local_alloc_ids.borrow_mut();