@@ -226,64 +226,6 @@ pub fn postorder<'a, 'tcx>(
226226 reverse_postorder ( body) . rev ( )
227227}
228228
229- /// Reverse postorder traversal of a graph
230- ///
231- /// Reverse postorder is the reverse order of a postorder traversal.
232- /// This is different to a preorder traversal and represents a natural
233- /// linearization of control-flow.
234- ///
235- /// ```text
236- ///
237- /// A
238- /// / \
239- /// / \
240- /// B C
241- /// \ /
242- /// \ /
243- /// D
244- /// ```
245- ///
246- /// A reverse postorder traversal of this graph is either `A B C D` or `A C B D`
247- /// Note that for a graph containing no loops (i.e., A DAG), this is equivalent to
248- /// a topological sort.
249- ///
250- /// Construction of a `ReversePostorder` traversal requires doing a full
251- /// postorder traversal of the graph, therefore this traversal should be
252- /// constructed as few times as possible.
253- #[ derive( Clone ) ]
254- pub struct ReversePostorder < ' a , ' tcx > {
255- body : & ' a Body < ' tcx > ,
256- blocks : Vec < BasicBlock > ,
257- idx : usize ,
258- }
259-
260- impl < ' a , ' tcx > ReversePostorder < ' a , ' tcx > {
261- pub fn new ( body : & ' a Body < ' tcx > , root : BasicBlock ) -> ReversePostorder < ' a , ' tcx > {
262- let blocks: Vec < _ > = Postorder :: new ( & body. basic_blocks , root) . map ( |( bb, _) | bb) . collect ( ) ;
263- let len = blocks. len ( ) ;
264- ReversePostorder { body, blocks, idx : len }
265- }
266- }
267-
268- impl < ' a , ' tcx > Iterator for ReversePostorder < ' a , ' tcx > {
269- type Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) ;
270-
271- fn next ( & mut self ) -> Option < ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > {
272- if self . idx == 0 {
273- return None ;
274- }
275- self . idx -= 1 ;
276-
277- self . blocks . get ( self . idx ) . map ( |& bb| ( bb, & self . body [ bb] ) )
278- }
279-
280- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
281- ( self . idx , Some ( self . idx ) )
282- }
283- }
284-
285- impl < ' a , ' tcx > ExactSizeIterator for ReversePostorder < ' a , ' tcx > { }
286-
287229/// Returns an iterator over all basic blocks reachable from the `START_BLOCK` in no particular
288230/// order.
289231///
0 commit comments