@@ -25,6 +25,7 @@ use rustc_middle::{
25
25
} ;
26
26
use rustc_span:: def_id:: { CrateNum , DefId } ;
27
27
use rustc_span:: symbol:: { sym, Symbol } ;
28
+ use rustc_span:: DUMMY_SP ;
28
29
use rustc_target:: abi:: Size ;
29
30
use rustc_target:: spec:: abi:: Abi ;
30
31
@@ -561,6 +562,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
561
562
alloc : Cow < ' b , Allocation > ,
562
563
kind : Option < MemoryKind < Self :: MemoryKind > > ,
563
564
) -> Cow < ' b , Allocation < Self :: PointerTag , Self :: AllocExtra > > {
565
+ set_current_span ( & ecx. machine ) ;
564
566
if ecx. machine . tracked_alloc_ids . contains ( & id) {
565
567
register_diagnostic ( NonHaltingDiagnostic :: CreatedAlloc ( id) ) ;
566
568
}
@@ -589,6 +591,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
589
591
ecx : & MiriEvalContext < ' mir , ' tcx > ,
590
592
ptr : Pointer < AllocId > ,
591
593
) -> Pointer < Tag > {
594
+ set_current_span ( & ecx. machine ) ;
592
595
let absolute_addr = intptrcast:: GlobalStateInner :: rel_ptr_to_addr ( ecx, ptr) ;
593
596
let sb_tag = if let Some ( stacked_borrows) = & ecx. machine . stacked_borrows {
594
597
stacked_borrows. borrow_mut ( ) . base_tag ( ptr. provenance )
@@ -624,6 +627,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
624
627
( alloc_id, tag) : ( AllocId , Self :: TagExtra ) ,
625
628
range : AllocRange ,
626
629
) -> InterpResult < ' tcx > {
630
+ set_current_span ( & machine) ;
627
631
if let Some ( data_race) = & alloc_extra. data_race {
628
632
data_race. read ( alloc_id, range, machine. data_race . as_ref ( ) . unwrap ( ) ) ?;
629
633
}
@@ -632,7 +636,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
632
636
alloc_id,
633
637
tag,
634
638
range,
635
- machine. stacked_borrows . as_ref ( ) . unwrap ( ) ,
639
+ machine. stacked_borrows . as_ref ( ) . unwrap ( ) ,
636
640
)
637
641
} else {
638
642
Ok ( ( ) )
@@ -647,6 +651,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
647
651
( alloc_id, tag) : ( AllocId , Self :: TagExtra ) ,
648
652
range : AllocRange ,
649
653
) -> InterpResult < ' tcx > {
654
+ set_current_span ( & machine) ;
650
655
if let Some ( data_race) = & mut alloc_extra. data_race {
651
656
data_race. write ( alloc_id, range, machine. data_race . as_mut ( ) . unwrap ( ) ) ?;
652
657
}
@@ -670,6 +675,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
670
675
( alloc_id, tag) : ( AllocId , Self :: TagExtra ) ,
671
676
range : AllocRange ,
672
677
) -> InterpResult < ' tcx > {
678
+ set_current_span ( & machine) ;
673
679
if machine. tracked_alloc_ids . contains ( & alloc_id) {
674
680
register_diagnostic ( NonHaltingDiagnostic :: FreedAlloc ( alloc_id) ) ;
675
681
}
@@ -694,7 +700,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
694
700
kind : mir:: RetagKind ,
695
701
place : & PlaceTy < ' tcx , Tag > ,
696
702
) -> InterpResult < ' tcx > {
697
- if ecx. machine . stacked_borrows . is_some ( ) { ecx. retag ( kind, place) } else { Ok ( ( ) ) }
703
+ if ecx. machine . stacked_borrows . is_some ( ) {
704
+ set_current_span ( & ecx. machine ) ;
705
+ ecx. retag ( kind, place)
706
+ } else {
707
+ Ok ( ( ) )
708
+ }
698
709
}
699
710
700
711
#[ inline( always) ]
@@ -740,7 +751,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
740
751
741
752
#[ inline( always) ]
742
753
fn after_stack_push ( ecx : & mut InterpCx < ' mir , ' tcx , Self > ) -> InterpResult < ' tcx > {
743
- if ecx. machine . stacked_borrows . is_some ( ) { ecx. retag_return_place ( ) } else { Ok ( ( ) ) }
754
+ if ecx. machine . stacked_borrows . is_some ( ) {
755
+ set_current_span ( & ecx. machine ) ;
756
+ ecx. retag_return_place ( )
757
+ } else {
758
+ Ok ( ( ) )
759
+ }
744
760
}
745
761
746
762
#[ inline( always) ]
@@ -757,3 +773,29 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
757
773
res
758
774
}
759
775
}
776
+
777
+ // This is potentially a performance hazard.
778
+ // Factoring it into its own function lets us keep an eye on how much it shows up in a profile.
779
+ fn set_current_span < ' mir , ' tcx : ' mir > ( machine : & Evaluator < ' mir , ' tcx > ) {
780
+ if let Some ( sb) = machine. stacked_borrows . as_ref ( ) {
781
+ if sb. borrow ( ) . current_span != DUMMY_SP {
782
+ return ;
783
+ }
784
+ let current_span = machine
785
+ . threads
786
+ . active_thread_stack ( )
787
+ . into_iter ( )
788
+ . rev ( )
789
+ . find ( |frame| {
790
+ let info = FrameInfo {
791
+ instance : frame. instance ,
792
+ span : frame. current_span ( ) ,
793
+ lint_root : None ,
794
+ } ;
795
+ machine. is_local ( & info)
796
+ } )
797
+ . map ( |frame| frame. current_span ( ) )
798
+ . unwrap_or ( rustc_span:: DUMMY_SP ) ;
799
+ sb. borrow_mut ( ) . current_span = current_span;
800
+ }
801
+ }
0 commit comments