about summary refs log tree commit diff
path: root/compiler/rustc_mir_dataflow
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-04-21 10:23:08 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2025-04-22 09:45:44 +1000
commit55a80cc132ae68ef624b28b3b3e2cdd4b3585b24 (patch)
tree0a151661613f78531861e6840b4ce3405d498075 /compiler/rustc_mir_dataflow
parent85f6025f45eb59ff99ac480906545f3cfbe68e7f (diff)
downloadrust-55a80cc132ae68ef624b28b3b3e2cdd4b3585b24.tar.gz
rust-55a80cc132ae68ef624b28b3b3e2cdd4b3585b24.zip
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.
Diffstat (limited to 'compiler/rustc_mir_dataflow')
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/graphviz.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
index 1a1b163b075..5d9a340db6a 100644
--- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
@@ -260,12 +260,15 @@ where
 
     fn node_label(&self, block: &Self::Node) -> dot::LabelText<'_> {
         let mut results = self.results.borrow_mut();
+
+        let diffs = StateDiffCollector::run(self.body, *block, *results, self.style);
+
         let mut fmt = BlockFormatter {
             cursor: results.as_results_cursor(self.body),
             style: self.style,
             bg: Background::Light,
         };
-        let label = fmt.write_node_label(*block).unwrap();
+        let label = fmt.write_node_label(*block, diffs).unwrap();
 
         dot::LabelText::html(String::from_utf8(label).unwrap())
     }
@@ -336,7 +339,11 @@ where
         bg
     }
 
-    fn write_node_label(&mut self, block: BasicBlock) -> io::Result<Vec<u8>> {
+    fn write_node_label(
+        &mut self,
+        block: BasicBlock,
+        diffs: StateDiffCollector<A::Domain>,
+    ) -> io::Result<Vec<u8>> {
         use std::io::Write;
 
         //   Sample output:
@@ -392,7 +399,7 @@ where
         self.write_row_with_full_state(w, "", "(on start)")?;
 
         // D + E: Statement and terminator transfer functions
-        self.write_statements_and_terminator(w, block)?;
+        self.write_statements_and_terminator(w, block, diffs)?;
 
         // F: State at end of block
 
@@ -575,14 +582,8 @@ where
         &mut self,
         w: &mut impl io::Write,
         block: BasicBlock,
+        diffs: StateDiffCollector<A::Domain>,
     ) -> io::Result<()> {
-        let diffs = StateDiffCollector::run(
-            self.cursor.body(),
-            block,
-            self.cursor.mut_results(),
-            self.style,
-        );
-
         let mut diffs_before = diffs.before.map(|v| v.into_iter());
         let mut diffs_after = diffs.after.into_iter();