Skip to content

Commit

Permalink
Add comments to explain memory usage optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Nov 9, 2020
1 parent b2d115f commit 0242f96
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_mir/src/dataflow/framework/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 0242f96

Please sign in to comment.