Skip to content

Commit 50ddda6

Browse files
authored
Rollup merge of #69158 - ecstatic-morse:graphviz-diff, r=matthewjasper
Don't print block exit state in dataflow graphviz if unchanged A small quality-of-life improvement I was using while working on #68528. It's pretty common to have a lot of zero-statement basic blocks, especially before a `SimplifyCfg` pass is run. When the dataflow state was dense, these blocks could take up a lot of vertical space since the full flow state was printed on both entry and exit. After this PR, we only print a block's exit state if it differs from that block's entry state. Take a look at the two basic blocks on the left. Before: ![image](https://user-images.githubusercontent.com/29463364/74505395-e2d1dd00-4eab-11ea-8006-ec8f0dc9d1b6.png) After: ![image](https://user-images.githubusercontent.com/29463364/74505277-98506080-4eab-11ea-8d95-5190bc378331.png)
2 parents c3fed9f + 5c473a0 commit 50ddda6

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

src/librustc_mir/dataflow/generic/graphviz.rs

+35-20
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ where
195195
// C: Entry state
196196
self.bg = Background::Light;
197197
self.results.seek_to_block_start(block);
198+
let block_entry_state = self.results.get().clone();
199+
198200
self.write_row_with_full_state(w, "", "(on entry)")?;
199201

200202
// D: Statement transfer functions
@@ -213,29 +215,42 @@ where
213215
self.write_row_for_location(w, "T", &terminator_str, terminator_loc)?;
214216

215217
// F: Exit state
218+
219+
// Write the full dataflow state immediately after the terminator if it differs from the
220+
// state at block entry.
216221
self.results.seek_after(terminator_loc);
217-
if let mir::TerminatorKind::Call { destination: Some(_), .. } = &terminator.kind {
218-
self.write_row_with_full_state(w, "", "(on unwind)")?;
219-
220-
let num_state_columns = self.num_state_columns();
221-
self.write_row(w, "", "(on successful return)", |this, w, fmt| {
222-
write!(
223-
w,
224-
r#"<td balign="left" colspan="{colspan}" {fmt} align="left">"#,
225-
colspan = num_state_columns,
226-
fmt = fmt,
227-
)?;
228-
229-
let state_on_unwind = this.results.get().clone();
230-
this.results.seek_after_assume_call_returns(terminator_loc);
231-
write_diff(w, this.results.analysis(), &state_on_unwind, this.results.get())?;
232-
233-
write!(w, "</td>")
234-
})?;
235-
} else {
236-
self.write_row_with_full_state(w, "", "(on exit)")?;
222+
if self.results.get() != &block_entry_state {
223+
let after_terminator_name = match terminator.kind {
224+
mir::TerminatorKind::Call { destination: Some(_), .. } => "(on unwind)",
225+
_ => "(on exit)",
226+
};
227+
228+
self.write_row_with_full_state(w, "", after_terminator_name)?;
237229
}
238230

231+
// Write any changes caused by terminator-specific effects
232+
match terminator.kind {
233+
mir::TerminatorKind::Call { destination: Some(_), .. } => {
234+
let num_state_columns = self.num_state_columns();
235+
self.write_row(w, "", "(on successful return)", |this, w, fmt| {
236+
write!(
237+
w,
238+
r#"<td balign="left" colspan="{colspan}" {fmt} align="left">"#,
239+
colspan = num_state_columns,
240+
fmt = fmt,
241+
)?;
242+
243+
let state_on_unwind = this.results.get().clone();
244+
this.results.seek_after_assume_call_returns(terminator_loc);
245+
write_diff(w, this.results.analysis(), &state_on_unwind, this.results.get())?;
246+
247+
write!(w, "</td>")
248+
})?;
249+
}
250+
251+
_ => {}
252+
};
253+
239254
write!(w, "</table>")
240255
}
241256

0 commit comments

Comments
 (0)