@@ -104,29 +104,23 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
104104/// ```
105105///
106106/// A Postorder traversal of this graph is `D B C A` or `D C B A`
107- pub struct Postorder < ' a , ' tcx , C > {
107+ pub struct Postorder < ' a , ' tcx > {
108108 basic_blocks : & ' a IndexSlice < BasicBlock , BasicBlockData < ' tcx > > ,
109109 visited : BitSet < BasicBlock > ,
110110 visit_stack : Vec < ( BasicBlock , Successors < ' a > ) > ,
111111 root_is_start_block : bool ,
112- extra : C ,
113112}
114113
115- impl < ' a , ' tcx , C > Postorder < ' a , ' tcx , C >
116- where
117- C : Customization < ' tcx > ,
118- {
114+ impl < ' a , ' tcx > Postorder < ' a , ' tcx > {
119115 pub fn new (
120116 basic_blocks : & ' a IndexSlice < BasicBlock , BasicBlockData < ' tcx > > ,
121117 root : BasicBlock ,
122- extra : C ,
123- ) -> Postorder < ' a , ' tcx , C > {
118+ ) -> Postorder < ' a , ' tcx > {
124119 let mut po = Postorder {
125120 basic_blocks,
126121 visited : BitSet :: new_empty ( basic_blocks. len ( ) ) ,
127122 visit_stack : Vec :: new ( ) ,
128123 root_is_start_block : root == START_BLOCK ,
129- extra,
130124 } ;
131125
132126 po. visit ( root) ;
@@ -140,7 +134,7 @@ where
140134 return ;
141135 }
142136 let data = & self . basic_blocks [ bb] ;
143- let successors = C :: successors ( data, self . extra ) ;
137+ let successors = data. terminator ( ) . successors ( ) ;
144138 self . visit_stack . push ( ( bb, successors) ) ;
145139 }
146140
@@ -198,10 +192,7 @@ where
198192 }
199193}
200194
201- impl < ' tcx , C > Iterator for Postorder < ' _ , ' tcx , C >
202- where
203- C : Customization < ' tcx > ,
204- {
195+ impl < ' tcx > Iterator for Postorder < ' _ , ' tcx > {
205196 type Item = BasicBlock ;
206197
207198 fn next ( & mut self ) -> Option < BasicBlock > {
@@ -252,29 +243,6 @@ impl<'tcx> Customization<'tcx> for () {
252243 }
253244}
254245
255- impl < ' tcx > Customization < ' tcx > for ( TyCtxt < ' tcx > , Instance < ' tcx > ) {
256- fn successors < ' a > (
257- data : & ' a BasicBlockData < ' tcx > ,
258- ( tcx, instance) : ( TyCtxt < ' tcx > , Instance < ' tcx > ) ,
259- ) -> Successors < ' a > {
260- data. mono_successors ( tcx, instance)
261- }
262- }
263-
264- pub fn mono_reachable_reverse_postorder < ' a , ' tcx > (
265- body : & ' a Body < ' tcx > ,
266- tcx : TyCtxt < ' tcx > ,
267- instance : Instance < ' tcx > ,
268- ) -> Vec < BasicBlock > {
269- let mut iter = Postorder :: new ( & body. basic_blocks , START_BLOCK , ( tcx, instance) ) ;
270- let mut items = Vec :: with_capacity ( body. basic_blocks . len ( ) ) ;
271- while let Some ( block) = iter. next ( ) {
272- items. push ( block) ;
273- }
274- items. reverse ( ) ;
275- items
276- }
277-
278246/// Returns an iterator over all basic blocks reachable from the `START_BLOCK` in no particular
279247/// order.
280248///
@@ -322,91 +290,3 @@ pub fn reverse_postorder<'a, 'tcx>(
322290{
323291 body. basic_blocks . reverse_postorder ( ) . iter ( ) . map ( |& bb| ( bb, & body. basic_blocks [ bb] ) )
324292}
325-
326- /// Traversal of a [`Body`] that tries to avoid unreachable blocks in a monomorphized [`Instance`].
327- ///
328- /// This is allowed to have false positives; blocks may be visited even if they are not actually
329- /// reachable.
330- ///
331- /// Such a traversal is mostly useful because it lets us skip lowering the `false` side
332- /// of `if <T as Trait>::CONST`, as well as [`NullOp::UbChecks`].
333- ///
334- /// [`NullOp::UbChecks`]: rustc_middle::mir::NullOp::UbChecks
335- pub fn mono_reachable < ' a , ' tcx > (
336- body : & ' a Body < ' tcx > ,
337- tcx : TyCtxt < ' tcx > ,
338- instance : Instance < ' tcx > ,
339- ) -> MonoReachable < ' a , ' tcx > {
340- MonoReachable :: new ( body, tcx, instance)
341- }
342-
343- /// [`MonoReachable`] internally accumulates a [`BitSet`] of visited blocks. This is just a
344- /// convenience function to run that traversal then extract its set of reached blocks.
345- pub fn mono_reachable_as_bitset < ' a , ' tcx > (
346- body : & ' a Body < ' tcx > ,
347- tcx : TyCtxt < ' tcx > ,
348- instance : Instance < ' tcx > ,
349- ) -> BitSet < BasicBlock > {
350- let mut iter = mono_reachable ( body, tcx, instance) ;
351- while let Some ( _) = iter. next ( ) { }
352- iter. visited
353- }
354-
355- pub struct MonoReachable < ' a , ' tcx > {
356- body : & ' a Body < ' tcx > ,
357- tcx : TyCtxt < ' tcx > ,
358- instance : Instance < ' tcx > ,
359- visited : BitSet < BasicBlock > ,
360- // Other traversers track their worklist in a Vec. But we don't care about order, so we can
361- // store ours in a BitSet and thus save allocations because BitSet has a small size
362- // optimization.
363- worklist : BitSet < BasicBlock > ,
364- }
365-
366- impl < ' a , ' tcx > MonoReachable < ' a , ' tcx > {
367- pub fn new (
368- body : & ' a Body < ' tcx > ,
369- tcx : TyCtxt < ' tcx > ,
370- instance : Instance < ' tcx > ,
371- ) -> MonoReachable < ' a , ' tcx > {
372- let mut worklist = BitSet :: new_empty ( body. basic_blocks . len ( ) ) ;
373- worklist. insert ( START_BLOCK ) ;
374- MonoReachable {
375- body,
376- tcx,
377- instance,
378- visited : BitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
379- worklist,
380- }
381- }
382-
383- fn add_work ( & mut self , blocks : impl IntoIterator < Item = BasicBlock > ) {
384- for block in blocks. into_iter ( ) {
385- if !self . visited . contains ( block) {
386- self . worklist . insert ( block) ;
387- }
388- }
389- }
390- }
391-
392- impl < ' a , ' tcx > Iterator for MonoReachable < ' a , ' tcx > {
393- type Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) ;
394-
395- fn next ( & mut self ) -> Option < ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > {
396- while let Some ( idx) = self . worklist . iter ( ) . next ( ) {
397- self . worklist . remove ( idx) ;
398- if !self . visited . insert ( idx) {
399- continue ;
400- }
401-
402- let data = & self . body [ idx] ;
403-
404- let targets = data. mono_successors ( self . tcx , self . instance ) ;
405- self . add_work ( targets) ;
406-
407- return Some ( ( idx, data) ) ;
408- }
409-
410- None
411- }
412- }
0 commit comments