@@ -30,14 +30,16 @@ use self::rustc::middle::infer;
30
30
use self :: rustc:: middle:: region:: CodeExtentData ;
31
31
use self :: rustc:: middle:: ty:: { self , Ty } ;
32
32
use self :: rustc:: util:: common:: ErrorReported ;
33
+ use self :: rustc:: util:: nodemap:: NodeMap ;
33
34
use self :: rustc_front:: hir;
34
35
use self :: rustc_front:: visit;
35
36
use self :: syntax:: ast;
36
37
use self :: syntax:: attr:: AttrMetaMethods ;
37
38
use self :: syntax:: codemap:: Span ;
38
39
39
40
pub fn dump_crate ( tcx : & ty:: ctxt ) {
40
- let mut dump = OuterDump { tcx : tcx } ;
41
+ let mut map = NodeMap ( ) ;
42
+ let mut dump = OuterDump { tcx : tcx, map : & mut map } ;
41
43
visit:: walk_crate ( & mut dump, tcx. map . krate ( ) ) ;
42
44
}
43
45
@@ -46,21 +48,19 @@ pub fn dump_crate(tcx: &ty::ctxt) {
46
48
47
49
struct OuterDump < ' a , ' tcx : ' a > {
48
50
tcx : & ' a ty:: ctxt < ' tcx > ,
51
+ map : & ' a mut NodeMap < Mir < ' tcx > > ,
49
52
}
50
53
51
54
impl < ' a , ' tcx > OuterDump < ' a , ' tcx > {
52
- fn visit_mir < OP > ( & self , attributes : & ' tcx [ ast:: Attribute ] , mut walk_op : OP )
53
- where OP : FnMut ( & mut InnerDump < ' a , ' tcx > )
55
+ fn visit_mir < OP > ( & mut self , attributes : & ' a [ ast:: Attribute ] , mut walk_op : OP )
56
+ where OP : for < ' m > FnMut ( & mut InnerDump < ' a , ' m , ' tcx > )
54
57
{
55
- let mut built_mir = false ;
56
-
57
- let mut closure_dump = InnerDump { tcx : self . tcx , attr : None } ;
58
+ let mut closure_dump = InnerDump { tcx : self . tcx , attr : None , map : & mut * self . map } ;
58
59
for attr in attributes {
59
60
if attr. check_name ( "rustc_mir" ) {
60
61
closure_dump. attr = Some ( attr) ;
61
62
}
62
63
}
63
-
64
64
walk_op ( & mut closure_dump) ;
65
65
}
66
66
}
@@ -77,25 +77,47 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for OuterDump<'a, 'tcx> {
77
77
hir:: MethodTraitItem ( _, Some ( _) ) => {
78
78
self . visit_mir ( & trait_item. attrs , |c| visit:: walk_trait_item ( c, trait_item) ) ;
79
79
}
80
- _ => { }
80
+ hir:: MethodTraitItem ( _, None ) |
81
+ hir:: ConstTraitItem ( ..) |
82
+ hir:: TypeTraitItem ( ..) => {
83
+ }
81
84
}
82
85
visit:: walk_trait_item ( self , trait_item) ;
83
86
}
87
+
88
+ fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem ) {
89
+ match impl_item. node {
90
+ hir:: MethodImplItem ( ..) => {
91
+ self . visit_mir ( & impl_item. attrs , |c| visit:: walk_impl_item ( c, impl_item) ) ;
92
+ }
93
+ hir:: ConstImplItem ( ..) | hir:: TypeImplItem ( ..) => { }
94
+ }
95
+ visit:: walk_impl_item ( self , impl_item) ;
96
+ }
84
97
}
85
98
86
99
///////////////////////////////////////////////////////////////////////////
87
100
// InnerDump -- dumps MIR for a single fn and its contained closures
88
101
89
- struct InnerDump < ' a , ' tcx : ' a > {
102
+ struct InnerDump < ' a , ' m , ' tcx : ' a + ' m > {
90
103
tcx : & ' a ty:: ctxt < ' tcx > ,
104
+ map : & ' m mut NodeMap < Mir < ' tcx > > ,
91
105
attr : Option < & ' a ast:: Attribute > ,
92
106
}
93
107
94
- impl < ' a , ' tcx > visit:: Visitor < ' tcx > for InnerDump < ' a , ' tcx > {
108
+ impl < ' a , ' m , ' tcx > visit:: Visitor < ' tcx > for InnerDump < ' a , ' m , ' tcx > {
95
109
fn visit_item ( & mut self , _: & ' tcx hir:: Item ) {
96
110
// ignore nested items; they need their own graphviz annotation
97
111
}
98
112
113
+ fn visit_trait_item ( & mut self , _: & ' tcx hir:: TraitItem ) {
114
+ // ignore nested items; they need their own graphviz annotation
115
+ }
116
+
117
+ fn visit_impl_item ( & mut self , _: & ' tcx hir:: ImplItem ) {
118
+ // ignore nested items; they need their own graphviz annotation
119
+ }
120
+
99
121
fn visit_fn ( & mut self ,
100
122
fk : visit:: FnKind < ' tcx > ,
101
123
decl : & ' tcx hir:: FnDecl ,
@@ -150,6 +172,9 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for InnerDump<'a,'tcx> {
150
172
}
151
173
}
152
174
}
175
+
176
+ let previous = self . map . insert ( id, mir) ;
177
+ assert ! ( previous. is_none( ) ) ;
153
178
}
154
179
Err ( ErrorReported ) => { }
155
180
}
0 commit comments