Skip to content

Commit e54f7a8

Browse files
committed
Add tracing calls to borrow tracker
1 parent e0b41b0 commit e54f7a8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/borrow_tracker/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ impl GlobalStateInner {
260260
kind: MemoryKind,
261261
machine: &MiriMachine<'_>,
262262
) -> AllocState {
263+
let _span = enter_trace_span!(
264+
"borrow_tracker::new_allocation",
265+
"id = {id:?}, size = {alloc_size:?}, kind = {kind:?}"
266+
);
263267
match self.borrow_tracker_method {
264268
BorrowTrackerMethod::StackedBorrows =>
265269
AllocState::StackedBorrows(Box::new(RefCell::new(Stacks::new_allocation(
@@ -280,6 +284,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
280284
kind: RetagKind,
281285
val: &ImmTy<'tcx>,
282286
) -> InterpResult<'tcx, ImmTy<'tcx>> {
287+
let _span = enter_trace_span!(
288+
"borrow_tracker::retag_ptr_value",
289+
"kind = {kind:?}, val.layout = {:?}",
290+
val.layout
291+
);
283292
let this = self.eval_context_mut();
284293
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
285294
match method {
@@ -293,6 +302,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
293302
kind: RetagKind,
294303
place: &PlaceTy<'tcx>,
295304
) -> InterpResult<'tcx> {
305+
let _span = enter_trace_span!(
306+
"borrow_tracker::retag_place_contents",
307+
"kind = {kind:?}, place = {place:?}"
308+
);
296309
let this = self.eval_context_mut();
297310
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
298311
match method {
@@ -302,6 +315,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
302315
}
303316

304317
fn protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
318+
let _span = enter_trace_span!("borrow_tracker::protect_place", "place = {place:?}");
305319
let this = self.eval_context_mut();
306320
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
307321
match method {
@@ -311,6 +325,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
311325
}
312326

313327
fn expose_tag(&self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
328+
let _span = enter_trace_span!(
329+
"borrow_tracker::expose_tag",
330+
"alloc_id = {}, tag = {}",
331+
alloc_id.0,
332+
tag.0
333+
);
314334
let this = self.eval_context_ref();
315335
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
316336
match method {
@@ -354,6 +374,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
354374
&self,
355375
frame: &Frame<'tcx, Provenance, FrameExtra<'tcx>>,
356376
) -> InterpResult<'tcx> {
377+
let _span = enter_trace_span!("borrow_tracker::on_stack_pop");
357378
let this = self.eval_context_ref();
358379
let borrow_tracker = this.machine.borrow_tracker.as_ref().unwrap();
359380
// The body of this loop needs `borrow_tracker` immutably
@@ -431,6 +452,7 @@ impl AllocState {
431452
range: AllocRange,
432453
machine: &MiriMachine<'tcx>,
433454
) -> InterpResult<'tcx> {
455+
let _span = enter_trace_span!("borrow_tracker::before_memory_read");
434456
match self {
435457
AllocState::StackedBorrows(sb) =>
436458
sb.borrow_mut().before_memory_read(alloc_id, prov_extra, range, machine),
@@ -452,6 +474,7 @@ impl AllocState {
452474
range: AllocRange,
453475
machine: &MiriMachine<'tcx>,
454476
) -> InterpResult<'tcx> {
477+
let _span = enter_trace_span!("borrow_tracker::before_memory_write");
455478
match self {
456479
AllocState::StackedBorrows(sb) =>
457480
sb.get_mut().before_memory_write(alloc_id, prov_extra, range, machine),
@@ -473,6 +496,7 @@ impl AllocState {
473496
size: Size,
474497
machine: &MiriMachine<'tcx>,
475498
) -> InterpResult<'tcx> {
499+
let _span = enter_trace_span!("borrow_tracker::before_memory_deallocation");
476500
match self {
477501
AllocState::StackedBorrows(sb) =>
478502
sb.get_mut().before_memory_deallocation(alloc_id, prov_extra, size, machine),
@@ -482,6 +506,7 @@ impl AllocState {
482506
}
483507

484508
pub fn remove_unreachable_tags(&self, tags: &FxHashSet<BorTag>) {
509+
let _span = enter_trace_span!("borrow_tracker::remove_unreachable_tags");
485510
match self {
486511
AllocState::StackedBorrows(sb) => sb.borrow_mut().remove_unreachable_tags(tags),
487512
AllocState::TreeBorrows(tb) => tb.borrow_mut().remove_unreachable_tags(tags),
@@ -496,6 +521,7 @@ impl AllocState {
496521
tag: BorTag,
497522
alloc_id: AllocId, // diagnostics
498523
) -> InterpResult<'tcx> {
524+
let _span = enter_trace_span!("borrow_tracker::release_protector");
499525
match self {
500526
AllocState::StackedBorrows(_sb) => interp_ok(()),
501527
AllocState::TreeBorrows(tb) =>
@@ -506,6 +532,7 @@ impl AllocState {
506532

507533
impl VisitProvenance for AllocState {
508534
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
535+
let _span = enter_trace_span!("borrow_tracker::visit_provenance");
509536
match self {
510537
AllocState::StackedBorrows(sb) => sb.visit_provenance(visit),
511538
AllocState::TreeBorrows(tb) => tb.visit_provenance(visit),

0 commit comments

Comments
 (0)