about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2020-05-13 09:45:00 -0700
committerDylan MacKenzie <ecstaticmorse@gmail.com>2020-05-19 17:52:08 -0700
commit3ff93177cf7976c1db072cdcb4bc3f23e5f6b78c (patch)
tree1c563f13ec3d25e9587c5f9ef4c03e91a3b79c21 /src
parentdd49c6ffd1eb2ce5919b7ce8788a55ecc4fe13b5 (diff)
downloadrust-3ff93177cf7976c1db072cdcb4bc3f23e5f6b78c.tar.gz
rust-3ff93177cf7976c1db072cdcb4bc3f23e5f6b78c.zip
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`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/transform/generator.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs
index bee129b8749..5f8104e7934 100644
--- a/src/librustc_mir/transform/generator.rs
+++ b/src/librustc_mir/transform/generator.rs
@@ -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);
@@ -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();