@@ -67,8 +67,8 @@ use rustc_middle::mir::*;
67
67
use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt } ;
68
68
use rustc_middle:: ty:: { GeneratorSubsts , SubstsRef } ;
69
69
use rustc_mir_dataflow:: impls:: {
70
- get_borrowed_locals_results, MaybeBorrowedLocals , MaybeLiveLocals , MaybeRequiresStorage ,
71
- MaybeStorageLive ,
70
+ get_borrowed_locals_results, BorrowedLocalsResultsCursor , MaybeLiveLocals ,
71
+ MaybeRequiresStorage , MaybeStorageLive ,
72
72
} ;
73
73
use rustc_mir_dataflow:: storage:: always_storage_live_locals;
74
74
use rustc_mir_dataflow:: { self , Analysis } ;
@@ -593,22 +593,18 @@ fn locals_live_across_suspend_points<'tcx>(
593
593
. iterate_to_fixpoint ( )
594
594
. into_results_cursor ( body_ref) ;
595
595
596
- // Calculate the MIR locals which have been previously
597
- // borrowed (even if they are still active).
598
- let borrowed_locals_results =
599
- MaybeBorrowedLocals . into_engine ( tcx, body_ref) . pass_name ( "generator" ) . iterate_to_fixpoint ( ) ;
600
-
601
- let mut borrowed_locals_cursor = borrowed_locals_results. cloned_results_cursor ( body_ref) ;
602
-
603
- let mut live_borrows_cursor = get_borrowed_locals_results ( body, tcx) ;
596
+ // Calculate the locals that are live due to outstanding references or pointers.
597
+ let live_borrows_results = get_borrowed_locals_results ( body_ref, tcx) ;
598
+ let mut live_borrows_cursor = BorrowedLocalsResultsCursor :: new ( body_ref, & live_borrows_results) ;
604
599
605
600
// Calculate the MIR locals that we actually need to keep storage around
606
601
// for.
607
- let mut requires_storage_results =
608
- MaybeRequiresStorage :: new ( borrowed_locals_results. cloned_results_cursor ( body) )
609
- . into_engine ( tcx, body_ref)
610
- . iterate_to_fixpoint ( ) ;
611
- let mut requires_storage_cursor = requires_storage_results. as_results_cursor ( body_ref) ;
602
+ let requires_storage_results = MaybeRequiresStorage :: new ( body, & live_borrows_results)
603
+ . into_engine ( tcx, body_ref)
604
+ . iterate_to_fixpoint ( ) ;
605
+
606
+ let mut requires_storage_cursor =
607
+ rustc_mir_dataflow:: ResultsCursor :: new ( body_ref, & requires_storage_results) ;
612
608
613
609
// Calculate the liveness of MIR locals ignoring borrows.
614
610
let mut liveness = MaybeLiveLocals
@@ -623,21 +619,9 @@ fn locals_live_across_suspend_points<'tcx>(
623
619
let mut live_locals_at_any_suspension_point = BitSet :: new_empty ( body. local_decls . len ( ) ) ;
624
620
625
621
for ( block, data) in body. basic_blocks . iter_enumerated ( ) {
626
- for ( i, stmt) in data. statements . iter ( ) . enumerate ( ) {
627
- debug ! ( ?stmt) ;
628
- let loc = Location { block, statement_index : i } ;
629
- debug ! ( "live_borrows_cursor seek before" ) ;
630
- live_borrows_cursor. seek_before_primary_effect ( loc) ;
631
- debug ! ( "finished seek before" ) ;
632
- let live_borrowed_locals = live_borrows_cursor. get ( ) ;
633
- debug ! ( ?live_borrowed_locals) ;
634
- }
635
-
636
622
debug ! ( ?block, ?data. terminator) ;
637
623
if let TerminatorKind :: Yield { .. } = data. terminator ( ) . kind {
638
624
let loc = Location { block, statement_index : data. statements . len ( ) } ;
639
- debug ! ( "encountered Yield at loc {:?}" , loc) ;
640
-
641
625
liveness. seek_to_block_end ( block) ;
642
626
let mut live_locals: BitSet < _ > = BitSet :: new_empty ( body. local_decls . len ( ) ) ;
643
627
live_locals. union ( liveness. get ( ) ) ;
@@ -653,13 +637,7 @@ fn locals_live_across_suspend_points<'tcx>(
653
637
// If a borrow is converted to a raw reference, we must also assume that it lives
654
638
// forever. Note that the final liveness is still bounded by the storage liveness
655
639
// of the local, which happens using the `intersect` operation below.
656
- borrowed_locals_cursor. seek_before_primary_effect ( loc) ;
657
- let current_borrowed_locals = borrowed_locals_cursor. get ( ) ;
658
-
659
- debug ! ( "live_borrows_cursor seek before" ) ;
660
- live_borrows_cursor. seek_before_primary_effect ( loc) ;
661
- debug ! ( "finished seek before" ) ;
662
- let live_borrowed_locals = live_borrows_cursor. get ( ) ;
640
+ let live_borrowed_locals = live_borrows_cursor. get ( loc) ;
663
641
664
642
let mut live_locals_stmt: BitSet < _ > = BitSet :: new_empty ( body. local_decls . len ( ) ) ;
665
643
liveness. seek_before_primary_effect ( loc) ;
@@ -669,12 +647,11 @@ fn locals_live_across_suspend_points<'tcx>(
669
647
requires_storage_cursor. seek_before_primary_effect ( loc) ;
670
648
storage_req. union ( requires_storage_cursor. get ( ) ) ;
671
649
672
- debug ! ( ?current_borrowed_locals) ;
673
650
debug ! ( ?live_borrowed_locals) ;
674
651
debug ! ( ?live_locals_stmt) ;
675
652
debug ! ( ?storage_req) ;
676
653
677
- live_locals. union ( current_borrowed_locals ) ;
654
+ live_locals. union ( & live_borrowed_locals ) ;
678
655
}
679
656
680
657
// Store the storage liveness for later use so we can restore the state
@@ -686,7 +663,8 @@ fn locals_live_across_suspend_points<'tcx>(
686
663
// suspension points (the `liveness` variable)
687
664
// and their storage is required (the `storage_required` variable)
688
665
requires_storage_cursor. seek_before_primary_effect ( loc) ;
689
- live_locals. intersect ( requires_storage_cursor. get ( ) ) ;
666
+ let storage_required = requires_storage_cursor. get ( ) ;
667
+ live_locals. intersect ( storage_required) ;
690
668
691
669
// The generator argument is ignored.
692
670
live_locals. remove ( SELF_ARG ) ;
@@ -777,11 +755,11 @@ impl ops::Deref for GeneratorSavedLocals {
777
755
/// time. Generates a bitset for every local of all the other locals that may be
778
756
/// StorageLive simultaneously with that local. This is used in the layout
779
757
/// computation; see `GeneratorLayout` for more.
780
- fn compute_storage_conflicts < ' mir , ' tcx > (
758
+ fn compute_storage_conflicts < ' a , ' mir , ' tcx > (
781
759
body : & ' mir Body < ' tcx > ,
782
760
saved_locals : & GeneratorSavedLocals ,
783
761
always_live_locals : BitSet < Local > ,
784
- mut requires_storage : rustc_mir_dataflow:: Results < ' tcx , MaybeRequiresStorage < ' _ , ' mir , ' tcx > > ,
762
+ requires_storage : rustc_mir_dataflow:: Results < ' tcx , MaybeRequiresStorage < ' a , ' mir , ' tcx > > ,
785
763
) -> BitMatrix < GeneratorSavedLocal , GeneratorSavedLocal > {
786
764
assert_eq ! ( body. local_decls. len( ) , saved_locals. domain_size( ) ) ;
787
765
0 commit comments