@@ -6,6 +6,7 @@ use std::{io, ops, str};
6
6
7
7
use regex:: Regex ;
8
8
use rustc_graphviz as dot;
9
+ use rustc_index:: bit_set:: BitSet ;
9
10
use rustc_middle:: mir:: graphviz_safe_def_name;
10
11
use rustc_middle:: mir:: { self , BasicBlock , Body , Location } ;
11
12
@@ -34,14 +35,16 @@ where
34
35
body : & ' a Body < ' tcx > ,
35
36
results : & ' a Results < ' tcx , A > ,
36
37
style : OutputStyle ,
38
+ reachable : BitSet < BasicBlock > ,
37
39
}
38
40
39
41
impl < ' a , ' tcx , A > Formatter < ' a , ' tcx , A >
40
42
where
41
43
A : Analysis < ' tcx > ,
42
44
{
43
45
pub fn new ( body : & ' a Body < ' tcx > , results : & ' a Results < ' tcx , A > , style : OutputStyle ) -> Self {
44
- Formatter { body, results, style }
46
+ let reachable = mir:: traversal:: reachable_as_bitset ( body) ;
47
+ Formatter { body, results, style, reachable }
45
48
}
46
49
}
47
50
@@ -108,7 +111,12 @@ where
108
111
type Edge = CfgEdge ;
109
112
110
113
fn nodes ( & self ) -> dot:: Nodes < ' _ , Self :: Node > {
111
- self . body . basic_blocks . indices ( ) . collect :: < Vec < _ > > ( ) . into ( )
114
+ self . body
115
+ . basic_blocks
116
+ . indices ( )
117
+ . filter ( |& idx| self . reachable . contains ( idx) )
118
+ . collect :: < Vec < _ > > ( )
119
+ . into ( )
112
120
}
113
121
114
122
fn edges ( & self ) -> dot:: Edges < ' _ , Self :: Edge > {
0 commit comments