@@ -286,7 +286,7 @@ impl<'tcx> Stack {
286
286
fn item_popped (
287
287
item : & Item ,
288
288
global : & GlobalStateInner ,
289
- dcx : & mut DiagnosticCx < ' _ , ' _ , ' tcx , ' _ > ,
289
+ dcx : & mut DiagnosticCx < ' _ , ' _ , ' _ , ' _ , ' tcx > ,
290
290
) -> InterpResult < ' tcx > {
291
291
if !global. tracked_pointer_tags . is_empty ( ) {
292
292
dcx. check_tracked_tag_popped ( item, global) ;
@@ -324,7 +324,7 @@ impl<'tcx> Stack {
324
324
access : AccessKind ,
325
325
tag : ProvenanceExtra ,
326
326
global : & mut GlobalStateInner ,
327
- dcx : & mut DiagnosticCx < ' _ , ' _ , ' tcx , ' _ > ,
327
+ dcx : & mut DiagnosticCx < ' _ , ' _ , ' _ , ' _ , ' tcx > ,
328
328
exposed_tags : & FxHashSet < SbTag > ,
329
329
) -> InterpResult < ' tcx > {
330
330
// Two main steps: Find granting item, remove incompatible items above.
@@ -410,7 +410,7 @@ impl<'tcx> Stack {
410
410
& mut self ,
411
411
tag : ProvenanceExtra ,
412
412
global : & GlobalStateInner ,
413
- dcx : & mut DiagnosticCx < ' _ , ' _ , ' tcx , ' _ > ,
413
+ dcx : & mut DiagnosticCx < ' _ , ' _ , ' _ , ' _ , ' tcx > ,
414
414
exposed_tags : & FxHashSet < SbTag > ,
415
415
) -> InterpResult < ' tcx > {
416
416
// Step 1: Make sure there is a granting item.
@@ -436,7 +436,7 @@ impl<'tcx> Stack {
436
436
derived_from : ProvenanceExtra ,
437
437
new : Item ,
438
438
global : & mut GlobalStateInner ,
439
- dcx : & mut DiagnosticCx < ' _ , ' _ , ' tcx , ' _ > ,
439
+ dcx : & mut DiagnosticCx < ' _ , ' _ , ' _ , ' _ , ' tcx > ,
440
440
exposed_tags : & FxHashSet < SbTag > ,
441
441
) -> InterpResult < ' tcx > {
442
442
dcx. start_grant ( new. perm ( ) ) ;
@@ -515,10 +515,10 @@ impl<'tcx> Stacks {
515
515
fn for_each (
516
516
& mut self ,
517
517
range : AllocRange ,
518
- mut dcx_builder : DiagnosticCxBuilder < ' _ , ' _ , ' tcx > ,
518
+ mut dcx_builder : DiagnosticCxBuilder < ' _ , ' _ , ' _ , ' tcx > ,
519
519
mut f : impl FnMut (
520
520
& mut Stack ,
521
- & mut DiagnosticCx < ' _ , ' _ , ' tcx , ' _ > ,
521
+ & mut DiagnosticCx < ' _ , ' _ , ' _ , ' _ , ' tcx > ,
522
522
& mut FxHashSet < SbTag > ,
523
523
) -> InterpResult < ' tcx > ,
524
524
) -> InterpResult < ' tcx > {
@@ -554,63 +554,66 @@ impl Stacks {
554
554
}
555
555
556
556
#[ inline( always) ]
557
- pub fn before_memory_read < ' tcx , ' mir > (
557
+ pub fn before_memory_read < ' tcx , ' mir , ' ecx > (
558
558
& mut self ,
559
559
alloc_id : AllocId ,
560
560
tag : ProvenanceExtra ,
561
561
range : AllocRange ,
562
562
state : & GlobalState ,
563
- current_span : CurrentSpan < ' _ , ' mir , ' tcx > ,
564
- threads : & ThreadManager < ' mir , ' tcx > ,
565
- ) -> InterpResult < ' tcx > {
563
+ mut current_span : CurrentSpan < ' ecx , ' mir , ' tcx > ,
564
+ threads : & ' ecx ThreadManager < ' mir , ' tcx > ,
565
+ ) -> InterpResult < ' tcx >
566
+ where
567
+ ' tcx : ' ecx ,
568
+ {
566
569
trace ! (
567
570
"read access with tag {:?}: {:?}, size {}" ,
568
571
tag,
569
572
Pointer :: new( alloc_id, range. start) ,
570
573
range. size. bytes( )
571
574
) ;
572
- let dcx = DiagnosticCxBuilder :: read ( current_span, threads, tag, range) ;
575
+ let dcx = DiagnosticCxBuilder :: read ( & mut current_span, threads, tag, range) ;
573
576
let mut state = state. borrow_mut ( ) ;
574
577
self . for_each ( range, dcx, |stack, dcx, exposed_tags| {
575
578
stack. access ( AccessKind :: Read , tag, & mut state, dcx, exposed_tags)
576
579
} )
577
580
}
578
581
579
582
#[ inline( always) ]
580
- pub fn before_memory_write < ' tcx , ' mir > (
583
+ pub fn before_memory_write < ' tcx , ' mir , ' ecx > (
581
584
& mut self ,
582
585
alloc_id : AllocId ,
583
586
tag : ProvenanceExtra ,
584
587
range : AllocRange ,
585
588
state : & GlobalState ,
586
- current_span : CurrentSpan < ' _ , ' mir , ' tcx > ,
587
- threads : & ThreadManager < ' mir , ' tcx > ,
589
+ mut current_span : CurrentSpan < ' ecx , ' mir , ' tcx > ,
590
+ threads : & ' ecx ThreadManager < ' mir , ' tcx > ,
588
591
) -> InterpResult < ' tcx > {
589
592
trace ! (
590
593
"write access with tag {:?}: {:?}, size {}" ,
591
594
tag,
592
595
Pointer :: new( alloc_id, range. start) ,
593
596
range. size. bytes( )
594
597
) ;
595
- let dcx = DiagnosticCxBuilder :: write ( current_span, threads, tag, range) ;
598
+ let dcx = DiagnosticCxBuilder :: write ( & mut current_span, threads, tag, range) ;
596
599
let mut state = state. borrow_mut ( ) ;
597
600
self . for_each ( range, dcx, |stack, dcx, exposed_tags| {
598
601
stack. access ( AccessKind :: Write , tag, & mut state, dcx, exposed_tags)
599
602
} )
600
603
}
601
604
602
605
#[ inline( always) ]
603
- pub fn before_memory_deallocation < ' tcx , ' mir > (
606
+ pub fn before_memory_deallocation < ' tcx , ' mir , ' ecx > (
604
607
& mut self ,
605
608
alloc_id : AllocId ,
606
609
tag : ProvenanceExtra ,
607
610
range : AllocRange ,
608
611
state : & GlobalState ,
609
- current_span : CurrentSpan < ' _ , ' mir , ' tcx > ,
610
- threads : & ThreadManager < ' mir , ' tcx > ,
612
+ mut current_span : CurrentSpan < ' ecx , ' mir , ' tcx > ,
613
+ threads : & ' ecx ThreadManager < ' mir , ' tcx > ,
611
614
) -> InterpResult < ' tcx > {
612
615
trace ! ( "deallocation with tag {:?}: {:?}, size {}" , tag, alloc_id, range. size. bytes( ) ) ;
613
- let dcx = DiagnosticCxBuilder :: dealloc ( current_span, threads, tag) ;
616
+ let dcx = DiagnosticCxBuilder :: dealloc ( & mut current_span, threads, tag) ;
614
617
let state = state. borrow ( ) ;
615
618
self . for_each ( range, dcx, |stack, dcx, exposed_tags| {
616
619
stack. dealloc ( tag, & state, dcx, exposed_tags)
@@ -621,8 +624,11 @@ impl Stacks {
621
624
622
625
/// Retagging/reborrowing. There is some policy in here, such as which permissions
623
626
/// to grant for which references, and when to add protectors.
624
- impl < ' mir , ' tcx : ' mir > EvalContextPrivExt < ' mir , ' tcx > for crate :: MiriEvalContext < ' mir , ' tcx > { }
625
- trait EvalContextPrivExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
627
+ impl < ' mir : ' ecx , ' tcx : ' mir , ' ecx > EvalContextPrivExt < ' mir , ' tcx , ' ecx >
628
+ for crate :: MiriEvalContext < ' mir , ' tcx >
629
+ {
630
+ }
631
+ trait EvalContextPrivExt < ' mir : ' ecx , ' tcx : ' mir , ' ecx > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
626
632
/// Returns the `AllocId` the reborrow was done in, if some actual borrow stack manipulation
627
633
/// happened.
628
634
fn reborrow (
@@ -635,11 +641,9 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
635
641
protect : bool ,
636
642
) -> InterpResult < ' tcx , Option < AllocId > > {
637
643
let this = self . eval_context_mut ( ) ;
638
- let current_span = this. machine . current_span ( * this. tcx ) ;
639
644
640
645
// It is crucial that this gets called on all code paths, to ensure we track tag creation.
641
646
let log_creation = |this : & MiriEvalContext < ' mir , ' tcx > ,
642
- current_span : CurrentSpan < ' _ , ' mir , ' tcx > ,
643
647
loc : Option < ( AllocId , Size , ProvenanceExtra ) > | // alloc_id, base_offset, orig_tag
644
648
-> InterpResult < ' tcx > {
645
649
let global = this. machine . stacked_borrows . as_ref ( ) . unwrap ( ) . borrow ( ) ;
@@ -658,6 +662,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
658
662
let ( _size, _align, alloc_kind) = this. get_alloc_info ( alloc_id) ;
659
663
match alloc_kind {
660
664
AllocKind :: LiveData => {
665
+ let current_span = & mut this. machine . current_span ( * this. tcx ) ;
661
666
// This should have alloc_extra data, but `get_alloc_extra` can still fail
662
667
// if converting this alloc_id from a global to a local one
663
668
// uncovers a non-supported `extern static`.
@@ -667,9 +672,12 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
667
672
. as_ref ( )
668
673
. expect ( "we should have Stacked Borrows data" )
669
674
. borrow_mut ( ) ;
670
- let dcx = DiagnosticCxBuilder :: retag (
675
+ let threads = & this. machine . threads ;
676
+ // Note that we create a *second* `DiagnosticCxBuilder` below for the actual retag.
677
+ // FIXME: can this be done cleaner?
678
+ let dcx = DiagnosticCxBuilder :: retag (
671
679
current_span,
672
- & this . machine . threads ,
680
+ threads,
673
681
retag_cause,
674
682
new_tag,
675
683
orig_tag,
@@ -704,16 +712,16 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
704
712
// Dangling slices are a common case here; it's valid to get their length but with raw
705
713
// pointer tagging for example all calls to get_unchecked on them are invalid.
706
714
if let Ok ( ( alloc_id, base_offset, orig_tag) ) = this. ptr_try_get_alloc_id ( place. ptr ) {
707
- log_creation ( this, current_span , Some ( ( alloc_id, base_offset, orig_tag) ) ) ?;
715
+ log_creation ( this, Some ( ( alloc_id, base_offset, orig_tag) ) ) ?;
708
716
return Ok ( Some ( alloc_id) ) ;
709
717
}
710
718
// This pointer doesn't come with an AllocId. :shrug:
711
- log_creation ( this, current_span , None ) ?;
719
+ log_creation ( this, None ) ?;
712
720
return Ok ( None ) ;
713
721
}
714
722
715
723
let ( alloc_id, base_offset, orig_tag) = this. ptr_get_alloc_id ( place. ptr ) ?;
716
- log_creation ( this, current_span , Some ( ( alloc_id, base_offset, orig_tag) ) ) ?;
724
+ log_creation ( this, Some ( ( alloc_id, base_offset, orig_tag) ) ) ?;
717
725
718
726
// Ensure we bail out if the pointer goes out-of-bounds (see miri#1050).
719
727
let ( alloc_size, _) = this. get_live_alloc_size_and_align ( alloc_id) ?;
@@ -770,6 +778,8 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
770
778
. as_ref ( )
771
779
. expect ( "we should have Stacked Borrows data" )
772
780
. borrow_mut ( ) ;
781
+ // FIXME: can't share this with the current_span inside log_creation
782
+ let mut current_span = this. machine . current_span ( * this. tcx ) ;
773
783
this. visit_freeze_sensitive ( place, size, |mut range, frozen| {
774
784
// Adjust range.
775
785
range. start += base_offset;
@@ -789,7 +799,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
789
799
let item = Item :: new ( new_tag, perm, protected) ;
790
800
let mut global = this. machine . stacked_borrows . as_ref ( ) . unwrap ( ) . borrow_mut ( ) ;
791
801
let dcx = DiagnosticCxBuilder :: retag (
792
- this . machine . current_span ( * this . tcx ) ,
802
+ & mut current_span, // FIXME avoid this `clone`
793
803
& this. machine . threads ,
794
804
retag_cause,
795
805
new_tag,
@@ -817,8 +827,10 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
817
827
let item = Item :: new ( new_tag, perm, protect) ;
818
828
let range = alloc_range ( base_offset, size) ;
819
829
let mut global = machine. stacked_borrows . as_ref ( ) . unwrap ( ) . borrow_mut ( ) ;
830
+ // FIXME: can't share this with the current_span inside log_creation
831
+ let current_span = & mut machine. current_span ( tcx) ;
820
832
let dcx = DiagnosticCxBuilder :: retag (
821
- machine . current_span ( tcx ) , // `get_alloc_extra_mut` invalidated our old `current_span`
833
+ current_span,
822
834
& machine. threads ,
823
835
retag_cause,
824
836
new_tag,
0 commit comments