@@ -516,6 +516,82 @@ impl<'tcx> Stacks {
516
516
}
517
517
}
518
518
519
+ impl < ' a , ' mir , ' tcx > EvalContextPrivExt < ' a , ' mir , ' tcx > for crate :: MiriEvalContext < ' a , ' mir , ' tcx > { }
520
+ trait EvalContextPrivExt < ' a , ' mir , ' tcx : ' a +' mir > : crate :: MiriEvalContextExt < ' a , ' mir , ' tcx > {
521
+ fn reborrow (
522
+ & mut self ,
523
+ place : MPlaceTy < ' tcx , Borrow > ,
524
+ size : Size ,
525
+ fn_barrier : bool ,
526
+ new_bor : Borrow
527
+ ) -> EvalResult < ' tcx > {
528
+ let this = self . eval_context_mut ( ) ;
529
+ let ptr = place. ptr . to_ptr ( ) ?;
530
+ let barrier = if fn_barrier { Some ( this. frame ( ) . extra ) } else { None } ;
531
+ trace ! ( "reborrow: Creating new reference for {:?} (pointee {}): {:?}" ,
532
+ ptr, place. layout. ty, new_bor) ;
533
+
534
+ // Get the allocation. It might not be mutable, so we cannot use `get_mut`.
535
+ let alloc = this. memory ( ) . get ( ptr. alloc_id ) ?;
536
+ alloc. check_bounds ( this, ptr, size) ?;
537
+ // Update the stacks.
538
+ if let Borrow :: Shr ( Some ( _) ) = new_bor {
539
+ // Reference that cares about freezing. We need a frozen-sensitive reborrow.
540
+ this. visit_freeze_sensitive ( place, size, |cur_ptr, size, frozen| {
541
+ let kind = if frozen { RefKind :: Frozen } else { RefKind :: Raw } ;
542
+ alloc. extra . reborrow ( cur_ptr, size, barrier, new_bor, kind)
543
+ } ) ?;
544
+ } else {
545
+ // Just treat this as one big chunk.
546
+ let kind = if new_bor. is_unique ( ) { RefKind :: Unique } else { RefKind :: Raw } ;
547
+ alloc. extra . reborrow ( ptr, size, barrier, new_bor, kind) ?;
548
+ }
549
+ Ok ( ( ) )
550
+ }
551
+
552
+ /// Retag an indidual pointer, returning the retagged version.
553
+ fn retag_reference (
554
+ & mut self ,
555
+ val : ImmTy < ' tcx , Borrow > ,
556
+ mutbl : Mutability ,
557
+ fn_barrier : bool ,
558
+ two_phase : bool ,
559
+ ) -> EvalResult < ' tcx , Immediate < Borrow > > {
560
+ let this = self . eval_context_mut ( ) ;
561
+ // We want a place for where the ptr *points to*, so we get one.
562
+ let place = this. ref_to_mplace ( val) ?;
563
+ let size = this. size_and_align_of_mplace ( place) ?
564
+ . map ( |( size, _) | size)
565
+ . unwrap_or_else ( || place. layout . size ) ;
566
+ if size == Size :: ZERO {
567
+ // Nothing to do for ZSTs.
568
+ return Ok ( * val) ;
569
+ }
570
+
571
+ // Compute new borrow.
572
+ let time = this. machine . stacked_borrows . increment_clock ( ) ;
573
+ let new_bor = match mutbl {
574
+ MutMutable => Borrow :: Uniq ( time) ,
575
+ MutImmutable => Borrow :: Shr ( Some ( time) ) ,
576
+ } ;
577
+
578
+ // Reborrow.
579
+ this. reborrow ( place, size, fn_barrier, new_bor) ?;
580
+ let new_place = place. with_tag ( new_bor) ;
581
+ // Handle two-phase borrows.
582
+ if two_phase {
583
+ assert ! ( mutbl == MutMutable , "two-phase shared borrows make no sense" ) ;
584
+ // We immediately share it, to allow read accesses
585
+ let two_phase_time = this. machine . stacked_borrows . increment_clock ( ) ;
586
+ let two_phase_bor = Borrow :: Shr ( Some ( two_phase_time) ) ;
587
+ this. reborrow ( new_place, size, /*fn_barrier*/ false , two_phase_bor) ?;
588
+ }
589
+
590
+ // Return new ptr.
591
+ Ok ( new_place. to_ref ( ) )
592
+ }
593
+ }
594
+
519
595
impl < ' a , ' mir , ' tcx > EvalContextExt < ' a , ' mir , ' tcx > for crate :: MiriEvalContext < ' a , ' mir , ' tcx > { }
520
596
pub trait EvalContextExt < ' a , ' mir , ' tcx : ' a +' mir > : crate :: MiriEvalContextExt < ' a , ' mir , ' tcx > {
521
597
fn tag_new_allocation (
@@ -601,79 +677,6 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
601
677
Ok ( ( ) )
602
678
}
603
679
604
- fn reborrow (
605
- & mut self ,
606
- place : MPlaceTy < ' tcx , Borrow > ,
607
- size : Size ,
608
- fn_barrier : bool ,
609
- new_bor : Borrow
610
- ) -> EvalResult < ' tcx > {
611
- let this = self . eval_context_mut ( ) ;
612
- let ptr = place. ptr . to_ptr ( ) ?;
613
- let barrier = if fn_barrier { Some ( this. frame ( ) . extra ) } else { None } ;
614
- trace ! ( "reborrow: Creating new reference for {:?} (pointee {}): {:?}" ,
615
- ptr, place. layout. ty, new_bor) ;
616
-
617
- // Get the allocation. It might not be mutable, so we cannot use `get_mut`.
618
- let alloc = this. memory ( ) . get ( ptr. alloc_id ) ?;
619
- alloc. check_bounds ( this, ptr, size) ?;
620
- // Update the stacks.
621
- if let Borrow :: Shr ( Some ( _) ) = new_bor {
622
- // Reference that cares about freezing. We need a frozen-sensitive reborrow.
623
- this. visit_freeze_sensitive ( place, size, |cur_ptr, size, frozen| {
624
- let kind = if frozen { RefKind :: Frozen } else { RefKind :: Raw } ;
625
- alloc. extra . reborrow ( cur_ptr, size, barrier, new_bor, kind)
626
- } ) ?;
627
- } else {
628
- // Just treat this as one big chunk.
629
- let kind = if new_bor. is_unique ( ) { RefKind :: Unique } else { RefKind :: Raw } ;
630
- alloc. extra . reborrow ( ptr, size, barrier, new_bor, kind) ?;
631
- }
632
- Ok ( ( ) )
633
- }
634
-
635
- /// Retag an indidual pointer, returning the retagged version.
636
- fn retag_reference (
637
- & mut self ,
638
- val : ImmTy < ' tcx , Borrow > ,
639
- mutbl : Mutability ,
640
- fn_barrier : bool ,
641
- two_phase : bool ,
642
- ) -> EvalResult < ' tcx , Immediate < Borrow > > {
643
- let this = self . eval_context_mut ( ) ;
644
- // We want a place for where the ptr *points to*, so we get one.
645
- let place = this. ref_to_mplace ( val) ?;
646
- let size = this. size_and_align_of_mplace ( place) ?
647
- . map ( |( size, _) | size)
648
- . unwrap_or_else ( || place. layout . size ) ;
649
- if size == Size :: ZERO {
650
- // Nothing to do for ZSTs.
651
- return Ok ( * val) ;
652
- }
653
-
654
- // Compute new borrow.
655
- let time = this. machine . stacked_borrows . increment_clock ( ) ;
656
- let new_bor = match mutbl {
657
- MutMutable => Borrow :: Uniq ( time) ,
658
- MutImmutable => Borrow :: Shr ( Some ( time) ) ,
659
- } ;
660
-
661
- // Reborrow.
662
- this. reborrow ( place, size, fn_barrier, new_bor) ?;
663
- let new_place = place. with_tag ( new_bor) ;
664
- // Handle two-phase borrows.
665
- if two_phase {
666
- assert ! ( mutbl == MutMutable , "two-phase shared borrows make no sense" ) ;
667
- // We immediately share it, to allow read accesses
668
- let two_phase_time = this. machine . stacked_borrows . increment_clock ( ) ;
669
- let two_phase_bor = Borrow :: Shr ( Some ( two_phase_time) ) ;
670
- this. reborrow ( new_place, size, /*fn_barrier*/ false , two_phase_bor) ?;
671
- }
672
-
673
- // Return new ptr.
674
- Ok ( new_place. to_ref ( ) )
675
- }
676
-
677
680
fn retag (
678
681
& mut self ,
679
682
fn_entry : bool ,
0 commit comments