Skip to content

Commit a67c615

Browse files
committed
Reduce rightward drift in locals_live_across_suspend_points
1 parent f0c98c2 commit a67c615

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
@@ -736,53 +736,53 @@ fn locals_live_across_suspend_points<'tcx>(
736736
let mut live_locals_at_any_suspension_point = DenseBitSet::new_empty(body.local_decls.len());
737737

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

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());
761+
// Store the storage liveness for later use so we can restore the state
762+
// after a suspension point
763+
storage_live.seek_before_primary_effect(loc);
764+
storage_liveness_map[block] = Some(storage_live.get().clone());
764765

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());
766+
// Locals live are live at this point only if they are used across
767+
// suspension points (the `liveness` variable)
768+
// and their storage is required (the `storage_required` variable)
769+
requires_storage_cursor.seek_before_primary_effect(loc);
770+
live_locals.intersect(requires_storage_cursor.get());
770771

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

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

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);
777+
// Add the locals live at this suspension point to the set of locals which live across
778+
// any suspension points
779+
live_locals_at_any_suspension_point.union(&live_locals);
779780

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

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

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

0 commit comments

Comments
 (0)