Skip to content

Commit ef3c5bb

Browse files
committed
Remove deleted docs + better link together MIR traversing docs
1 parent 2724243 commit ef3c5bb

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

compiler/rustc_middle/src/mir/basic_blocks.rs

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ impl<'tcx> BasicBlocks<'tcx> {
6363
}
6464

6565
/// Returns basic blocks in a reverse postorder.
66+
///
67+
/// See [`traverse::reverse_postorder`]'s docs to learn what is preorder traversal.
6668
#[inline]
6769
pub fn reverse_postorder(&self) -> &[BasicBlock] {
6870
self.cache.reverse_postorder.get_or_init(|| {

compiler/rustc_middle/src/mir/traversal.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ impl<'a, 'tcx> Preorder<'a, 'tcx> {
4141
}
4242
}
4343

44+
/// Preorder traversal of a graph.
45+
///
46+
/// This function creates an iterator over the `Body`'s basic blocks, that
47+
/// returns basic blocks in a preorder.
48+
///
49+
/// See [`Preorder`]'s docs to learn what is preorder traversal.
4450
pub fn preorder<'a, 'tcx>(body: &'a Body<'tcx>) -> Preorder<'a, 'tcx> {
4551
Preorder::new(body, START_BLOCK)
4652
}
@@ -213,10 +219,14 @@ impl<'tcx> Iterator for Postorder<'_, 'tcx> {
213219
}
214220
}
215221

216-
/// Creates an iterator over the `Body`'s basic blocks, that:
222+
/// Postorder traversal of a graph.
223+
///
224+
/// This function creates an iterator over the `Body`'s basic blocks, that:
217225
/// - returns basic blocks in a postorder,
218226
/// - traverses the `BasicBlocks` CFG cache's reverse postorder backwards, and does not cache the
219227
/// postorder itself.
228+
///
229+
/// See [`Postorder`]'s docs to learn what is postorder traversal.
220230
pub fn postorder<'a, 'tcx>(
221231
body: &'a Body<'tcx>,
222232
) -> impl Iterator<Item = (BasicBlock, &'a BasicBlockData<'tcx>)> + ExactSizeIterator + DoubleEndedIterator
@@ -241,9 +251,30 @@ pub fn reachable_as_bitset(body: &Body<'_>) -> BitSet<BasicBlock> {
241251
iter.visited
242252
}
243253

244-
/// Creates an iterator over the `Body`'s basic blocks, that:
254+
/// Reverse postorder traversal of a graph.
255+
///
256+
/// This function creates an iterator over the `Body`'s basic blocks, that:
245257
/// - returns basic blocks in a reverse postorder,
246258
/// - makes use of the `BasicBlocks` CFG cache's reverse postorder.
259+
///
260+
/// Reverse postorder is the reverse order of a postorder traversal.
261+
/// This is different to a preorder traversal and represents a natural
262+
/// linearization of control-flow.
263+
///
264+
/// ```text
265+
///
266+
/// A
267+
/// / \
268+
/// / \
269+
/// B C
270+
/// \ /
271+
/// \ /
272+
/// D
273+
/// ```
274+
///
275+
/// A reverse postorder traversal of this graph is either `A B C D` or `A C B D`
276+
/// Note that for a graph containing no loops (i.e., A DAG), this is equivalent to
277+
/// a topological sort.
247278
pub fn reverse_postorder<'a, 'tcx>(
248279
body: &'a Body<'tcx>,
249280
) -> impl Iterator<Item = (BasicBlock, &'a BasicBlockData<'tcx>)> + ExactSizeIterator + DoubleEndedIterator

0 commit comments

Comments
 (0)