@@ -55,9 +55,9 @@ impl fmt::Debug for BorTag {
5555 }
5656}
5757
58- /// Per-frame data for borrow tracking
58+ /// Per-call-stack- frame data for borrow tracking
5959#[ derive( Debug ) ]
60- pub struct FrameExtra {
60+ pub struct FrameState {
6161 /// The ID of the call this frame corresponds to.
6262 pub call_id : CallId ,
6363
@@ -72,7 +72,7 @@ pub struct FrameExtra {
7272 pub protected_tags : SmallVec < [ BorTag ; 2 ] > ,
7373}
7474
75- impl VisitTags for FrameExtra {
75+ impl VisitTags for FrameState {
7676 fn visit_tags ( & self , _visit : & mut dyn FnMut ( BorTag ) ) {
7777 // `protected_tags` are fine to GC.
7878 }
@@ -190,17 +190,17 @@ impl GlobalStateInner {
190190 id
191191 }
192192
193- pub fn new_frame ( & mut self , machine : & MiriMachine < ' _ , ' _ > ) -> FrameExtra {
193+ pub fn new_frame ( & mut self , machine : & MiriMachine < ' _ , ' _ > ) -> FrameState {
194194 let call_id = self . next_call_id ;
195195 trace ! ( "new_frame: Assigning call ID {}" , call_id) ;
196196 if self . tracked_call_ids . contains ( & call_id) {
197197 machine. emit_diagnostic ( NonHaltingDiagnostic :: CreatedCallId ( call_id) ) ;
198198 }
199199 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 ( ) }
201201 }
202202
203- pub fn end_call ( & mut self , frame : & machine:: FrameData < ' _ > ) {
203+ pub fn end_call ( & mut self , frame : & machine:: FrameExtra < ' _ > ) {
204204 for tag in & frame
205205 . borrow_tracker
206206 . as_ref ( )
@@ -253,10 +253,10 @@ impl GlobalStateInner {
253253 alloc_size : Size ,
254254 kind : MemoryKind < machine:: MiriMemoryKind > ,
255255 machine : & MiriMachine < ' _ , ' _ > ,
256- ) -> AllocExtra {
256+ ) -> AllocState {
257257 match self . borrow_tracker_method {
258258 BorrowTrackerMethod :: StackedBorrows =>
259- AllocExtra :: StackedBorrows ( Box :: new ( RefCell :: new ( Stacks :: new_allocation (
259+ AllocState :: StackedBorrows ( Box :: new ( RefCell :: new ( Stacks :: new_allocation (
260260 id, alloc_size, self , kind, machine,
261261 ) ) ) ) ,
262262 }
@@ -292,24 +292,30 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
292292
293293/// Extra per-allocation data for borrow tracking
294294#[ derive( Debug , Clone ) ]
295- pub enum AllocExtra {
295+ pub enum AllocState {
296296 /// Data corresponding to Stacked Borrows
297- StackedBorrows ( Box < RefCell < stacked_borrows:: AllocExtra > > ) ,
297+ StackedBorrows ( Box < RefCell < stacked_borrows:: AllocState > > ) ,
298298}
299299
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" ) ,
304306 }
305307 }
306308
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" ) ,
310314 }
311315 }
316+ }
312317
318+ impl AllocState {
313319 pub fn before_memory_read < ' tcx > (
314320 & self ,
315321 alloc_id : AllocId ,
@@ -318,7 +324,7 @@ impl AllocExtra {
318324 machine : & MiriMachine < ' _ , ' tcx > ,
319325 ) -> InterpResult < ' tcx > {
320326 match self {
321- AllocExtra :: StackedBorrows ( sb) =>
327+ AllocState :: StackedBorrows ( sb) =>
322328 sb. borrow_mut ( ) . before_memory_read ( alloc_id, prov_extra, range, machine) ,
323329 }
324330 }
@@ -331,7 +337,7 @@ impl AllocExtra {
331337 machine : & mut MiriMachine < ' _ , ' tcx > ,
332338 ) -> InterpResult < ' tcx > {
333339 match self {
334- AllocExtra :: StackedBorrows ( sb) =>
340+ AllocState :: StackedBorrows ( sb) =>
335341 sb. get_mut ( ) . before_memory_write ( alloc_id, prov_extra, range, machine) ,
336342 }
337343 }
@@ -344,22 +350,22 @@ impl AllocExtra {
344350 machine : & mut MiriMachine < ' _ , ' tcx > ,
345351 ) -> InterpResult < ' tcx > {
346352 match self {
347- AllocExtra :: StackedBorrows ( sb) =>
353+ AllocState :: StackedBorrows ( sb) =>
348354 sb. get_mut ( ) . before_memory_deallocation ( alloc_id, prov_extra, range, machine) ,
349355 }
350356 }
351357
352358 pub fn remove_unreachable_tags ( & self , tags : & FxHashSet < BorTag > ) {
353359 match self {
354- AllocExtra :: StackedBorrows ( sb) => sb. borrow_mut ( ) . remove_unreachable_tags ( tags) ,
360+ AllocState :: StackedBorrows ( sb) => sb. borrow_mut ( ) . remove_unreachable_tags ( tags) ,
355361 }
356362 }
357363}
358364
359- impl VisitTags for AllocExtra {
365+ impl VisitTags for AllocState {
360366 fn visit_tags ( & self , visit : & mut dyn FnMut ( BorTag ) ) {
361367 match self {
362- AllocExtra :: StackedBorrows ( sb) => sb. visit_tags ( visit) ,
368+ AllocState :: StackedBorrows ( sb) => sb. visit_tags ( visit) ,
363369 }
364370 }
365371}
0 commit comments