Commit 472e678
committed
Auto merge of #65459 - ecstatic-morse:graphviz-subgraph, r=estebank
Fix `-Zunpretty=mir-cfg` to render multiple items
`-Zunpretty=mir-cfg` outputs DOT to stdout for all items being compiled. However, it puts all of these items in separate `digraph`s, which means the result of redirecting that output to a file is not valid. Most dot renderers (I have tried `dot` and `xdot`) cannot render the output.
This PR checks to see if `write_mir_graphviz` will process multiple items, and writes them each as a `subgraph` in a single, top-level `digraph`. As a result, DOT can be viewed without manually editing the output file. The output is unchanged when printing a single item (e.g.`-Zunpretty=mir-cfg=item_name`).
Here's the output of `xdot` for a rust file containing three items:

The borders are a result of the nonstandard–but well-supported–[`cluster` prefix](https://graphviz.gitlab.io/_pages/doc/info/lang.html) (search for "Subgraphs and Clusters"). They will not appear if your renderer does not support this extension, but the graph will still render properly.File tree
3 files changed
+45
-20
lines changed- src
- librustc_mir/util
- test/mir-opt
3 files changed
+45
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | | - | |
| 28 | + | |
22 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
23 | 35 | | |
24 | 36 | | |
25 | 37 | | |
| |||
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
| 53 | + | |
41 | 54 | | |
42 | 55 | | |
43 | 56 | | |
44 | 57 | | |
45 | 58 | | |
46 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
47 | 63 | | |
48 | 64 | | |
49 | 65 | | |
| |||
55 | 71 | | |
56 | 72 | | |
57 | 73 | | |
58 | | - | |
| 74 | + | |
59 | 75 | | |
60 | 76 | | |
61 | 77 | | |
62 | 78 | | |
63 | | - | |
| 79 | + | |
64 | 80 | | |
65 | 81 | | |
66 | 82 | | |
| |||
111 | 127 | | |
112 | 128 | | |
113 | 129 | | |
114 | | - | |
| 130 | + | |
115 | 131 | | |
116 | 132 | | |
117 | 133 | | |
118 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
119 | 140 | | |
120 | | - | |
| 141 | + | |
121 | 142 | | |
122 | 143 | | |
123 | 144 | | |
124 | 145 | | |
125 | 146 | | |
126 | 147 | | |
127 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
128 | 154 | | |
129 | 155 | | |
130 | 156 | | |
131 | 157 | | |
132 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
133 | 161 | | |
134 | 162 | | |
135 | 163 | | |
| |||
181 | 209 | | |
182 | 210 | | |
183 | 211 | | |
184 | | - | |
185 | | - | |
| 212 | + | |
| 213 | + | |
186 | 214 | | |
187 | 215 | | |
188 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
22 | 19 | | |
23 | 20 | | |
0 commit comments