@@ -39,7 +39,7 @@ pub const STACK_SIZE: u64 = 16 * PAGE_SIZE; // whatever
39
39
/// Extra data stored with each stack frame
40
40
pub struct FrameData < ' tcx > {
41
41
/// Extra data for Stacked Borrows.
42
- pub stacked_borrows : Option < stacked_borrows :: FrameExtra > ,
42
+ pub borrow_tracker : Option < borrow_tracker :: FrameExtra > ,
43
43
44
44
/// If this is Some(), then this is a special "catch unwind" frame (the frame of `try_fn`
45
45
/// called by `try`). When this frame is popped during unwinding a panic,
@@ -61,20 +61,20 @@ pub struct FrameData<'tcx> {
61
61
impl < ' tcx > std:: fmt:: Debug for FrameData < ' tcx > {
62
62
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
63
63
// Omitting `timing`, it does not support `Debug`.
64
- let FrameData { stacked_borrows , catch_unwind, timing : _, is_user_relevant : _ } = self ;
64
+ let FrameData { borrow_tracker , catch_unwind, timing : _, is_user_relevant : _ } = self ;
65
65
f. debug_struct ( "FrameData" )
66
- . field ( "stacked_borrows " , stacked_borrows )
66
+ . field ( "borrow_tracker " , borrow_tracker )
67
67
. field ( "catch_unwind" , catch_unwind)
68
68
. finish ( )
69
69
}
70
70
}
71
71
72
72
impl VisitTags for FrameData < ' _ > {
73
- fn visit_tags ( & self , visit : & mut dyn FnMut ( SbTag ) ) {
74
- let FrameData { catch_unwind, stacked_borrows , timing : _, is_user_relevant : _ } = self ;
73
+ fn visit_tags ( & self , visit : & mut dyn FnMut ( BorTag ) ) {
74
+ let FrameData { catch_unwind, borrow_tracker , timing : _, is_user_relevant : _ } = self ;
75
75
76
76
catch_unwind. visit_tags ( visit) ;
77
- stacked_borrows . visit_tags ( visit) ;
77
+ borrow_tracker . visit_tags ( visit) ;
78
78
}
79
79
}
80
80
@@ -254,8 +254,8 @@ impl ProvenanceExtra {
254
254
/// Extra per-allocation data
255
255
#[ derive( Debug , Clone ) ]
256
256
pub struct AllocExtra {
257
- /// Stacked Borrows state is only added if it is enabled.
258
- pub stacked_borrows : Option < stacked_borrows :: AllocExtra > ,
257
+ /// Global state of the borrow tracker, if enabled.
258
+ pub borrow_tracker : Option < borrow_tracker :: AllocExtra > ,
259
259
/// Data race detection via the use of a vector-clock,
260
260
/// this is only added if it is enabled.
261
261
pub data_race : Option < data_race:: AllocExtra > ,
@@ -265,10 +265,10 @@ pub struct AllocExtra {
265
265
}
266
266
267
267
impl VisitTags for AllocExtra {
268
- fn visit_tags ( & self , visit : & mut dyn FnMut ( SbTag ) ) {
269
- let AllocExtra { stacked_borrows , data_race, weak_memory } = self ;
268
+ fn visit_tags ( & self , visit : & mut dyn FnMut ( BorTag ) ) {
269
+ let AllocExtra { borrow_tracker , data_race, weak_memory } = self ;
270
270
271
- stacked_borrows . visit_tags ( visit) ;
271
+ borrow_tracker . visit_tags ( visit) ;
272
272
data_race. visit_tags ( visit) ;
273
273
weak_memory. visit_tags ( visit) ;
274
274
}
@@ -350,8 +350,8 @@ pub struct MiriMachine<'mir, 'tcx> {
350
350
// We carry a copy of the global `TyCtxt` for convenience, so methods taking just `&Evaluator` have `tcx` access.
351
351
pub tcx : TyCtxt < ' tcx > ,
352
352
353
- /// Stacked Borrows global data .
354
- pub stacked_borrows : Option < stacked_borrows :: GlobalState > ,
353
+ /// Global data for borrow tracking .
354
+ pub borrow_tracker : Option < borrow_tracker :: GlobalState > ,
355
355
356
356
/// Data race detector global data.
357
357
pub data_race : Option < data_race:: GlobalState > ,
@@ -480,17 +480,11 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
480
480
measureme:: Profiler :: new ( out) . expect ( "Couldn't create `measureme` profiler" )
481
481
} ) ;
482
482
let rng = StdRng :: seed_from_u64 ( config. seed . unwrap_or ( 0 ) ) ;
483
- let stacked_borrows = config. stacked_borrows . then ( || {
484
- RefCell :: new ( stacked_borrows:: GlobalStateInner :: new (
485
- config. tracked_pointer_tags . clone ( ) ,
486
- config. tracked_call_ids . clone ( ) ,
487
- config. retag_fields ,
488
- ) )
489
- } ) ;
483
+ let borrow_tracker = config. borrow_tracker . map ( |bt| bt. instanciate_global_state ( config) ) ;
490
484
let data_race = config. data_race_detector . then ( || data_race:: GlobalState :: new ( config) ) ;
491
485
MiriMachine {
492
486
tcx : layout_cx. tcx ,
493
- stacked_borrows ,
487
+ borrow_tracker ,
494
488
data_race,
495
489
intptrcast : RefCell :: new ( intptrcast:: GlobalStateInner :: new ( config) ) ,
496
490
// `env_vars` depends on a full interpreter so we cannot properly initialize it yet.
@@ -668,7 +662,7 @@ impl VisitTags for MiriMachine<'_, '_> {
668
662
cmd_line,
669
663
extern_statics,
670
664
dir_handler,
671
- stacked_borrows ,
665
+ borrow_tracker ,
672
666
data_race,
673
667
intptrcast,
674
668
file_handler,
@@ -706,7 +700,7 @@ impl VisitTags for MiriMachine<'_, '_> {
706
700
dir_handler. visit_tags ( visit) ;
707
701
file_handler. visit_tags ( visit) ;
708
702
data_race. visit_tags ( visit) ;
709
- stacked_borrows . visit_tags ( visit) ;
703
+ borrow_tracker . visit_tags ( visit) ;
710
704
intptrcast. visit_tags ( visit) ;
711
705
main_fn_ret_place. visit_tags ( visit) ;
712
706
argc. visit_tags ( visit) ;
@@ -907,15 +901,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
907
901
}
908
902
909
903
let alloc = alloc. into_owned ( ) ;
910
- let stacks = ecx. machine . stacked_borrows . as_ref ( ) . map ( |stacked_borrows| {
911
- stacked_borrows:: Stacks :: new_allocation (
912
- id,
913
- alloc. size ( ) ,
914
- stacked_borrows,
915
- kind,
916
- & ecx. machine ,
917
- )
918
- } ) ;
904
+ let borrow_tracker = ecx
905
+ . machine
906
+ . borrow_tracker
907
+ . as_ref ( )
908
+ . map ( |bt| bt. borrow_mut ( ) . new_allocation ( id, alloc. size ( ) , kind, & ecx. machine ) ) ;
909
+
919
910
let race_alloc = ecx. machine . data_race . as_ref ( ) . map ( |data_race| {
920
911
data_race:: AllocExtra :: new_allocation (
921
912
data_race,
@@ -927,11 +918,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
927
918
let buffer_alloc = ecx. machine . weak_memory . then ( weak_memory:: AllocExtra :: new_allocation) ;
928
919
let alloc: Allocation < Provenance , Self :: AllocExtra > = alloc. adjust_from_tcx (
929
920
& ecx. tcx ,
930
- AllocExtra {
931
- stacked_borrows : stacks. map ( RefCell :: new) ,
932
- data_race : race_alloc,
933
- weak_memory : buffer_alloc,
934
- } ,
921
+ AllocExtra { borrow_tracker, data_race : race_alloc, weak_memory : buffer_alloc } ,
935
922
|ptr| ecx. global_base_pointer ( ptr) ,
936
923
) ?;
937
924
Ok ( Cow :: Owned ( alloc) )
@@ -955,8 +942,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
955
942
}
956
943
}
957
944
let absolute_addr = intptrcast:: GlobalStateInner :: rel_ptr_to_addr ( ecx, ptr) ;
958
- let sb_tag = if let Some ( stacked_borrows ) = & ecx. machine . stacked_borrows {
959
- stacked_borrows . borrow_mut ( ) . base_ptr_tag ( ptr. provenance , & ecx. machine )
945
+ let tag = if let Some ( borrow_tracker ) = & ecx. machine . borrow_tracker {
946
+ borrow_tracker . borrow_mut ( ) . base_ptr_tag ( ptr. provenance , & ecx. machine )
960
947
} else {
961
948
// Value does not matter, SB is disabled
962
949
BorTag :: default ( )
@@ -1018,10 +1005,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1018
1005
if let Some ( data_race) = & alloc_extra. data_race {
1019
1006
data_race. read ( alloc_id, range, machine) ?;
1020
1007
}
1021
- if let Some ( stacked_borrows) = & alloc_extra. stacked_borrows {
1022
- stacked_borrows
1023
- . borrow_mut ( )
1024
- . before_memory_read ( alloc_id, prov_extra, range, machine) ?;
1008
+ if let Some ( borrow_tracker) = & alloc_extra. borrow_tracker {
1009
+ borrow_tracker. before_memory_read ( alloc_id, prov_extra, range, machine) ?;
1025
1010
}
1026
1011
if let Some ( weak_memory) = & alloc_extra. weak_memory {
1027
1012
weak_memory. memory_accessed ( range, machine. data_race . as_ref ( ) . unwrap ( ) ) ;
@@ -1040,8 +1025,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1040
1025
if let Some ( data_race) = & mut alloc_extra. data_race {
1041
1026
data_race. write ( alloc_id, range, machine) ?;
1042
1027
}
1043
- if let Some ( stacked_borrows ) = & mut alloc_extra. stacked_borrows {
1044
- stacked_borrows . get_mut ( ) . before_memory_write ( alloc_id, prov_extra, range, machine) ?;
1028
+ if let Some ( borrow_tracker ) = & mut alloc_extra. borrow_tracker {
1029
+ borrow_tracker . before_memory_write ( alloc_id, prov_extra, range, machine) ?;
1045
1030
}
1046
1031
if let Some ( weak_memory) = & alloc_extra. weak_memory {
1047
1032
weak_memory. memory_accessed ( range, machine. data_race . as_ref ( ) . unwrap ( ) ) ;
@@ -1063,16 +1048,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1063
1048
if let Some ( data_race) = & mut alloc_extra. data_race {
1064
1049
data_race. deallocate ( alloc_id, range, machine) ?;
1065
1050
}
1066
- if let Some ( stacked_borrows) = & mut alloc_extra. stacked_borrows {
1067
- stacked_borrows. get_mut ( ) . before_memory_deallocation (
1068
- alloc_id,
1069
- prove_extra,
1070
- range,
1071
- machine,
1072
- )
1073
- } else {
1074
- Ok ( ( ) )
1051
+ if let Some ( borrow_tracker) = & mut alloc_extra. borrow_tracker {
1052
+ borrow_tracker. before_memory_deallocation ( alloc_id, prove_extra, range, machine) ?;
1075
1053
}
1054
+ Ok ( ( ) )
1076
1055
}
1077
1056
1078
1057
#[ inline( always) ]
@@ -1081,7 +1060,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1081
1060
kind : mir:: RetagKind ,
1082
1061
place : & PlaceTy < ' tcx , Provenance > ,
1083
1062
) -> InterpResult < ' tcx > {
1084
- if ecx. machine . stacked_borrows . is_some ( ) { ecx. retag ( kind, place) } else { Ok ( ( ) ) }
1063
+ if ecx. machine . borrow_tracker . is_some ( ) {
1064
+ ecx. retag ( kind, place) ?;
1065
+ }
1066
+ Ok ( ( ) )
1085
1067
}
1086
1068
1087
1069
#[ inline( always) ]
@@ -1104,10 +1086,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1104
1086
None
1105
1087
} ;
1106
1088
1107
- let stacked_borrows = ecx. machine . stacked_borrows . as_ref ( ) ;
1089
+ let borrow_tracker = ecx. machine . borrow_tracker . as_ref ( ) ;
1108
1090
1109
1091
let extra = FrameData {
1110
- stacked_borrows : stacked_borrows . map ( |sb| sb . borrow_mut ( ) . new_frame ( & ecx. machine ) ) ,
1092
+ borrow_tracker : borrow_tracker . map ( |bt| bt . borrow_mut ( ) . new_frame ( & ecx. machine ) ) ,
1111
1093
catch_unwind : None ,
1112
1094
timing,
1113
1095
is_user_relevant : ecx. machine . is_user_relevant ( & frame) ,
@@ -1140,7 +1122,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1140
1122
}
1141
1123
}
1142
1124
1143
- // Search for SbTags to find all live pointers, then remove all other tags from borrow
1125
+ // Search for BorTags to find all live pointers, then remove all other tags from borrow
1144
1126
// stacks.
1145
1127
// When debug assertions are enabled, run the GC as often as possible so that any cases
1146
1128
// where it mistakenly removes an important tag become visible.
@@ -1166,8 +1148,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1166
1148
let stack_len = ecx. active_thread_stack ( ) . len ( ) ;
1167
1149
ecx. active_thread_mut ( ) . set_top_user_relevant_frame ( stack_len - 1 ) ;
1168
1150
}
1169
-
1170
- if ecx. machine . stacked_borrows . is_some ( ) { ecx. retag_return_place ( ) } else { Ok ( ( ) ) }
1151
+ if ecx. machine . borrow_tracker . is_some ( ) {
1152
+ ecx. retag_return_place ( ) ?;
1153
+ }
1154
+ Ok ( ( ) )
1171
1155
}
1172
1156
1173
1157
#[ inline( always) ]
@@ -1184,8 +1168,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
1184
1168
ecx. active_thread_mut ( ) . recompute_top_user_relevant_frame ( ) ;
1185
1169
}
1186
1170
let timing = frame. extra . timing . take ( ) ;
1187
- if let Some ( stacked_borrows ) = & ecx. machine . stacked_borrows {
1188
- stacked_borrows . borrow_mut ( ) . end_call ( & frame. extra ) ;
1171
+ if let Some ( borrow_tracker ) = & ecx. machine . borrow_tracker {
1172
+ borrow_tracker . borrow_mut ( ) . end_call ( & frame. extra ) ;
1189
1173
}
1190
1174
let res = ecx. handle_stack_pop_unwind ( frame. extra , unwinding) ;
1191
1175
if let Some ( profiler) = ecx. machine . profiler . as_ref ( ) {
0 commit comments