Skip to content

Commit 08a9f25

Browse files
committed
remove redundant combinators between PO and RPO
1 parent f134101 commit 08a9f25

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

compiler/rustc_middle/src/mir/traversal.rs

+6-30
Original file line numberDiff line numberDiff line change
@@ -219,38 +219,13 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> {
219219
/// - returns basic blocks in a postorder,
220220
/// - traverses the `BasicBlocks` CFG cache's reverse postorder backwards, and does not cache the
221221
/// postorder itself.
222-
pub fn postorder<'a, 'tcx>(body: &'a Body<'tcx>) -> PostorderIter<'a, 'tcx> {
223-
let blocks = body.basic_blocks.reverse_postorder();
224-
let len = blocks.len();
225-
PostorderIter { body, blocks, idx: len }
226-
}
227-
228-
#[derive(Clone)]
229-
pub struct PostorderIter<'a, 'tcx> {
222+
pub fn postorder<'a, 'tcx>(
230223
body: &'a Body<'tcx>,
231-
blocks: &'a [BasicBlock],
232-
idx: usize,
224+
) -> impl Iterator<Item = (BasicBlock, &'a BasicBlockData<'tcx>)> + ExactSizeIterator + DoubleEndedIterator
225+
{
226+
reverse_postorder(body).rev()
233227
}
234228

235-
impl<'a, 'tcx> Iterator for PostorderIter<'a, 'tcx> {
236-
type Item = (BasicBlock, &'a BasicBlockData<'tcx>);
237-
238-
fn next(&mut self) -> Option<(BasicBlock, &'a BasicBlockData<'tcx>)> {
239-
if self.idx == 0 {
240-
return None;
241-
}
242-
self.idx -= 1;
243-
244-
self.blocks.get(self.idx).map(|&bb| (bb, &self.body[bb]))
245-
}
246-
247-
fn size_hint(&self) -> (usize, Option<usize>) {
248-
(self.idx, Some(self.idx))
249-
}
250-
}
251-
252-
impl<'a, 'tcx> ExactSizeIterator for PostorderIter<'a, 'tcx> {}
253-
254229
/// Reverse postorder traversal of a graph
255230
///
256231
/// Reverse postorder is the reverse order of a postorder traversal.
@@ -332,6 +307,7 @@ pub fn reachable_as_bitset(body: &Body<'_>) -> BitSet<BasicBlock> {
332307
/// - makes use of the `BasicBlocks` CFG cache's reverse postorder.
333308
pub fn reverse_postorder<'a, 'tcx>(
334309
body: &'a Body<'tcx>,
335-
) -> impl Iterator<Item = (BasicBlock, &'a BasicBlockData<'tcx>)> + ExactSizeIterator {
310+
) -> impl Iterator<Item = (BasicBlock, &'a BasicBlockData<'tcx>)> + ExactSizeIterator + DoubleEndedIterator
311+
{
336312
body.basic_blocks.reverse_postorder().iter().map(|&bb| (bb, &body.basic_blocks[bb]))
337313
}

0 commit comments

Comments
 (0)