]> git.lizzy.rs Git - rust.git/commitdiff
Add comments to explain memory usage optimization
authorCamelid <camelidcamel@gmail.com>
Sun, 8 Nov 2020 21:52:15 +0000 (13:52 -0800)
committerCamelid <camelidcamel@gmail.com>
Mon, 9 Nov 2020 21:34:16 +0000 (13:34 -0800)
compiler/rustc_mir/src/dataflow/framework/engine.rs

index 1b7264f86a2d159348da7d67d0e24c944ef59f56..3f9f558223bb00dabc2d89860953553237da139e 100644 (file)
@@ -208,12 +208,19 @@ pub fn iterate_to_fixpoint(self) -> Results<'tcx, A>
             }
         }
 
+        // `state` is not actually used between iterations;
+        // this is just an optimization to avoid reallocating
+        // every iteration.
         let mut state = analysis.bottom_value(body);
         while let Some(bb) = dirty_queue.pop() {
             let bb_data = &body[bb];
 
-            // Apply the block transfer function, using the cached one if it exists.
+            // Set the state to the entry state of the block.
+            // This is equivalent to `state = entry_sets[bb].clone()`,
+            // but it saves an allocation, thus improving compile times.
             state.clone_from(&entry_sets[bb]);
+
+            // Apply the block transfer function, using the cached one if it exists.
             match &apply_trans_for_block {
                 Some(apply) => apply(bb, &mut state),
                 None => A::Direction::apply_effects_in_block(&analysis, &mut state, bb, bb_data),