@@ -65,7 +65,6 @@ use std::{
6565 cell:: { Cell , Ref , RefCell , RefMut } ,
6666 fmt:: Debug ,
6767 mem,
68- rc:: Rc ,
6968} ;
7069
7170use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
@@ -80,7 +79,7 @@ use crate::{
8079} ;
8180
8281pub type AllocExtra = VClockAlloc ;
83- pub type MemoryExtra = Rc < GlobalState > ;
82+ pub type MemoryExtra = GlobalState ;
8483
8584/// Valid atomic read-write operations, alias of atomic::Ordering (not non-exhaustive).
8685#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
@@ -488,7 +487,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
488487 ) -> InterpResult < ' tcx , ScalarMaybeUninit < Tag > > {
489488 let this = self . eval_context_ref ( ) ;
490489 let scalar = this. allow_data_races_ref ( move |this| this. read_scalar ( & place. into ( ) ) ) ?;
491- self . validate_atomic_load ( place, atomic) ?;
490+ this . validate_atomic_load ( place, atomic) ?;
492491 Ok ( scalar)
493492 }
494493
@@ -501,7 +500,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
501500 ) -> InterpResult < ' tcx > {
502501 let this = self . eval_context_mut ( ) ;
503502 this. allow_data_races_mut ( move |this| this. write_scalar ( val, & ( * dest) . into ( ) ) ) ?;
504- self . validate_atomic_store ( dest, atomic)
503+ this . validate_atomic_store ( dest, atomic)
505504 }
506505
507506 /// Perform a atomic operation on a memory location.
@@ -733,9 +732,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
733732pub struct VClockAlloc {
734733 /// Assigning each byte a MemoryCellClocks.
735734 alloc_ranges : RefCell < RangeMap < MemoryCellClocks > > ,
736-
737- /// Pointer to global state.
738- global : MemoryExtra ,
739735}
740736
741737impl VClockAlloc {
@@ -767,7 +763,6 @@ impl VClockAlloc {
767763 | MemoryKind :: Vtable => ( 0 , VectorIdx :: MAX_INDEX ) ,
768764 } ;
769765 VClockAlloc {
770- global : Rc :: clone ( global) ,
771766 alloc_ranges : RefCell :: new ( RangeMap :: new (
772767 len,
773768 MemoryCellClocks :: new ( alloc_timestamp, alloc_index) ,
@@ -888,21 +883,19 @@ impl VClockAlloc {
888883 /// being created or if it is temporarily disabled during a racy read or write
889884 /// operation for which data-race detection is handled separately, for example
890885 /// atomic read operations.
891- pub fn read < ' tcx > ( & self , pointer : Pointer < Tag > , len : Size ) -> InterpResult < ' tcx > {
892- if self . global . multi_threaded . get ( ) {
893- let ( index, clocks) = self . global . current_thread_state ( ) ;
886+ pub fn read < ' tcx > (
887+ & self ,
888+ pointer : Pointer < Tag > ,
889+ len : Size ,
890+ global : & GlobalState ,
891+ ) -> InterpResult < ' tcx > {
892+ if global. multi_threaded . get ( ) {
893+ let ( index, clocks) = global. current_thread_state ( ) ;
894894 let mut alloc_ranges = self . alloc_ranges . borrow_mut ( ) ;
895895 for ( _, range) in alloc_ranges. iter_mut ( pointer. offset , len) {
896896 if let Err ( DataRace ) = range. read_race_detect ( & * clocks, index) {
897897 // Report data-race.
898- return Self :: report_data_race (
899- & self . global ,
900- range,
901- "Read" ,
902- false ,
903- pointer,
904- len,
905- ) ;
898+ return Self :: report_data_race ( global, range, "Read" , false , pointer, len) ;
906899 }
907900 }
908901 Ok ( ( ) )
@@ -917,14 +910,15 @@ impl VClockAlloc {
917910 pointer : Pointer < Tag > ,
918911 len : Size ,
919912 write_type : WriteType ,
913+ global : & mut GlobalState ,
920914 ) -> InterpResult < ' tcx > {
921- if self . global . multi_threaded . get ( ) {
922- let ( index, clocks) = self . global . current_thread_state ( ) ;
915+ if global. multi_threaded . get ( ) {
916+ let ( index, clocks) = global. current_thread_state ( ) ;
923917 for ( _, range) in self . alloc_ranges . get_mut ( ) . iter_mut ( pointer. offset , len) {
924918 if let Err ( DataRace ) = range. write_race_detect ( & * clocks, index, write_type) {
925919 // Report data-race
926920 return Self :: report_data_race (
927- & self . global ,
921+ global,
928922 range,
929923 write_type. get_descriptor ( ) ,
930924 false ,
@@ -943,16 +937,26 @@ impl VClockAlloc {
943937 /// data-race threads if `multi-threaded` is false, either due to no threads
944938 /// being created or if it is temporarily disabled during a racy read or write
945939 /// operation
946- pub fn write < ' tcx > ( & mut self , pointer : Pointer < Tag > , len : Size ) -> InterpResult < ' tcx > {
947- self . unique_access ( pointer, len, WriteType :: Write )
940+ pub fn write < ' tcx > (
941+ & mut self ,
942+ pointer : Pointer < Tag > ,
943+ len : Size ,
944+ global : & mut GlobalState ,
945+ ) -> InterpResult < ' tcx > {
946+ self . unique_access ( pointer, len, WriteType :: Write , global)
948947 }
949948
950949 /// Detect data-races for an unsynchronized deallocate operation, will not perform
951950 /// data-race threads if `multi-threaded` is false, either due to no threads
952951 /// being created or if it is temporarily disabled during a racy read or write
953952 /// operation
954- pub fn deallocate < ' tcx > ( & mut self , pointer : Pointer < Tag > , len : Size ) -> InterpResult < ' tcx > {
955- self . unique_access ( pointer, len, WriteType :: Deallocate )
953+ pub fn deallocate < ' tcx > (
954+ & mut self ,
955+ pointer : Pointer < Tag > ,
956+ len : Size ,
957+ global : & mut GlobalState ,
958+ ) -> InterpResult < ' tcx > {
959+ self . unique_access ( pointer, len, WriteType :: Deallocate , global)
956960 }
957961}
958962
@@ -1035,15 +1039,14 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
10351039 ) ;
10361040
10371041 // Perform the atomic operation.
1038- let data_race = & alloc_meta. global ;
10391042 data_race. maybe_perform_sync_operation ( |index, mut clocks| {
10401043 for ( _, range) in
10411044 alloc_meta. alloc_ranges . borrow_mut ( ) . iter_mut ( place_ptr. offset , size)
10421045 {
10431046 if let Err ( DataRace ) = op ( range, & mut * clocks, index, atomic) {
10441047 mem:: drop ( clocks) ;
10451048 return VClockAlloc :: report_data_race (
1046- & alloc_meta . global ,
1049+ data_race ,
10471050 range,
10481051 description,
10491052 true ,
0 commit comments