@@ -11,6 +11,7 @@ use rustc_target::abi::Size;
11
11
12
12
use crate :: * ;
13
13
pub mod stacked_borrows;
14
+ pub mod tree_borrows;
14
15
15
16
pub type CallId = NonZeroU64 ;
16
17
@@ -230,8 +231,10 @@ impl GlobalStateInner {
230
231
/// Which borrow tracking method to use
231
232
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
232
233
pub enum BorrowTrackerMethod {
233
- /// Stacked Borrows, as implemented in borrow_tracker/stacked
234
+ /// Stacked Borrows, as implemented in borrow_tracker/stacked_borrows
234
235
StackedBorrows ,
236
+ /// Tree borrows, as implemented in borrow_tracker/tree_borrows
237
+ TreeBorrows ,
235
238
}
236
239
237
240
impl BorrowTrackerMethod {
@@ -258,6 +261,10 @@ impl GlobalStateInner {
258
261
AllocState :: StackedBorrows ( Box :: new ( RefCell :: new ( Stacks :: new_allocation (
259
262
id, alloc_size, self , kind, machine,
260
263
) ) ) ) ,
264
+ BorrowTrackerMethod :: TreeBorrows =>
265
+ AllocState :: TreeBorrows ( Box :: new ( RefCell :: new ( Tree :: new_allocation (
266
+ id, alloc_size, self , kind, machine,
267
+ ) ) ) ) ,
261
268
}
262
269
}
263
270
}
@@ -273,6 +280,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
273
280
let method = this. machine . borrow_tracker . as_ref ( ) . unwrap ( ) . borrow ( ) . borrow_tracker_method ;
274
281
match method {
275
282
BorrowTrackerMethod :: StackedBorrows => this. sb_retag_ptr_value ( kind, val) ,
283
+ BorrowTrackerMethod :: TreeBorrows => this. tb_retag_ptr_value ( kind, val) ,
276
284
}
277
285
}
278
286
@@ -285,6 +293,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
285
293
let method = this. machine . borrow_tracker . as_ref ( ) . unwrap ( ) . borrow ( ) . borrow_tracker_method ;
286
294
match method {
287
295
BorrowTrackerMethod :: StackedBorrows => this. sb_retag_place_contents ( kind, place) ,
296
+ BorrowTrackerMethod :: TreeBorrows => this. tb_retag_place_contents ( kind, place) ,
288
297
}
289
298
}
290
299
@@ -293,6 +302,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
293
302
let method = this. machine . borrow_tracker . as_ref ( ) . unwrap ( ) . borrow ( ) . borrow_tracker_method ;
294
303
match method {
295
304
BorrowTrackerMethod :: StackedBorrows => this. sb_retag_return_place ( ) ,
305
+ BorrowTrackerMethod :: TreeBorrows => this. tb_retag_return_place ( ) ,
296
306
}
297
307
}
298
308
@@ -301,6 +311,34 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
301
311
let method = this. machine . borrow_tracker . as_ref ( ) . unwrap ( ) . borrow ( ) . borrow_tracker_method ;
302
312
match method {
303
313
BorrowTrackerMethod :: StackedBorrows => this. sb_expose_tag ( alloc_id, tag) ,
314
+ BorrowTrackerMethod :: TreeBorrows => this. tb_expose_tag ( alloc_id, tag) ,
315
+ }
316
+ }
317
+
318
+ fn give_pointer_debug_name (
319
+ & mut self ,
320
+ ptr : Pointer < Option < Provenance > > ,
321
+ nth_parent : u8 ,
322
+ name : & str ,
323
+ ) -> InterpResult < ' tcx > {
324
+ let this = self . eval_context_mut ( ) ;
325
+ let method = this. machine . borrow_tracker . as_ref ( ) . unwrap ( ) . borrow ( ) . borrow_tracker_method ;
326
+ match method {
327
+ BorrowTrackerMethod :: StackedBorrows => {
328
+ this. tcx . tcx . sess . warn ( "Stacked Borrows does not support named pointers; `miri_pointer_name` is a no-op" ) ;
329
+ Ok ( ( ) )
330
+ }
331
+ BorrowTrackerMethod :: TreeBorrows =>
332
+ this. tb_give_pointer_debug_name ( ptr, nth_parent, name) ,
333
+ }
334
+ }
335
+
336
+ fn print_borrow_state ( & mut self , alloc_id : AllocId , show_unnamed : bool ) -> InterpResult < ' tcx > {
337
+ let this = self . eval_context_mut ( ) ;
338
+ let method = this. machine . borrow_tracker . as_ref ( ) . unwrap ( ) . borrow ( ) . borrow_tracker_method ;
339
+ match method {
340
+ BorrowTrackerMethod :: StackedBorrows => this. print_stacks ( alloc_id) ,
341
+ BorrowTrackerMethod :: TreeBorrows => this. print_tree ( alloc_id, show_unnamed) ,
304
342
}
305
343
}
306
344
}
@@ -310,6 +348,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
310
348
pub enum AllocState {
311
349
/// Data corresponding to Stacked Borrows
312
350
StackedBorrows ( Box < RefCell < stacked_borrows:: AllocState > > ) ,
351
+ /// Data corresponding to Tree Borrows
352
+ TreeBorrows ( Box < RefCell < tree_borrows:: AllocState > > ) ,
313
353
}
314
354
315
355
impl machine:: AllocExtra {
@@ -328,6 +368,14 @@ impl machine::AllocExtra {
328
368
_ => panic ! ( "expected Stacked Borrows borrow tracking, got something else" ) ,
329
369
}
330
370
}
371
+
372
+ #[ track_caller]
373
+ pub fn borrow_tracker_tb ( & self ) -> & RefCell < tree_borrows:: AllocState > {
374
+ match self . borrow_tracker {
375
+ Some ( AllocState :: TreeBorrows ( ref tb) ) => tb,
376
+ _ => panic ! ( "expected Tree Borrows borrow tracking, got something else" ) ,
377
+ }
378
+ }
331
379
}
332
380
333
381
impl AllocState {
@@ -341,6 +389,14 @@ impl AllocState {
341
389
match self {
342
390
AllocState :: StackedBorrows ( sb) =>
343
391
sb. borrow_mut ( ) . before_memory_read ( alloc_id, prov_extra, range, machine) ,
392
+ AllocState :: TreeBorrows ( tb) =>
393
+ tb. borrow_mut ( ) . before_memory_access (
394
+ AccessKind :: Read ,
395
+ alloc_id,
396
+ prov_extra,
397
+ range,
398
+ machine,
399
+ ) ,
344
400
}
345
401
}
346
402
@@ -354,6 +410,14 @@ impl AllocState {
354
410
match self {
355
411
AllocState :: StackedBorrows ( sb) =>
356
412
sb. get_mut ( ) . before_memory_write ( alloc_id, prov_extra, range, machine) ,
413
+ AllocState :: TreeBorrows ( tb) =>
414
+ tb. get_mut ( ) . before_memory_access (
415
+ AccessKind :: Write ,
416
+ alloc_id,
417
+ prov_extra,
418
+ range,
419
+ machine,
420
+ ) ,
357
421
}
358
422
}
359
423
@@ -367,12 +431,15 @@ impl AllocState {
367
431
match self {
368
432
AllocState :: StackedBorrows ( sb) =>
369
433
sb. get_mut ( ) . before_memory_deallocation ( alloc_id, prov_extra, range, machine) ,
434
+ AllocState :: TreeBorrows ( tb) =>
435
+ tb. get_mut ( ) . before_memory_deallocation ( alloc_id, prov_extra, range, machine) ,
370
436
}
371
437
}
372
438
373
439
pub fn remove_unreachable_tags ( & self , tags : & FxHashSet < BorTag > ) {
374
440
match self {
375
441
AllocState :: StackedBorrows ( sb) => sb. borrow_mut ( ) . remove_unreachable_tags ( tags) ,
442
+ AllocState :: TreeBorrows ( tb) => tb. borrow_mut ( ) . remove_unreachable_tags ( tags) ,
376
443
}
377
444
}
378
445
}
@@ -381,6 +448,7 @@ impl VisitTags for AllocState {
381
448
fn visit_tags ( & self , visit : & mut dyn FnMut ( BorTag ) ) {
382
449
match self {
383
450
AllocState :: StackedBorrows ( sb) => sb. visit_tags ( visit) ,
451
+ AllocState :: TreeBorrows ( tb) => tb. visit_tags ( visit) ,
384
452
}
385
453
}
386
454
}
0 commit comments