@@ -55,9 +55,9 @@ impl fmt::Debug for BorTag {
55
55
}
56
56
}
57
57
58
- /// Per-frame data for borrow tracking
58
+ /// Per-call-stack- frame data for borrow tracking
59
59
#[ derive( Debug ) ]
60
- pub struct FrameExtra {
60
+ pub struct FrameState {
61
61
/// The ID of the call this frame corresponds to.
62
62
pub call_id : CallId ,
63
63
@@ -72,7 +72,7 @@ pub struct FrameExtra {
72
72
pub protected_tags : SmallVec < [ BorTag ; 2 ] > ,
73
73
}
74
74
75
- impl VisitTags for FrameExtra {
75
+ impl VisitTags for FrameState {
76
76
fn visit_tags ( & self , _visit : & mut dyn FnMut ( BorTag ) ) {
77
77
// `protected_tags` are fine to GC.
78
78
}
@@ -190,17 +190,17 @@ impl GlobalStateInner {
190
190
id
191
191
}
192
192
193
- pub fn new_frame ( & mut self , machine : & MiriMachine < ' _ , ' _ > ) -> FrameExtra {
193
+ pub fn new_frame ( & mut self , machine : & MiriMachine < ' _ , ' _ > ) -> FrameState {
194
194
let call_id = self . next_call_id ;
195
195
trace ! ( "new_frame: Assigning call ID {}" , call_id) ;
196
196
if self . tracked_call_ids . contains ( & call_id) {
197
197
machine. emit_diagnostic ( NonHaltingDiagnostic :: CreatedCallId ( call_id) ) ;
198
198
}
199
199
self . next_call_id = NonZeroU64 :: new ( call_id. get ( ) + 1 ) . unwrap ( ) ;
200
- FrameExtra { call_id, protected_tags : SmallVec :: new ( ) }
200
+ FrameState { call_id, protected_tags : SmallVec :: new ( ) }
201
201
}
202
202
203
- pub fn end_call ( & mut self , frame : & machine:: FrameData < ' _ > ) {
203
+ pub fn end_call ( & mut self , frame : & machine:: FrameExtra < ' _ > ) {
204
204
for tag in & frame
205
205
. borrow_tracker
206
206
. as_ref ( )
@@ -253,10 +253,10 @@ impl GlobalStateInner {
253
253
alloc_size : Size ,
254
254
kind : MemoryKind < machine:: MiriMemoryKind > ,
255
255
machine : & MiriMachine < ' _ , ' _ > ,
256
- ) -> AllocExtra {
256
+ ) -> AllocState {
257
257
match self . borrow_tracker_method {
258
258
BorrowTrackerMethod :: StackedBorrows =>
259
- AllocExtra :: StackedBorrows ( Box :: new ( RefCell :: new ( Stacks :: new_allocation (
259
+ AllocState :: StackedBorrows ( Box :: new ( RefCell :: new ( Stacks :: new_allocation (
260
260
id, alloc_size, self , kind, machine,
261
261
) ) ) ) ,
262
262
}
@@ -292,24 +292,30 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
292
292
293
293
/// Extra per-allocation data for borrow tracking
294
294
#[ derive( Debug , Clone ) ]
295
- pub enum AllocExtra {
295
+ pub enum AllocState {
296
296
/// Data corresponding to Stacked Borrows
297
- StackedBorrows ( Box < RefCell < stacked_borrows:: AllocExtra > > ) ,
297
+ StackedBorrows ( Box < RefCell < stacked_borrows:: AllocState > > ) ,
298
298
}
299
299
300
- impl AllocExtra {
301
- pub fn assert_sb ( & self ) -> & RefCell < stacked_borrows:: AllocExtra > {
302
- match self {
303
- AllocExtra :: StackedBorrows ( ref sb) => sb,
300
+ impl machine:: AllocExtra {
301
+ #[ track_caller]
302
+ pub fn borrow_tracker_sb ( & self ) -> & RefCell < stacked_borrows:: AllocState > {
303
+ match self . borrow_tracker {
304
+ Some ( AllocState :: StackedBorrows ( ref sb) ) => sb,
305
+ _ => panic ! ( "expected Stacked Borrows borrow tracking, got something else" ) ,
304
306
}
305
307
}
306
308
307
- pub fn assert_sb_mut ( & mut self ) -> & mut RefCell < stacked_borrows:: AllocExtra > {
308
- match self {
309
- AllocExtra :: StackedBorrows ( ref mut sb) => sb,
309
+ #[ track_caller]
310
+ pub fn borrow_tracker_sb_mut ( & mut self ) -> & mut RefCell < stacked_borrows:: AllocState > {
311
+ match self . borrow_tracker {
312
+ Some ( AllocState :: StackedBorrows ( ref mut sb) ) => sb,
313
+ _ => panic ! ( "expected Stacked Borrows borrow tracking, got something else" ) ,
310
314
}
311
315
}
316
+ }
312
317
318
+ impl AllocState {
313
319
pub fn before_memory_read < ' tcx > (
314
320
& self ,
315
321
alloc_id : AllocId ,
@@ -318,7 +324,7 @@ impl AllocExtra {
318
324
machine : & MiriMachine < ' _ , ' tcx > ,
319
325
) -> InterpResult < ' tcx > {
320
326
match self {
321
- AllocExtra :: StackedBorrows ( sb) =>
327
+ AllocState :: StackedBorrows ( sb) =>
322
328
sb. borrow_mut ( ) . before_memory_read ( alloc_id, prov_extra, range, machine) ,
323
329
}
324
330
}
@@ -331,7 +337,7 @@ impl AllocExtra {
331
337
machine : & mut MiriMachine < ' _ , ' tcx > ,
332
338
) -> InterpResult < ' tcx > {
333
339
match self {
334
- AllocExtra :: StackedBorrows ( sb) =>
340
+ AllocState :: StackedBorrows ( sb) =>
335
341
sb. get_mut ( ) . before_memory_write ( alloc_id, prov_extra, range, machine) ,
336
342
}
337
343
}
@@ -344,22 +350,22 @@ impl AllocExtra {
344
350
machine : & mut MiriMachine < ' _ , ' tcx > ,
345
351
) -> InterpResult < ' tcx > {
346
352
match self {
347
- AllocExtra :: StackedBorrows ( sb) =>
353
+ AllocState :: StackedBorrows ( sb) =>
348
354
sb. get_mut ( ) . before_memory_deallocation ( alloc_id, prov_extra, range, machine) ,
349
355
}
350
356
}
351
357
352
358
pub fn remove_unreachable_tags ( & self , tags : & FxHashSet < BorTag > ) {
353
359
match self {
354
- AllocExtra :: StackedBorrows ( sb) => sb. borrow_mut ( ) . remove_unreachable_tags ( tags) ,
360
+ AllocState :: StackedBorrows ( sb) => sb. borrow_mut ( ) . remove_unreachable_tags ( tags) ,
355
361
}
356
362
}
357
363
}
358
364
359
- impl VisitTags for AllocExtra {
365
+ impl VisitTags for AllocState {
360
366
fn visit_tags ( & self , visit : & mut dyn FnMut ( BorTag ) ) {
361
367
match self {
362
- AllocExtra :: StackedBorrows ( sb) => sb. visit_tags ( visit) ,
368
+ AllocState :: StackedBorrows ( sb) => sb. visit_tags ( visit) ,
363
369
}
364
370
}
365
371
}
0 commit comments