Skip to content

Commit a08e7af

Browse files
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.
2 parents 105f4b8 + 0242f96 commit a08e7af

File tree

1 file changed

+8
-1
lines changed
  • compiler/rustc_mir/src/dataflow/framework

1 file changed

+8
-1
lines changed

compiler/rustc_mir/src/dataflow/framework/engine.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,19 @@ where
208208
}
209209
}
210210

211+
// `state` is not actually used between iterations;
212+
// this is just an optimization to avoid reallocating
213+
// every iteration.
211214
let mut state = analysis.bottom_value(body);
212215
while let Some(bb) = dirty_queue.pop() {
213216
let bb_data = &body[bb];
214217

215-
// Apply the block transfer function, using the cached one if it exists.
218+
// Set the state to the entry state of the block.
219+
// This is equivalent to `state = entry_sets[bb].clone()`,
220+
// but it saves an allocation, thus improving compile times.
216221
state.clone_from(&entry_sets[bb]);
222+
223+
// Apply the block transfer function, using the cached one if it exists.
217224
match &apply_trans_for_block {
218225
Some(apply) => apply(bb, &mut state),
219226
None => A::Direction::apply_effects_in_block(&analysis, &mut state, bb, bb_data),

0 commit comments

Comments
 (0)