From 8d6208c39b5aa63c7bbda30e325fdffefc7b81b8 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 21 Jan 2020 13:37:59 -0800 Subject: [PATCH] Use nicer alignment when printing state vectors --- src/librustc_mir/dataflow/generic/graphviz.rs | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/librustc_mir/dataflow/generic/graphviz.rs b/src/librustc_mir/dataflow/generic/graphviz.rs index f70564d4019..b805b13592f 100644 --- a/src/librustc_mir/dataflow/generic/graphviz.rs +++ b/src/librustc_mir/dataflow/generic/graphviz.rs @@ -171,10 +171,19 @@ where // | | (on successful return) | +_4 | // +-+----------------------------------+------------+ - write!( - w, - r#""#, - )?; + // N.B., Some attributes (`align`, `balign`) are repeated on parent elements and their + // children. This is because `xdot` seemed to have a hard time correctly propagating + // 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
. + + let table_fmt = concat!( + " border=\"1\"", + " cellborder=\"1\"", + " cellspacing=\"0\"", + " cellpadding=\"3\"", + " sides=\"rb\"", + ); + write!(w, r#""#, fmt = table_fmt)?; // A + B: Block header if self.state_formatter.column_names().is_empty() { @@ -186,7 +195,7 @@ where // C: Entry state self.bg = Background::Light; self.results.seek_to_block_start(block); - self.write_row_with_full_state(w, "", "(on_entry)")?; + self.write_row_with_full_state(w, "", "(on entry)")?; // D: Statement transfer functions for (i, statement) in body[block].statements.iter().enumerate() { @@ -212,7 +221,7 @@ where self.write_row(w, "", "(on successful return)", |this, w, fmt| { write!( w, - r#"") }) } @@ -416,7 +427,7 @@ where } self.prev_loc = location; - write!(w, r#"")?; } @@ -561,25 +572,28 @@ fn write_diff>( if !set.is_empty() { write!(w, r#"+"#)?; - pretty_print_state_elems(w, analysis, set.iter(), ",", LIMIT_40_ALIGN_1)?; + pretty_print_state_elems(w, analysis, set.iter(), ", ", LIMIT_30_ALIGN_1)?; write!(w, r#""#)?; } if !set.is_empty() && !clear.is_empty() { - write!(w, "
")?; + write!(w, "{}", BR_LEFT)?; } if !clear.is_empty() { write!(w, r#"-"#)?; - pretty_print_state_elems(w, analysis, clear.iter(), ",", LIMIT_40_ALIGN_1)?; + pretty_print_state_elems(w, analysis, clear.iter(), ", ", LIMIT_30_ALIGN_1)?; write!(w, r#""#)?; } Ok(()) } +const BR_LEFT: &'static str = r#"
"#; +const BR_LEFT_SPACE: &'static str = r#"
"#; + /// Line break policy that breaks at 40 characters and starts the next line with a single space. -const LIMIT_40_ALIGN_1: Option = Some(LineBreak { sequence: "
", limit: 40 }); +const LIMIT_30_ALIGN_1: Option = Some(LineBreak { sequence: BR_LEFT_SPACE, limit: 30 }); struct LineBreak { sequence: &'static str,
"#, + r#""#, colspan = num_state_columns, fmt = fmt, )?; @@ -311,7 +320,9 @@ where f: impl FnOnce(&mut Self, &mut W, &str) -> io::Result<()>, ) -> io::Result<()> { let bg = self.toggle_background(); - let fmt = format!("sides=\"tl\" {}", bg.attr()); + let valign = if mir.starts_with("(on ") && mir != "(on entry)" { "bottom" } else { "top" }; + + let fmt = format!("valign=\"{}\" sides=\"tl\" {}", valign, bg.attr()); write!( w, @@ -345,7 +356,7 @@ where colspan = this.num_state_columns(), fmt = fmt, )?; - pretty_print_state_elems(w, analysis, state.iter(), ",", LIMIT_40_ALIGN_1)?; + pretty_print_state_elems(w, analysis, state.iter(), ", ", LIMIT_30_ALIGN_1)?; write!(w, "}}"#, fmt = fmt)?; + write!(w, r#""#, fmt = fmt)?; results.seek_after(location); let curr_state = results.get(); write_diff(&mut w, results.analysis(), &self.prev_state, curr_state)?; @@ -524,12 +535,12 @@ where for set in &[&block_trans.gen, &block_trans.kill] { write!( w, - r#""#, + r#""#, fmt = fmt, rowspan = rowspan )?; - pretty_print_state_elems(&mut w, results.analysis(), set.iter(), "\n", None)?; + pretty_print_state_elems(&mut w, results.analysis(), set.iter(), BR_LEFT, None)?; write!(w, "