@@ -24,40 +24,14 @@ for the alternative lectures.
24
24
25
25
## Defining a Dataflow Analysis
26
26
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
31
30
forward or backward. The domain of your dataflow analysis must be a [ lattice] [ ]
32
31
(strictly speaking a join-semilattice) with a well-behaved ` join ` operator. See
33
32
documentation for the [ ` lattice ` ] module, as well as the [ ` JoinSemiLattice ` ]
34
33
trait, for more information.
35
34
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
-
61
35
### Transfer Functions and Effects
62
36
63
37
The dataflow framework in ` rustc ` allows each statement (and terminator) inside
@@ -69,12 +43,6 @@ particular outgoing edges of some terminators (e.g.
69
43
[ ` apply_call_return_effect ` ] for the ` success ` edge of a ` Call `
70
44
terminator). Collectively, these are referred to as "per-edge effects".
71
45
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
-
78
46
### "Before" Effects
79
47
80
48
Observant readers of the documentation may notice that there are actually * two*
@@ -143,25 +111,16 @@ println!("x: {}", x);
143
111
144
112
## Inspecting the Results of a Dataflow Analysis
145
113
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.
158
121
159
122
``` text
160
123
Analysis
161
- |
162
- | into_engine(…)
163
- |
164
- Engine
165
124
|
166
125
| iterate_to_fixpoint()
167
126
|
@@ -181,9 +140,8 @@ let mut my_visitor = MyVisitor::new();
181
140
182
141
// inspect the fixpoint state for every location within every block in RPO.
183
142
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);`
187
145
```
188
146
189
147
whereas this code uses [ ` ResultsCursor ` ] :
@@ -222,12 +180,10 @@ the example below:
222
180
[ "gen-kill" problems ] : https://en.wikipedia.org/wiki/Data-flow_analysis#Bit_vector_problems
223
181
[ *Static Program Analysis* ] : https://cs.au.dk/~amoeller/spa/
224
182
[ Debugging MIR ] : ./debugging.md
225
- [ `AnalysisDomain` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.AnalysisDomain.html
226
183
[ `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
228
184
[ `GenKillAnalysis` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.GenKillAnalysis.html
229
185
[ `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
231
187
[ `ResultsCursor` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/struct.ResultsCursor.html
232
188
[ `ResultsVisitor` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_dataflow/trait.ResultsVisitor.html
233
189
[ `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