Skip to content

Commit 6f682c2

Browse files
committed
Reduce rightward drift in locals_live_across_suspend_points
1 parent ef6bc3b commit 6f682c2

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -735,53 +735,53 @@ fn locals_live_across_suspend_points<'tcx>(
735735
let mut live_locals_at_any_suspension_point = DenseBitSet::new_empty(body.local_decls.len());
736736

737737
for (block, data) in body.basic_blocks.iter_enumerated() {
738-
if let TerminatorKind::Yield { .. } = data.terminator().kind {
739-
let loc = Location { block, statement_index: data.statements.len() };
740-
741-
liveness.seek_to_block_end(block);
742-
let mut live_locals = liveness.get().clone();
743-
744-
if !movable {
745-
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.
746-
// This is correct for movable coroutines since borrows cannot live across
747-
// suspension points. However for immovable coroutines we need to account for
748-
// borrows, so we conservatively assume that all borrowed locals are live until
749-
// we find a StorageDead statement referencing the locals.
750-
// To do this we just union our `liveness` result with `borrowed_locals`, which
751-
// contains all the locals which has been borrowed before this suspension point.
752-
// If a borrow is converted to a raw reference, we must also assume that it lives
753-
// forever. Note that the final liveness is still bounded by the storage liveness
754-
// of the local, which happens using the `intersect` operation below.
755-
borrowed_locals_cursor2.seek_before_primary_effect(loc);
756-
live_locals.union(borrowed_locals_cursor2.get());
757-
}
738+
let TerminatorKind::Yield { .. } = data.terminator().kind else { continue };
739+
740+
let loc = Location { block, statement_index: data.statements.len() };
741+
742+
liveness.seek_to_block_end(block);
743+
let mut live_locals = liveness.get().clone();
744+
745+
if !movable {
746+
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.
747+
// This is correct for movable coroutines since borrows cannot live across
748+
// suspension points. However for immovable coroutines we need to account for
749+
// borrows, so we conservatively assume that all borrowed locals are live until
750+
// we find a StorageDead statement referencing the locals.
751+
// To do this we just union our `liveness` result with `borrowed_locals`, which
752+
// contains all the locals which has been borrowed before this suspension point.
753+
// If a borrow is converted to a raw reference, we must also assume that it lives
754+
// forever. Note that the final liveness is still bounded by the storage liveness
755+
// of the local, which happens using the `intersect` operation below.
756+
borrowed_locals_cursor2.seek_before_primary_effect(loc);
757+
live_locals.union(borrowed_locals_cursor2.get());
758+
}
758759

759-
// Store the storage liveness for later use so we can restore the state
760-
// after a suspension point
761-
storage_live.seek_before_primary_effect(loc);
762-
storage_liveness_map[block] = Some(storage_live.get().clone());
760+
// Store the storage liveness for later use so we can restore the state
761+
// after a suspension point
762+
storage_live.seek_before_primary_effect(loc);
763+
storage_liveness_map[block] = Some(storage_live.get().clone());
763764

764-
// Locals live are live at this point only if they are used across
765-
// suspension points (the `liveness` variable)
766-
// and their storage is required (the `storage_required` variable)
767-
requires_storage_cursor.seek_before_primary_effect(loc);
768-
live_locals.intersect(requires_storage_cursor.get());
765+
// Locals live are live at this point only if they are used across
766+
// suspension points (the `liveness` variable)
767+
// and their storage is required (the `storage_required` variable)
768+
requires_storage_cursor.seek_before_primary_effect(loc);
769+
live_locals.intersect(requires_storage_cursor.get());
769770

770-
// The coroutine argument is ignored.
771-
live_locals.remove(SELF_ARG);
771+
// The coroutine argument is ignored.
772+
live_locals.remove(SELF_ARG);
772773

773-
debug!("loc = {:?}, live_locals = {:?}", loc, live_locals);
774+
debug!(?loc, ?live_locals);
774775

775-
// Add the locals live at this suspension point to the set of locals which live across
776-
// any suspension points
777-
live_locals_at_any_suspension_point.union(&live_locals);
776+
// Add the locals live at this suspension point to the set of locals which live across
777+
// any suspension points
778+
live_locals_at_any_suspension_point.union(&live_locals);
778779

779-
live_locals_at_suspension_points.push(live_locals);
780-
source_info_at_suspension_points.push(data.terminator().source_info);
781-
}
780+
live_locals_at_suspension_points.push(live_locals);
781+
source_info_at_suspension_points.push(data.terminator().source_info);
782782
}
783783

784-
debug!("live_locals_anywhere = {:?}", live_locals_at_any_suspension_point);
784+
debug!(?live_locals_at_any_suspension_point);
785785
let saved_locals = CoroutineSavedLocals(live_locals_at_any_suspension_point);
786786

787787
// Renumber our liveness_map bitsets to include only the locals we are

0 commit comments

Comments
 (0)