Skip to content

Commit 39b9a25

Browse files
authored
Rollup merge of #76732 - camelid:mir-basic-block-docs, r=RalfJung
Add docs for `BasicBlock` Fixes #76715. --- @rustbot modify labels: A-mir T-doc C-enhancement
2 parents 41507ed + 451f7f6 commit 39b9a25

File tree

1 file changed

+20
-0
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+20
-0
lines changed

compiler/rustc_middle/src/mir/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,25 @@ pub struct VarDebugInfo<'tcx> {
10771077
// BasicBlock
10781078

10791079
rustc_index::newtype_index! {
1080+
/// A node in the MIR [control-flow graph][CFG].
1081+
///
1082+
/// There are no branches (e.g., `if`s, function calls, etc.) within a basic block, which makes
1083+
/// it easier to do [data-flow analyses] and optimizations. Instead, branches are represented
1084+
/// as an edge in a graph between basic blocks.
1085+
///
1086+
/// Basic blocks consist of a series of [statements][Statement], ending with a
1087+
/// [terminator][Terminator]. Basic blocks can have multiple predecessors and successors,
1088+
/// however there is a MIR pass ([`CriticalCallEdges`]) that removes *critical edges*, which
1089+
/// are edges that go from a multi-successor node to a multi-predecessor node. This pass is
1090+
/// needed because some analyses require that there are no critical edges in the CFG.
1091+
///
1092+
/// Read more about basic blocks in the [rustc-dev-guide][guide-mir].
1093+
///
1094+
/// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg
1095+
/// [data-flow analyses]:
1096+
/// https://rustc-dev-guide.rust-lang.org/appendix/background.html#what-is-a-dataflow-analysis
1097+
/// [`CriticalCallEdges`]: ../../rustc_mir/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
1098+
/// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/
10801099
pub struct BasicBlock {
10811100
derive [HashStable]
10821101
DEBUG_FORMAT = "bb{}",
@@ -1093,6 +1112,7 @@ impl BasicBlock {
10931112
///////////////////////////////////////////////////////////////////////////
10941113
// BasicBlockData and Terminator
10951114

1115+
/// See [`BasicBlock`] for documentation on what basic blocks are at a high level.
10961116
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
10971117
pub struct BasicBlockData<'tcx> {
10981118
/// List of statements in this block.

0 commit comments

Comments
 (0)