Skip to content

Commit 0fb7794

Browse files
committed
use new analysis in generator transform
1 parent de5ce09 commit 0fb7794

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

compiler/rustc_mir_transform/src/generator.rs

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ use rustc_middle::mir::*;
6767
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
6868
use rustc_middle::ty::{GeneratorSubsts, SubstsRef};
6969
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,
7272
};
7373
use rustc_mir_dataflow::storage::always_storage_live_locals;
7474
use rustc_mir_dataflow::{self, Analysis};
@@ -593,22 +593,18 @@ fn locals_live_across_suspend_points<'tcx>(
593593
.iterate_to_fixpoint()
594594
.into_results_cursor(body_ref);
595595

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);
604599

605600
// Calculate the MIR locals that we actually need to keep storage around
606601
// 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);
612608

613609
// Calculate the liveness of MIR locals ignoring borrows.
614610
let mut liveness = MaybeLiveLocals
@@ -623,21 +619,9 @@ fn locals_live_across_suspend_points<'tcx>(
623619
let mut live_locals_at_any_suspension_point = BitSet::new_empty(body.local_decls.len());
624620

625621
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-
636622
debug!(?block, ?data.terminator);
637623
if let TerminatorKind::Yield { .. } = data.terminator().kind {
638624
let loc = Location { block, statement_index: data.statements.len() };
639-
debug!("encountered Yield at loc {:?}", loc);
640-
641625
liveness.seek_to_block_end(block);
642626
let mut live_locals: BitSet<_> = BitSet::new_empty(body.local_decls.len());
643627
live_locals.union(liveness.get());
@@ -653,13 +637,7 @@ fn locals_live_across_suspend_points<'tcx>(
653637
// If a borrow is converted to a raw reference, we must also assume that it lives
654638
// forever. Note that the final liveness is still bounded by the storage liveness
655639
// 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);
663641

664642
let mut live_locals_stmt: BitSet<_> = BitSet::new_empty(body.local_decls.len());
665643
liveness.seek_before_primary_effect(loc);
@@ -669,12 +647,11 @@ fn locals_live_across_suspend_points<'tcx>(
669647
requires_storage_cursor.seek_before_primary_effect(loc);
670648
storage_req.union(requires_storage_cursor.get());
671649

672-
debug!(?current_borrowed_locals);
673650
debug!(?live_borrowed_locals);
674651
debug!(?live_locals_stmt);
675652
debug!(?storage_req);
676653

677-
live_locals.union(current_borrowed_locals);
654+
live_locals.union(&live_borrowed_locals);
678655
}
679656

680657
// Store the storage liveness for later use so we can restore the state
@@ -686,7 +663,8 @@ fn locals_live_across_suspend_points<'tcx>(
686663
// suspension points (the `liveness` variable)
687664
// and their storage is required (the `storage_required` variable)
688665
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);
690668

691669
// The generator argument is ignored.
692670
live_locals.remove(SELF_ARG);
@@ -777,11 +755,11 @@ impl ops::Deref for GeneratorSavedLocals {
777755
/// time. Generates a bitset for every local of all the other locals that may be
778756
/// StorageLive simultaneously with that local. This is used in the layout
779757
/// computation; see `GeneratorLayout` for more.
780-
fn compute_storage_conflicts<'mir, 'tcx>(
758+
fn compute_storage_conflicts<'a, 'mir, 'tcx>(
781759
body: &'mir Body<'tcx>,
782760
saved_locals: &GeneratorSavedLocals,
783761
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>>,
785763
) -> BitMatrix<GeneratorSavedLocal, GeneratorSavedLocal> {
786764
assert_eq!(body.local_decls.len(), saved_locals.domain_size());
787765

0 commit comments

Comments
 (0)