@@ -295,34 +295,11 @@ pub fn reachable_as_bitset(body: &Body<'_>) -> BitSet<BasicBlock> {
295
295
iter. visited
296
296
}
297
297
298
- #[ derive( Clone ) ]
299
- pub struct ReversePostorderIter < ' a , ' tcx > {
298
+ /// Creates an iterator over the `Body`'s basic blocks, that:
299
+ /// - returns basic blocks in a reverse postorder,
300
+ /// - makes use of the `BasicBlocks` CFG cache's reverse postorder.
301
+ pub fn reverse_postorder < ' a , ' tcx > (
300
302
body : & ' a Body < ' tcx > ,
301
- blocks : & ' a [ BasicBlock ] ,
302
- idx : usize ,
303
- }
304
-
305
- impl < ' a , ' tcx > Iterator for ReversePostorderIter < ' a , ' tcx > {
306
- type Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) ;
307
-
308
- fn next ( & mut self ) -> Option < ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > {
309
- if self . idx == 0 {
310
- return None ;
311
- }
312
- self . idx -= 1 ;
313
-
314
- self . blocks . get ( self . idx ) . map ( |& bb| ( bb, & self . body [ bb] ) )
315
- }
316
-
317
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
318
- ( self . idx , Some ( self . idx ) )
319
- }
320
- }
321
-
322
- impl < ' a , ' tcx > ExactSizeIterator for ReversePostorderIter < ' a , ' tcx > { }
323
-
324
- pub fn reverse_postorder < ' a , ' tcx > ( body : & ' a Body < ' tcx > ) -> ReversePostorderIter < ' a , ' tcx > {
325
- let blocks = body. basic_blocks . postorder ( ) ;
326
- let len = blocks. len ( ) ;
327
- ReversePostorderIter { body, blocks, idx : len }
303
+ ) -> impl Iterator < Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > + ExactSizeIterator {
304
+ body. basic_blocks . reverse_postorder ( ) . iter ( ) . map ( |& bb| ( bb, & body. basic_blocks [ bb] ) )
328
305
}
0 commit comments