Skip to content

Commit fe0e7c3

Browse files
Update framework module docs
1 parent 7108cea commit fe0e7c3

File tree

1 file changed

+15
-17
lines changed
  • src/librustc_mir/dataflow/framework

1 file changed

+15
-17
lines changed

src/librustc_mir/dataflow/framework/mod.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
//! A framework that can express both [gen-kill] and generic dataflow problems.
22
//!
3-
//! There is another interface for dataflow in the compiler in `librustc_mir/dataflow/mod.rs`. The
4-
//! interface in this module will eventually [replace that one][design-meeting].
3+
//! To actually use this framework, you must implement either the `Analysis` or the
4+
//! `GenKillAnalysis` trait. If your transfer function can be expressed with only gen/kill
5+
//! operations, prefer `GenKillAnalysis` since it will run faster while iterating to fixpoint. The
6+
//! `impls` module contains several examples of gen/kill dataflow analyses.
57
//!
6-
//! To actually use this framework, you must implement either the `Analysis` or the `GenKillAnalysis`
7-
//! trait. If your transfer function can be expressed with only gen/kill operations, prefer
8-
//! `GenKillAnalysis` since it will run faster while iterating to fixpoint. Create an `Engine` using
9-
//! the appropriate constructor and call `iterate_to_fixpoint`. You can use a `ResultsCursor` to
10-
//! inspect the fixpoint solution to your dataflow problem.
8+
//! Create an `Engine` for your analysis using the `into_engine` method on the `Analysis` trait,
9+
//! then call `iterate_to_fixpoint`. From there, you can use a `ResultsCursor` to inspect the
10+
//! fixpoint solution to your dataflow problem, or implement the `ResultsVisitor` interface and use
11+
//! `visit_results`. The following example uses the `ResultsCursor` approach.
1112
//!
1213
//! ```ignore(cross-crate-imports)
13-
//! fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>, did: DefId) {
14-
//! let analysis = MyAnalysis::new();
15-
//!
16-
//! // If `MyAnalysis` implements `GenKillAnalysis`.
17-
//! let results = Engine::new_gen_kill(tcx, body, did, analysis).iterate_to_fixpoint();
14+
//! use rustc_mir::dataflow::Analysis; // Makes `into_engine` available.
1815
//!
19-
//! // If `MyAnalysis` implements `Analysis`.
20-
//! // let results = Engine::new_generic(tcx, body, did, analysis).iterate_to_fixpoint();
21-
//!
22-
//! let mut cursor = ResultsCursor::new(body, results);
16+
//! fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>, did: DefId) {
17+
//! let analysis = MyAnalysis::new()
18+
//! .into_engine(tcx, body, did)
19+
//! .iterate_to_fixpoint()
20+
//! .into_results_cursor(body);
2321
//!
22+
//! // Print the dataflow state *after* each statement in the start block.
2423
//! for (_, statement_index) in body.block_data[START_BLOCK].statements.iter_enumerated() {
2524
//! cursor.seek_after(Location { block: START_BLOCK, statement_index });
2625
//! let state = cursor.get();
@@ -30,7 +29,6 @@
3029
//! ```
3130
//!
3231
//! [gen-kill]: https://en.wikipedia.org/wiki/Data-flow_analysis#Bit_vector_problems
33-
//! [design-meeting]https://github.com/rust-lang/compiler-team/issues/202
3432
3533
use std::io;
3634

0 commit comments

Comments
 (0)