Skip to content

Commit 2d1a047

Browse files
authored
Update for recent dataflow simplifications. (rust-lang#2121)
1 parent a54fe75 commit 2d1a047

File tree

2 files changed

+16
-60
lines changed

2 files changed

+16
-60
lines changed

Diff for: src/borrow_check/moves_and_initialization/move_paths.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ move_data.move_paths[mpi].place
5454
One of the first things we do in the MIR borrow check is to construct
5555
the set of move paths. This is done as part of the
5656
[`MoveData::gather_moves`] function. This function uses a MIR visitor
57-
called [`Gatherer`] to walk the MIR and look at how each [`Place`]
57+
called [`MoveDataBuilder`] to walk the MIR and look at how each [`Place`]
5858
within is accessed. For each such [`Place`], it constructs a
5959
corresponding [`MovePathIndex`]. It also records when/where that
6060
particular move path is moved/initialized, but we'll get to that in a
6161
later section.
6262

63-
[`Gatherer`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/move_paths/builder/struct.Gatherer.html
63+
[`MoveDataBuilder`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/move_paths/builder/struct.MoveDataBuilder.html
6464
[`MoveData::gather_moves`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/move_paths/struct.MoveData.html#method.gather_moves
6565

6666
### Illegal move paths
@@ -82,7 +82,7 @@ those just discussed, the function returns an `Err`. This in turn
8282
means we don't have to bother tracking whether those places are
8383
initialized (which lowers overhead).
8484

85-
[`move_path_for`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/move_paths/builder/struct.Gatherer.html#method.move_path_for
85+
[`move_path_for`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/move_paths/builder/struct.MoveDataBuilder.html#method.move_path_for
8686

8787
## Looking up a move-path
8888

Diff for: src/mir/dataflow.md

+13-57
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,14 @@ for the alternative lectures.
2424

2525
## Defining a Dataflow Analysis
2626

27-
The interface for dataflow analyses is split into three traits. The first is
28-
[`AnalysisDomain`], which must be implemented by *all* analyses. In addition to
29-
the type of the dataflow state, this trait defines the initial value of that
30-
state at entry to each block, as well as the direction of the analysis, either
27+
A dataflow analysis is defined by the [`Analysis`] trait. In addition to the
28+
type of the dataflow state, this trait defines the initial value of that state
29+
at entry to each block, as well as the direction of the analysis, either
3130
forward or backward. The domain of your dataflow analysis must be a [lattice][]
3231
(strictly speaking a join-semilattice) with a well-behaved `join` operator. See
3332
documentation for the [`lattice`] module, as well as the [`JoinSemiLattice`]
3433
trait, for more information.
3534

36-
You must then provide *either* a direct implementation of the [`Analysis`] trait
37-
*or* an implementation of the proxy trait [`GenKillAnalysis`]. The latter is for
38-
so-called ["gen-kill" problems], which have a simple class of transfer function
39-
that can be applied very efficiently. Analyses whose domain is not a `BitSet`
40-
of some index type, or whose transfer functions cannot be expressed through
41-
"gen" and "kill" operations, must implement `Analysis` directly, and will run
42-
slower as a result. All implementers of `GenKillAnalysis` also implement
43-
`Analysis` automatically via a default `impl`.
44-
45-
46-
```text
47-
AnalysisDomain
48-
^
49-
| | = has as a supertrait
50-
| . = provides a default impl for
51-
|
52-
Analysis
53-
^ ^
54-
| .
55-
| .
56-
| .
57-
GenKillAnalysis
58-
59-
```
60-
6135
### Transfer Functions and Effects
6236

6337
The dataflow framework in `rustc` allows each statement (and terminator) inside
@@ -69,12 +43,6 @@ particular outgoing edges of some terminators (e.g.
6943
[`apply_call_return_effect`] for the `success` edge of a `Call`
7044
terminator). Collectively, these are referred to as "per-edge effects".
7145

72-
The only meaningful difference (besides the "apply" prefix) between the methods
73-
of the `GenKillAnalysis` trait and the `Analysis` trait is that an `Analysis`
74-
has direct, mutable access to the dataflow state, whereas a `GenKillAnalysis`
75-
only sees an implementer of the `GenKill` trait, which only allows the `gen`
76-
and `kill` operations for mutation.
77-
7846
### "Before" Effects
7947

8048
Observant readers of the documentation may notice that there are actually *two*
@@ -143,25 +111,16 @@ println!("x: {}", x);
143111

144112
## Inspecting the Results of a Dataflow Analysis
145113

146-
Once you have constructed an analysis, you must pass it to an [`Engine`], which
147-
is responsible for finding the steady-state solution to your dataflow problem.
148-
You should use the [`into_engine`] method defined on the `Analysis` trait for
149-
this, since it will use the more efficient `Engine::new_gen_kill` constructor
150-
when possible.
151-
152-
Calling `iterate_to_fixpoint` on your `Engine` will return a `Results`, which
153-
contains the dataflow state at fixpoint upon entry of each block. Once you have
154-
a `Results`, you can inspect the dataflow state at fixpoint at any point in
155-
the CFG. If you only need the state at a few locations (e.g., each `Drop`
156-
terminator) use a [`ResultsCursor`]. If you need the state at *every* location,
157-
a [`ResultsVisitor`] will be more efficient.
114+
Once you have constructed an analysis, you must call `iterate_to_fixpoint`
115+
which will return a `Results`, which contains the dataflow state at fixpoint
116+
upon entry of each block. Once you have a `Results`, you can inspect the
117+
dataflow state at fixpoint at any point in the CFG. If you only need the state
118+
at a few locations (e.g., each `Drop` terminator) use a [`ResultsCursor`]. If
119+
you need the state at *every* location, a [`ResultsVisitor`] will be more
120+
efficient.
158121

159122
```text
160123
Analysis
161-
|
162-
| into_engine(…)
163-
|
164-
Engine
165124
|
166125
| iterate_to_fixpoint()
167126
|
@@ -181,9 +140,8 @@ let mut my_visitor = MyVisitor::new();
181140
182141
// inspect the fixpoint state for every location within every block in RPO.
183142
let results = MyAnalysis::new()
184-
.into_engine(tcx, body, def_id)
185-
.iterate_to_fixpoint()
186-
.visit_in_rpo_with(body, &mut my_visitor);
143+
.iterate_to_fixpoint(tcx, body, None);
144+
results.visit_with(body, &mut my_visitor);`
187145
```
188146

189147
whereas this code uses [`ResultsCursor`]:
@@ -222,12 +180,10 @@ the example below:
222180
["gen-kill" problems]: https://en.wikipedia.org/wiki/Data-flow_analysis#Bit_vector_problems
223181
[*Static Program Analysis*]: https://cs.au.dk/~amoeller/spa/
224182
[Debugging MIR]: ./debugging.md
225-
[`AnalysisDomain`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.AnalysisDomain.html
226183
[`Analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.Analysis.html
227-
[`Engine`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/struct.Engine.html
228184
[`GenKillAnalysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.GenKillAnalysis.html
229185
[`JoinSemiLattice`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/lattice/trait.JoinSemiLattice.html
230-
[`NAME`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.AnalysisDomain.html#associatedconstant.NAME
186+
[`NAME`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.Analysis.html#associatedconstant.NAME
231187
[`ResultsCursor`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/struct.ResultsCursor.html
232188
[`ResultsVisitor`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.ResultsVisitor.html
233189
[`apply_call_return_effect`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.Analysis.html#tymethod.apply_call_return_effect

0 commit comments

Comments
 (0)