Skip to content

Some more graphviz tweaks #140142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 23, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
nnethercote committed Apr 21, 2025
commit 55a80cc132ae68ef624b28b3b3e2cdd4b3585b24
21 changes: 11 additions & 10 deletions compiler/rustc_mir_dataflow/src/framework/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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();

Expand Down