Document why we don't look at storage liveness

...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`.
This commit is contained in:
Dylan MacKenzie 2020-05-13 09:45:00 -07:00
parent dd49c6ffd1
commit 3ff93177cf

View File

@ -505,6 +505,12 @@ fn locals_live_across_suspend_points(
let mut live_locals = locals_live_across_yield_point(block); 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. // Ignore the generator's `self` argument since it is handled seperately.
live_locals.remove(SELF_ARG); live_locals.remove(SELF_ARG);
debug!("block = {:?}, live_locals = {:?}", block, live_locals); debug!("block = {:?}, live_locals = {:?}", block, live_locals);
@ -571,6 +577,9 @@ fn record_conflicts_at_curr_loc(
// //
// requires_storage := init | borrowed // 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 // FIXME: This function is called in a loop, so it might be better to pass in a temporary
// bitset rather than cloning here. // bitset rather than cloning here.
let mut requires_storage = init.get().clone(); let mut requires_storage = init.get().clone();