11//! DOT (Graphviz) format output for MIR graphs.
22
3- use {
4- dot_writer:: { Attributes , Color , DotWriter , Scope , Shape , Style } ,
5- std:: collections:: HashSet ,
6- } ;
3+ use std:: collections:: HashSet ;
4+
5+ use dot_writer:: { Attributes , Color , DotWriter , Scope , Shape , Style } ;
76
87extern crate stable_mir;
9- use {
10- crate :: {
11- mk_graph:: {
12- context:: GraphContext ,
13- util:: { block_name, is_unqualified, name_lines, short_name, GraphLabelString } ,
14- } ,
15- printer:: SmirJson ,
16- MonoItemKind ,
17- } ,
18- stable_mir:: mir:: { BasicBlock , ConstOperand , Operand , TerminatorKind , UnwindAction } ,
19- } ;
8+ use stable_mir:: mir:: { BasicBlock , ConstOperand , Operand , TerminatorKind , UnwindAction } ;
9+
10+ use crate :: printer:: SmirJson ;
11+ use crate :: MonoItemKind ;
12+
13+ use crate :: mk_graph:: context:: GraphContext ;
14+ use crate :: mk_graph:: util:: { block_name, is_unqualified, name_lines, short_name, GraphLabelString } ;
2015
2116impl SmirJson < ' _ > {
2217 /// Convert the MIR to DOT (Graphviz) format
@@ -96,8 +91,7 @@ impl SmirJson<'_> {
9691 local_node. set ( "color" , "palegreen3" , false ) ;
9792 drop ( local_node) ;
9893
99- // Cannot define local functions that capture env. variables. Instead we
100- // define _closures_.
94+ // Cannot define local functions that capture env. variables. Instead we define _closures_.
10195 let process_block =
10296 |cluster : & mut Scope < ' _ , ' _ > , node_id : usize , b : & BasicBlock | {
10397 let name = & item. symbol_name ;
@@ -179,11 +173,8 @@ impl SmirJson<'_> {
179173 . set_label ( & dest) ;
180174 }
181175
182- // The call edge has to be drawn outside
183- // the cluster, outside this function
184- // (cluster borrows &mut graph)!
185- // Code for that is therefore separated
186- // into its own second function below.
176+ // The call edge has to be drawn outside the cluster, outside this function (cluster borrows &mut graph)!
177+ // Code for that is therefore separated into its own second function below.
187178 }
188179 Assert {
189180 cond,
@@ -244,10 +235,9 @@ impl SmirJson<'_> {
244235
245236 drop ( c) ; // so we can borrow graph again
246237
247- // call edges have to be added _outside_ the cluster of blocks for one
248- // function because they go between different
249- // clusters. Due to a scope/borrow issue, we have to
250- // make a 2nd pass over the bodies of the item.
238+ // call edges have to be added _outside_ the cluster of blocks for one function
239+ // because they go between different clusters. Due to a scope/borrow issue, we have
240+ // to make a 2nd pass over the bodies of the item.
251241 let add_call_edges =
252242 |graph : & mut Scope < ' _ , ' _ > , offset : usize , bs : & Vec < BasicBlock > | {
253243 for ( i, b) in bs. iter ( ) . enumerate ( ) {
@@ -262,17 +252,15 @@ impl SmirJson<'_> {
262252 if let Some ( callee) =
263253 ctx. functions . get ( & const_. ty ( ) )
264254 {
265- // callee node/body will be added when its
266- // body is added, missing ones added before
255+ // callee node/body will be added when its body is added, missing ones added before
267256 graph. edge (
268257 & this_block,
269258 block_name ( callee, 0 ) ,
270259 )
271260 } else {
272261 let unknown = format ! ( "{}" , const_. ty( ) ) ;
273262 // pathological case, could panic! instead.
274- // all unknown callees will be collapsed
275- // into one `unknown` node
263+ // all unknown callees will be collapsed into one `unknown` node
276264 graph. edge ( & this_block, unknown)
277265 }
278266 }
0 commit comments