Skip to content

Commit 55a80cc

Browse files
committed
Move StateDiffCollector's use point.
Currently the graphviz code does a `results.visit_with` call while also holding a `ResultsCursor` on the `results`. That is both kinds of results traversals at the same time, which is awkward. This commit moves the `results.visit_with` part earlier so the two results traversals don't overlap.
1 parent 85f6025 commit 55a80cc

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,15 @@ where
260260

261261
fn node_label(&self, block: &Self::Node) -> dot::LabelText<'_> {
262262
let mut results = self.results.borrow_mut();
263+
264+
let diffs = StateDiffCollector::run(self.body, *block, *results, self.style);
265+
263266
let mut fmt = BlockFormatter {
264267
cursor: results.as_results_cursor(self.body),
265268
style: self.style,
266269
bg: Background::Light,
267270
};
268-
let label = fmt.write_node_label(*block).unwrap();
271+
let label = fmt.write_node_label(*block, diffs).unwrap();
269272

270273
dot::LabelText::html(String::from_utf8(label).unwrap())
271274
}
@@ -336,7 +339,11 @@ where
336339
bg
337340
}
338341

339-
fn write_node_label(&mut self, block: BasicBlock) -> io::Result<Vec<u8>> {
342+
fn write_node_label(
343+
&mut self,
344+
block: BasicBlock,
345+
diffs: StateDiffCollector<A::Domain>,
346+
) -> io::Result<Vec<u8>> {
340347
use std::io::Write;
341348

342349
// Sample output:
@@ -392,7 +399,7 @@ where
392399
self.write_row_with_full_state(w, "", "(on start)")?;
393400

394401
// D + E: Statement and terminator transfer functions
395-
self.write_statements_and_terminator(w, block)?;
402+
self.write_statements_and_terminator(w, block, diffs)?;
396403

397404
// F: State at end of block
398405

@@ -575,14 +582,8 @@ where
575582
&mut self,
576583
w: &mut impl io::Write,
577584
block: BasicBlock,
585+
diffs: StateDiffCollector<A::Domain>,
578586
) -> io::Result<()> {
579-
let diffs = StateDiffCollector::run(
580-
self.cursor.body(),
581-
block,
582-
self.cursor.mut_results(),
583-
self.style,
584-
);
585-
586587
let mut diffs_before = diffs.before.map(|v| v.into_iter());
587588
let mut diffs_after = diffs.after.into_iter();
588589

0 commit comments

Comments
 (0)