@@ -155,68 +155,68 @@ pub trait MirPass {
155155 mir : & mut Mir < ' tcx > ) ;
156156}
157157
158- pub macro run_passes(
159- $tcx: ident,
160- $mir: ident,
161- $def_id: ident,
162- $mir_phase: expr;
163- $( $pass: expr, ) *
164- ) { {
165- let phase_index = $mir_phase. phase_index ( ) ;
166-
167- let run_passes = |mir : & mut _ , promoted| {
168- let mir: & mut Mir < ' _ > = mir;
169-
170- if mir. phase >= $mir_phase {
158+ pub fn run_passes (
159+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
160+ mir : & mut Mir < ' tcx > ,
161+ def_id : DefId ,
162+ mir_phase : MirPhase ,
163+ passes : & [ & dyn MirPass ] ) {
164+ let phase_index = mir_phase. phase_index ( ) ;
165+
166+ let run_passes = |mir : & mut Mir < ' tcx > , promoted| {
167+ if mir. phase >= mir_phase {
171168 return ;
172169 }
173170
174171 let source = MirSource {
175- def_id : $def_id ,
176- promoted
172+ def_id,
173+ promoted,
177174 } ;
178175 let mut index = 0 ;
179176 let mut run_pass = |pass : & dyn MirPass | {
180177 let run_hooks = |mir : & _ , index, is_after| {
181- dump_mir:: on_mir_pass ( $ tcx, & format_args ! ( "{:03}-{:03}" , phase_index, index) ,
178+ dump_mir:: on_mir_pass ( tcx, & format_args ! ( "{:03}-{:03}" , phase_index, index) ,
182179 & pass. name ( ) , source, mir, is_after) ;
183180 } ;
184181 run_hooks ( mir, index, false ) ;
185- pass. run_pass ( $ tcx, source, mir) ;
182+ pass. run_pass ( tcx, source, mir) ;
186183 run_hooks ( mir, index, true ) ;
187184
188185 index += 1 ;
189186 } ;
190- $( run_pass ( & $pass) ; ) *
191187
192- mir. phase = $mir_phase;
188+ for pass in passes {
189+ run_pass ( * pass) ;
190+ }
191+
192+ mir. phase = mir_phase;
193193 } ;
194194
195- run_passes ( & mut $ mir, None ) ;
195+ run_passes ( mir, None ) ;
196196
197- for ( index, promoted_mir) in $ mir. promoted . iter_enumerated_mut ( ) {
197+ for ( index, promoted_mir) in mir. promoted . iter_enumerated_mut ( ) {
198198 run_passes ( promoted_mir, Some ( index) ) ;
199199
200- // Let's make sure we don't miss any nested instances
201- assert ! ( promoted_mir. promoted. is_empty( ) ) ;
200+ //Let's make sure we don't miss any nested instances
201+ assert ! ( promoted_mir. promoted. is_empty( ) )
202202 }
203- } }
203+ }
204204
205205fn mir_const < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> & ' tcx Steal < Mir < ' tcx > > {
206206 // Unsafety check uses the raw mir, so make sure it is run
207207 let _ = tcx. unsafety_check_result ( def_id) ;
208208
209209 let mut mir = tcx. mir_built ( def_id) . steal ( ) ;
210- run_passes ! [ tcx, mir, def_id, MirPhase :: Const ;
210+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Const , & [
211211 // Remove all `EndRegion` statements that are not involved in borrows.
212- cleanup_post_borrowck:: CleanEndRegions ,
212+ & cleanup_post_borrowck:: CleanEndRegions ,
213213
214214 // What we need to do constant evaluation.
215- simplify:: SimplifyCfg :: new( "initial" ) ,
216- type_check:: TypeckMir ,
217- rustc_peek:: SanityCheck ,
218- uniform_array_move_out:: UniformArrayMoveOut ,
219- ] ;
215+ & simplify:: SimplifyCfg :: new ( "initial" ) ,
216+ & type_check:: TypeckMir ,
217+ & rustc_peek:: SanityCheck ,
218+ & uniform_array_move_out:: UniformArrayMoveOut ,
219+ ] ) ;
220220 tcx. alloc_steal_mir ( mir)
221221}
222222
@@ -229,11 +229,11 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
229229 }
230230
231231 let mut mir = tcx. mir_const ( def_id) . steal ( ) ;
232- run_passes ! [ tcx, mir, def_id, MirPhase :: Validated ;
232+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Validated , & [
233233 // What we need to run borrowck etc.
234- qualify_consts:: QualifyAndPromoteConstants ,
235- simplify:: SimplifyCfg :: new( "qualify-consts" ) ,
236- ] ;
234+ & qualify_consts:: QualifyAndPromoteConstants ,
235+ & simplify:: SimplifyCfg :: new ( "qualify-consts" ) ,
236+ ] ) ;
237237 tcx. alloc_steal_mir ( mir)
238238}
239239
@@ -247,59 +247,59 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
247247 }
248248
249249 let mut mir = tcx. mir_validated ( def_id) . steal ( ) ;
250- run_passes ! [ tcx, mir, def_id, MirPhase :: Optimized ;
250+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Optimized , & [
251251 // Remove all things not needed by analysis
252- no_landing_pads:: NoLandingPads ,
253- simplify_branches:: SimplifyBranches :: new( "initial" ) ,
254- remove_noop_landing_pads:: RemoveNoopLandingPads ,
252+ & no_landing_pads:: NoLandingPads ,
253+ & simplify_branches:: SimplifyBranches :: new ( "initial" ) ,
254+ & remove_noop_landing_pads:: RemoveNoopLandingPads ,
255255 // Remove all `AscribeUserType` statements.
256- cleanup_post_borrowck:: CleanAscribeUserType ,
256+ & cleanup_post_borrowck:: CleanAscribeUserType ,
257257 // Remove all `FakeRead` statements and the borrows that are only
258258 // used for checking matches
259- cleanup_post_borrowck:: CleanFakeReadsAndBorrows ,
260- simplify:: SimplifyCfg :: new( "early-opt" ) ,
259+ & cleanup_post_borrowck:: CleanFakeReadsAndBorrows ,
260+ & simplify:: SimplifyCfg :: new ( "early-opt" ) ,
261261
262262 // These next passes must be executed together
263- add_call_guards:: CriticalCallEdges ,
264- elaborate_drops:: ElaborateDrops ,
265- no_landing_pads:: NoLandingPads ,
263+ & add_call_guards:: CriticalCallEdges ,
264+ & elaborate_drops:: ElaborateDrops ,
265+ & no_landing_pads:: NoLandingPads ,
266266 // AddValidation needs to run after ElaborateDrops and before EraseRegions, and it needs
267267 // an AllCallEdges pass right before it.
268- add_call_guards:: AllCallEdges ,
269- add_validation:: AddValidation ,
268+ & add_call_guards:: AllCallEdges ,
269+ & add_validation:: AddValidation ,
270270 // AddMovesForPackedDrops needs to run after drop
271271 // elaboration.
272- add_moves_for_packed_drops:: AddMovesForPackedDrops ,
272+ & add_moves_for_packed_drops:: AddMovesForPackedDrops ,
273273
274- simplify:: SimplifyCfg :: new( "elaborate-drops" ) ,
274+ & simplify:: SimplifyCfg :: new ( "elaborate-drops" ) ,
275275
276276 // No lifetime analysis based on borrowing can be done from here on out.
277277
278278 // From here on out, regions are gone.
279- erase_regions:: EraseRegions ,
279+ & erase_regions:: EraseRegions ,
280280
281- lower_128bit:: Lower128Bit ,
281+ & lower_128bit:: Lower128Bit ,
282282
283283
284284 // Optimizations begin.
285- uniform_array_move_out:: RestoreSubsliceArrayMoveOut ,
286- inline:: Inline ,
285+ & uniform_array_move_out:: RestoreSubsliceArrayMoveOut ,
286+ & inline:: Inline ,
287287
288288 // Lowering generator control-flow and variables
289289 // has to happen before we do anything else to them.
290- generator:: StateTransform ,
291-
292- instcombine:: InstCombine ,
293- const_prop:: ConstProp ,
294- simplify_branches:: SimplifyBranches :: new( "after-const-prop" ) ,
295- deaggregator:: Deaggregator ,
296- copy_prop:: CopyPropagation ,
297- remove_noop_landing_pads:: RemoveNoopLandingPads ,
298- simplify:: SimplifyCfg :: new( "final" ) ,
299- simplify:: SimplifyLocals ,
300-
301- add_call_guards:: CriticalCallEdges ,
302- dump_mir:: Marker ( "PreCodegen" ) ,
303- ] ;
290+ & generator:: StateTransform ,
291+
292+ & instcombine:: InstCombine ,
293+ & const_prop:: ConstProp ,
294+ & simplify_branches:: SimplifyBranches :: new ( "after-const-prop" ) ,
295+ & deaggregator:: Deaggregator ,
296+ & copy_prop:: CopyPropagation ,
297+ & remove_noop_landing_pads:: RemoveNoopLandingPads ,
298+ & simplify:: SimplifyCfg :: new ( "final" ) ,
299+ & simplify:: SimplifyLocals ,
300+
301+ & add_call_guards:: CriticalCallEdges ,
302+ & dump_mir:: Marker ( "PreCodegen" ) ,
303+ ] ) ;
304304 tcx. alloc_mir ( mir)
305305}
0 commit comments