Skip to content

Commit 3ff9317

Browse files
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`.
1 parent dd49c6f commit 3ff9317

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/librustc_mir/transform/generator.rs

+9
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ fn locals_live_across_suspend_points(
505505

506506
let mut live_locals = locals_live_across_yield_point(block);
507507

508+
// The combination of `MaybeInitializedLocals` and `MaybeBorrowedLocals` should be strictly
509+
// more precise than `MaybeStorageLive` because they handle `StorageDead` themselves. This
510+
// assumes that the MIR forbids locals from being initialized/borrowed before reaching
511+
// `StorageLive`.
512+
debug_assert!(storage_live.get().superset(&live_locals));
513+
508514
// Ignore the generator's `self` argument since it is handled seperately.
509515
live_locals.remove(SELF_ARG);
510516
debug!("block = {:?}, live_locals = {:?}", block, live_locals);
@@ -571,6 +577,9 @@ fn record_conflicts_at_curr_loc(
571577
//
572578
// requires_storage := init | borrowed
573579
//
580+
// Just like when determining what locals are live at yield points, there is no need
581+
// to look at storage liveness here, since `init | borrowed` is strictly more precise.
582+
//
574583
// FIXME: This function is called in a loop, so it might be better to pass in a temporary
575584
// bitset rather than cloning here.
576585
let mut requires_storage = init.get().clone();

0 commit comments

Comments
 (0)