@@ -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
3130forward 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
3332documentation for the [ ` lattice ` ] module, as well as the [ ` JoinSemiLattice ` ]
3433trait, 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
6337The 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 `
7044terminator). 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
8048Observant 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.
183142let 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
189147whereas 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