Skip to content

Commit

Permalink
Return label from write_node_label.
Browse files Browse the repository at this point in the history
Instead of appending an empty label. Because it's conceptually simpler.
  • Loading branch information
nnethercote committed Oct 30, 2024
1 parent a8ce44f commit d921be9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions compiler/rustc_mir_dataflow/src/framework/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ where
}

fn node_label(&self, block: &Self::Node) -> dot::LabelText<'_> {
let mut label = Vec::new();
let mut cursor = self.cursor.borrow_mut();
let mut fmt =
BlockFormatter { cursor: &mut cursor, style: self.style, bg: Background::Light };
fmt.write_node_label(&mut label, *block).unwrap();
let label = fmt.write_node_label(*block).unwrap();

dot::LabelText::html(String::from_utf8(label).unwrap())
}
Expand Down Expand Up @@ -172,7 +171,9 @@ where
bg
}

fn write_node_label(&mut self, w: &mut impl io::Write, block: BasicBlock) -> io::Result<()> {
fn write_node_label(&mut self, block: BasicBlock) -> io::Result<Vec<u8>> {
use std::io::Write;

// Sample output:
// +-+-----------------------------------------------+
// A | bb4 |
Expand All @@ -199,6 +200,9 @@ where
// attributes. Make sure to test the output before trying to remove the redundancy.
// Notably, `align` was found to have no effect when applied only to <table>.

let mut v = vec![];
let w = &mut v;

let table_fmt = concat!(
" border=\"1\"",
" cellborder=\"1\"",
Expand Down Expand Up @@ -327,7 +331,9 @@ where
_ => {}
};

write!(w, "</table>")
write!(w, "</table>")?;

Ok(v)
}

fn write_block_header_simple(
Expand Down

0 comments on commit d921be9

Please sign in to comment.