Skip to content

Commit 5d17f08

Browse files
Rollup merge of #153432 - nnethercote:dataflow-comments, r=cjgillot
Fix some comments about dataflow analysis. Mostly in the examples in `initialized.rs`. In particular, the `EverInitializedPlaces` example currently doesn't cover how it's initialization sites that are tracked, rather than local variables (that's the `b_0`/`b_1` distinction in the example.) r? @cjgillot
2 parents 0102e91 + 1f94e97 commit 5d17f08

2 files changed

Lines changed: 29 additions & 27 deletions

File tree

compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> BasicBlocks<'tcx> {
6565

6666
/// Returns basic blocks in a reverse postorder.
6767
///
68-
/// See [`traversal::reverse_postorder`]'s docs to learn what is preorder traversal.
68+
/// See [`traversal::reverse_postorder`]'s docs to learn what is postorder traversal.
6969
///
7070
/// [`traversal::reverse_postorder`]: crate::mir::traversal::reverse_postorder
7171
#[inline]

compiler/rustc_mir_dataflow/src/impls/initialized.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,21 @@ impl<'tcx> MaybePlacesSwitchIntData<'tcx> {
109109
/// ```rust
110110
/// struct S;
111111
/// #[rustfmt::skip]
112-
/// fn foo(pred: bool) { // maybe-init:
113-
/// // {}
114-
/// let a = S; let mut b = S; let c; let d; // {a, b}
112+
/// fn foo(p: bool) { // maybe-init:
113+
/// // {p}
114+
/// let a = S; let mut b = S; let c; let d; // {p, a, b}
115115
///
116-
/// if pred {
117-
/// drop(a); // { b}
118-
/// b = S; // { b}
116+
/// if p {
117+
/// drop(a); // {p, b}
118+
/// b = S; // {p, b}
119119
///
120120
/// } else {
121-
/// drop(b); // {a}
122-
/// d = S; // {a, d}
121+
/// drop(b); // {p, a}
122+
/// d = S; // {p, a, d}
123123
///
124-
/// } // {a, b, d}
124+
/// } // {p, a, b, d}
125125
///
126-
/// c = S; // {a, b, c, d}
126+
/// c = S; // {p, a, b, c, d}
127127
/// }
128128
/// ```
129129
///
@@ -199,11 +199,11 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'tcx> {
199199
/// ```rust
200200
/// struct S;
201201
/// #[rustfmt::skip]
202-
/// fn foo(pred: bool) { // maybe-uninit:
202+
/// fn foo(p: bool) { // maybe-uninit:
203203
/// // {a, b, c, d}
204204
/// let a = S; let mut b = S; let c; let d; // { c, d}
205205
///
206-
/// if pred {
206+
/// if p {
207207
/// drop(a); // {a, c, d}
208208
/// b = S; // {a, c, d}
209209
///
@@ -279,34 +279,36 @@ impl<'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
279279
}
280280
}
281281

282-
/// `EverInitializedPlaces` tracks all places that might have ever been
283-
/// initialized upon reaching a particular point in the control flow
284-
/// for a function, without an intervening `StorageDead`.
282+
/// `EverInitializedPlaces` tracks all initializations that may have occurred
283+
/// upon reaching a particular point in the control flow for a function,
284+
/// without an intervening `StorageDead`.
285285
///
286286
/// This dataflow is used to determine if an immutable local variable may
287287
/// be assigned to.
288288
///
289289
/// For example, in code like the following, we have corresponding
290-
/// dataflow information shown in the right-hand comments.
290+
/// dataflow information shown in the right-hand comments. Underscored indices
291+
/// are used to distinguish between multiple initializations of the same local
292+
/// variable, e.g. `b_0` and `b_1`.
291293
///
292294
/// ```rust
293295
/// struct S;
294296
/// #[rustfmt::skip]
295-
/// fn foo(pred: bool) { // ever-init:
296-
/// // { }
297-
/// let a = S; let mut b = S; let c; let d; // {a, b }
297+
/// fn foo(p: bool) { // ever-init:
298+
/// // {p, }
299+
/// let a = S; let mut b = S; let c; let d; // {p, a, b_0, }
298300
///
299-
/// if pred {
300-
/// drop(a); // {a, b, }
301-
/// b = S; // {a, b, }
301+
/// if p {
302+
/// drop(a); // {p, a, b_0, }
303+
/// b = S; // {p, a, b_0, b_1, }
302304
///
303305
/// } else {
304-
/// drop(b); // {a, b, }
305-
/// d = S; // {a, b, d }
306+
/// drop(b); // {p, a, b_0, b_1, }
307+
/// d = S; // {p, a, b_0, b_1, d}
306308
///
307-
/// } // {a, b, d }
309+
/// } // {p, a, b_0, b_1, d}
308310
///
309-
/// c = S; // {a, b, c, d }
311+
/// c = S; // {p, a, b_0, b_1, c, d}
310312
/// }
311313
/// ```
312314
pub struct EverInitializedPlaces<'a, 'tcx> {

0 commit comments

Comments
 (0)