Skip to content

Commit

Permalink
Document why we don't look at storage liveness
Browse files Browse the repository at this point in the history
...when determining what locals are live.

A local cannot be borrowed before it is `storage_live` and
`MaybeBorrowedLocals` already invalidates borrows on `StorageDead`.
Likewise, a local cannot be initialized before it is marked StorageLive
and is marked as uninitialized after `StorageDead`.
  • Loading branch information
ecstatic-morse committed May 20, 2020
1 parent dd49c6f commit 3ff9317
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/librustc_mir/transform/generator.rs
Expand Up @@ -505,6 +505,12 @@ fn locals_live_across_suspend_points(

let mut live_locals = locals_live_across_yield_point(block);

// The combination of `MaybeInitializedLocals` and `MaybeBorrowedLocals` should be strictly
// more precise than `MaybeStorageLive` because they handle `StorageDead` themselves. This
// assumes that the MIR forbids locals from being initialized/borrowed before reaching
// `StorageLive`.
debug_assert!(storage_live.get().superset(&live_locals));

// Ignore the generator's `self` argument since it is handled seperately.
live_locals.remove(SELF_ARG);
debug!("block = {:?}, live_locals = {:?}", block, live_locals);
Expand Down Expand Up @@ -571,6 +577,9 @@ fn record_conflicts_at_curr_loc(
//
// requires_storage := init | borrowed
//
// Just like when determining what locals are live at yield points, there is no need
// to look at storage liveness here, since `init | borrowed` is strictly more precise.
//
// FIXME: This function is called in a loop, so it might be better to pass in a temporary
// bitset rather than cloning here.
let mut requires_storage = init.get().clone();
Expand Down

0 comments on commit 3ff9317

Please sign in to comment.