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.
This commit is contained in:
Jonas Schievink 2020-11-10 14:45:23 +01:00 committed by GitHub
commit a08e7afefd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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),