diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2020-11-10 14:45:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-10 14:45:23 +0100 |
| commit | a08e7afefd729a573380eb981da7f255fb3b73dc (patch) | |
| tree | ed87e4459561b103a46a25c7512a5ebe251fc2f6 | |
| parent | 105f4b879291deb15f3ef40b783b209faefe2c6a (diff) | |
| parent | 0242f963c631a130a3c405d7e54f4695ef10a139 (diff) | |
| download | rust-a08e7afefd729a573380eb981da7f255fb3b73dc.tar.gz rust-a08e7afefd729a573380eb981da7f255fb3b73dc.zip | |
Rollup merge of #78887 - camelid:dataflow-state-decl, r=jonas-schievink
Add comments to explain memory usage optimization Add explanatory comments so that people understand that it's just an optimization and doesn't affect behavior.
| -rw-r--r-- | compiler/rustc_mir/src/dataflow/framework/engine.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_mir/src/dataflow/framework/engine.rs b/compiler/rustc_mir/src/dataflow/framework/engine.rs index 1b7264f86a2..3f9f558223b 100644 --- a/compiler/rustc_mir/src/dataflow/framework/engine.rs +++ b/compiler/rustc_mir/src/dataflow/framework/engine.rs @@ -208,12 +208,19 @@ where } } + // `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), |
