@@ -15,7 +15,6 @@ use hir::def_id::DefId;
15
15
use hir:: map:: DefPathData ;
16
16
use mir:: { Mir , Promoted } ;
17
17
use ty:: TyCtxt ;
18
- use std:: cell:: Ref ;
19
18
use std:: rc:: Rc ;
20
19
use syntax:: ast:: NodeId ;
21
20
@@ -83,29 +82,6 @@ pub fn default_name<T: ?Sized>() -> Cow<'static, str> {
83
82
}
84
83
}
85
84
86
- /// Gives you access to various bits of state during your MIR pass.
87
- pub trait MirCtxt < ' a , ' tcx : ' a > {
88
- fn tcx ( & self ) -> TyCtxt < ' a , ' tcx , ' tcx > ;
89
- fn def_id ( & self ) -> DefId ;
90
- fn suite ( & self ) -> MirSuite ;
91
- fn pass_num ( & self ) -> MirPassIndex ;
92
- fn source ( & self ) -> MirSource ;
93
-
94
- // Get a read-only view on the MIR of this def-id from the
95
- // previous pass.
96
- fn read_previous_mir ( & self ) -> Ref < ' tcx , Mir < ' tcx > > ;
97
-
98
- // Steal the MIR of this def-id from the previous pass; any future
99
- // attempt to access the MIR from the previous pass is a bug.
100
- fn steal_previous_mir ( & self ) -> Mir < ' tcx > ;
101
-
102
- // Same as `read_previous_mir()`, but for any def-id you want.
103
- fn read_previous_mir_of ( & self , def_id : DefId ) -> Ref < ' tcx , Mir < ' tcx > > ;
104
-
105
- // Same as `steal_previous_mir()`, but for any def-id you want.
106
- fn steal_previous_mir_of ( & self , def_id : DefId ) -> Mir < ' tcx > ;
107
- }
108
-
109
85
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
110
86
pub struct MirSuite ( pub usize ) ;
111
87
@@ -125,26 +101,19 @@ pub struct MirPassIndex(pub usize);
125
101
/// the hook will be invoked once per output.
126
102
pub trait PassHook {
127
103
fn on_mir_pass < ' a , ' tcx : ' a > ( & self ,
128
- mir_cx : & MirCtxt < ' a , ' tcx > ,
129
- mir : Option < ( DefId , & Mir < ' tcx > ) > ) ;
104
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
105
+ suite : MirSuite ,
106
+ pass_num : MirPassIndex ,
107
+ pass_name : & str ,
108
+ source : MirSource ,
109
+ mir : & Mir < ' tcx > ,
110
+ is_after : bool ) ;
130
111
}
131
112
132
113
/// The full suite of types that identifies a particular
133
114
/// application of a pass to a def-id.
134
115
pub type PassId = ( MirSuite , MirPassIndex , DefId ) ;
135
116
136
- /// A streamlined trait that you can implement to create an
137
- /// intraprocedural pass; the pass will be invoked to process the MIR
138
- /// with the given `def_id`. This lets you do things before we fetch
139
- /// the MIR itself. You may prefer `MirPass`, which is even more streamlined.
140
- pub trait DefIdPass {
141
- fn name < ' a > ( & ' a self ) -> Cow < ' a , str > {
142
- default_name :: < Self > ( )
143
- }
144
-
145
- fn run_pass < ' a , ' tcx : ' a > ( & self , mir_cx : & MirCtxt < ' a , ' tcx > ) -> Mir < ' tcx > ;
146
- }
147
-
148
117
/// A streamlined trait that you can implement to create a pass; the
149
118
/// pass will be named after the type, and it will consist of a main
150
119
/// loop that goes over each available MIR and applies `run_pass`.
@@ -159,32 +128,11 @@ pub trait MirPass {
159
128
mir : & mut Mir < ' tcx > ) ;
160
129
}
161
130
162
- impl < T : MirPass > DefIdPass for T {
163
- fn name < ' a > ( & ' a self ) -> Cow < ' a , str > {
164
- MirPass :: name ( self )
165
- }
166
-
167
- fn run_pass < ' a , ' tcx : ' a > ( & self , mir_cx : & MirCtxt < ' a , ' tcx > ) -> Mir < ' tcx > {
168
- let tcx = mir_cx. tcx ( ) ;
169
- let source = mir_cx. source ( ) ;
170
- let mut mir = mir_cx. steal_previous_mir ( ) ;
171
- MirPass :: run_pass ( self , tcx, source, & mut mir) ;
172
-
173
- let item_id = source. item_id ( ) ;
174
- for ( promoted_index, promoted_mir) in mir. promoted . iter_enumerated_mut ( ) {
175
- let promoted_source = MirSource :: Promoted ( item_id, promoted_index) ;
176
- MirPass :: run_pass ( self , tcx, promoted_source, promoted_mir) ;
177
- }
178
-
179
- mir
180
- }
181
- }
182
-
183
131
/// A manager for MIR passes.
184
132
#[ derive( Clone ) ]
185
133
pub struct Passes {
186
134
pass_hooks : Vec < Rc < PassHook > > ,
187
- suites : Vec < Vec < Rc < DefIdPass > > > ,
135
+ suites : Vec < Vec < Rc < MirPass > > > ,
188
136
}
189
137
190
138
/// The number of "pass suites" that we have:
@@ -212,7 +160,7 @@ impl<'a, 'tcx> Passes {
212
160
}
213
161
214
162
/// Pushes a built-in pass.
215
- pub fn push_pass < T : DefIdPass + ' static > ( & mut self , suite : MirSuite , pass : T ) {
163
+ pub fn push_pass < T : MirPass + ' static > ( & mut self , suite : MirSuite , pass : T ) {
216
164
self . suites [ suite. 0 ] . push ( Rc :: new ( pass) ) ;
217
165
}
218
166
@@ -225,7 +173,7 @@ impl<'a, 'tcx> Passes {
225
173
self . suites [ suite. 0 ] . len ( )
226
174
}
227
175
228
- pub fn pass ( & self , suite : MirSuite , pass : MirPassIndex ) -> & DefIdPass {
176
+ pub fn pass ( & self , suite : MirSuite , pass : MirPassIndex ) -> & MirPass {
229
177
& * self . suites [ suite. 0 ] [ pass. 0 ]
230
178
}
231
179
0 commit comments