@@ -65,7 +65,6 @@ use std::{
65
65
cell:: { Cell , Ref , RefCell , RefMut } ,
66
66
fmt:: Debug ,
67
67
mem,
68
- rc:: Rc ,
69
68
} ;
70
69
71
70
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
@@ -80,7 +79,7 @@ use crate::{
80
79
} ;
81
80
82
81
pub type AllocExtra = VClockAlloc ;
83
- pub type MemoryExtra = Rc < GlobalState > ;
82
+ pub type MemoryExtra = GlobalState ;
84
83
85
84
/// Valid atomic read-write operations, alias of atomic::Ordering (not non-exhaustive).
86
85
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
@@ -488,7 +487,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
488
487
) -> InterpResult < ' tcx , ScalarMaybeUninit < Tag > > {
489
488
let this = self . eval_context_ref ( ) ;
490
489
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) ?;
492
491
Ok ( scalar)
493
492
}
494
493
@@ -501,7 +500,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
501
500
) -> InterpResult < ' tcx > {
502
501
let this = self . eval_context_mut ( ) ;
503
502
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)
505
504
}
506
505
507
506
/// Perform a atomic operation on a memory location.
@@ -733,9 +732,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
733
732
pub struct VClockAlloc {
734
733
/// Assigning each byte a MemoryCellClocks.
735
734
alloc_ranges : RefCell < RangeMap < MemoryCellClocks > > ,
736
-
737
- /// Pointer to global state.
738
- global : MemoryExtra ,
739
735
}
740
736
741
737
impl VClockAlloc {
@@ -767,7 +763,6 @@ impl VClockAlloc {
767
763
| MemoryKind :: Vtable => ( 0 , VectorIdx :: MAX_INDEX ) ,
768
764
} ;
769
765
VClockAlloc {
770
- global : Rc :: clone ( global) ,
771
766
alloc_ranges : RefCell :: new ( RangeMap :: new (
772
767
len,
773
768
MemoryCellClocks :: new ( alloc_timestamp, alloc_index) ,
@@ -888,15 +883,15 @@ impl VClockAlloc {
888
883
/// being created or if it is temporarily disabled during a racy read or write
889
884
/// operation for which data-race detection is handled separately, for example
890
885
/// 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 > ( & self , pointer : Pointer < Tag > , len : Size , global : & GlobalState ) -> InterpResult < ' tcx > {
887
+ if global. multi_threaded . get ( ) {
888
+ let ( index, clocks) = global. current_thread_state ( ) ;
894
889
let mut alloc_ranges = self . alloc_ranges . borrow_mut ( ) ;
895
890
for ( _, range) in alloc_ranges. iter_mut ( pointer. offset , len) {
896
891
if let Err ( DataRace ) = range. read_race_detect ( & * clocks, index) {
897
892
// Report data-race.
898
893
return Self :: report_data_race (
899
- & self . global ,
894
+ global,
900
895
range,
901
896
"Read" ,
902
897
false ,
@@ -917,14 +912,15 @@ impl VClockAlloc {
917
912
pointer : Pointer < Tag > ,
918
913
len : Size ,
919
914
write_type : WriteType ,
915
+ global : & mut GlobalState ,
920
916
) -> InterpResult < ' tcx > {
921
- if self . global . multi_threaded . get ( ) {
922
- let ( index, clocks) = self . global . current_thread_state ( ) ;
917
+ if global. multi_threaded . get ( ) {
918
+ let ( index, clocks) = global. current_thread_state ( ) ;
923
919
for ( _, range) in self . alloc_ranges . get_mut ( ) . iter_mut ( pointer. offset , len) {
924
920
if let Err ( DataRace ) = range. write_race_detect ( & * clocks, index, write_type) {
925
921
// Report data-race
926
922
return Self :: report_data_race (
927
- & self . global ,
923
+ global,
928
924
range,
929
925
write_type. get_descriptor ( ) ,
930
926
false ,
@@ -943,16 +939,16 @@ impl VClockAlloc {
943
939
/// data-race threads if `multi-threaded` is false, either due to no threads
944
940
/// being created or if it is temporarily disabled during a racy read or write
945
941
/// operation
946
- pub fn write < ' tcx > ( & mut self , pointer : Pointer < Tag > , len : Size ) -> InterpResult < ' tcx > {
947
- self . unique_access ( pointer, len, WriteType :: Write )
942
+ pub fn write < ' tcx > ( & mut self , pointer : Pointer < Tag > , len : Size , global : & mut GlobalState ) -> InterpResult < ' tcx > {
943
+ self . unique_access ( pointer, len, WriteType :: Write , global )
948
944
}
949
945
950
946
/// Detect data-races for an unsynchronized deallocate operation, will not perform
951
947
/// data-race threads if `multi-threaded` is false, either due to no threads
952
948
/// being created or if it is temporarily disabled during a racy read or write
953
949
/// operation
954
- pub fn deallocate < ' tcx > ( & mut self , pointer : Pointer < Tag > , len : Size ) -> InterpResult < ' tcx > {
955
- self . unique_access ( pointer, len, WriteType :: Deallocate )
950
+ pub fn deallocate < ' tcx > ( & mut self , pointer : Pointer < Tag > , len : Size , global : & mut GlobalState ) -> InterpResult < ' tcx > {
951
+ self . unique_access ( pointer, len, WriteType :: Deallocate , global )
956
952
}
957
953
}
958
954
@@ -1035,15 +1031,14 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
1035
1031
) ;
1036
1032
1037
1033
// Perform the atomic operation.
1038
- let data_race = & alloc_meta. global ;
1039
1034
data_race. maybe_perform_sync_operation ( |index, mut clocks| {
1040
1035
for ( _, range) in
1041
1036
alloc_meta. alloc_ranges . borrow_mut ( ) . iter_mut ( place_ptr. offset , size)
1042
1037
{
1043
1038
if let Err ( DataRace ) = op ( range, & mut * clocks, index, atomic) {
1044
1039
mem:: drop ( clocks) ;
1045
1040
return VClockAlloc :: report_data_race (
1046
- & alloc_meta . global ,
1041
+ data_race ,
1047
1042
range,
1048
1043
description,
1049
1044
true ,
0 commit comments