Expand description
A framework that can express both gen-kill and generic dataflow problems.
To use this framework, implement the Analysis trait. There used to be a GenKillAnalysis
alternative trait for gen-kill analyses that would pre-compute the transfer function for each
block. It was intended as an optimization, but it ended up not being any faster than
Analysis.
The impls module contains several examples of dataflow analyses.
Then call iterate_to_fixpoint on your type that impls Analysis to get a Results. From
there, you can use a ResultsCursor to inspect the fixpoint solution to your dataflow problem
(good for inspecting a small number of locations), or implement the ResultsVisitor interface
and use visit_results (good for inspecting many or all locations). The following example uses
the ResultsCursor approach.
use rustc_const_eval::dataflow::Analysis; // Makes `iterate_to_fixpoint` available.
fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) {
let analysis = MyAnalysis::new()
.iterate_to_fixpoint(tcx, body, None)
.into_results_cursor(body);
// Print the dataflow state *after* each statement in the start block.
for (_, statement_index) in body.block_data[START_BLOCK].statements.iter_enumerated() {
cursor.seek_after(Location { block: START_BLOCK, statement_index });
let state = cursor.get();
println!("{:?}", state);
}
}Re-exportsยง
pub use self::cursor::ResultsCursor;pub use self::direction::Backward;pub use self::direction::Direction;pub use self::direction::Forward;pub use self::lattice::JoinSemiLattice;pub use self::lattice::MaybeReachable;pub use self::results::Results;pub use self::visitor::ResultsVisitor;pub use self::visitor::visit_reachable_results;pub use self::visitor::visit_results;
Modulesยง
- cursor ๐
- Random access inspection of the results of a dataflow analysis.
- direction ๐
- fmt
- Custom formatting traits used when outputting Graphviz diagrams with the results of a dataflow analysis.
- graphviz
- A helpful diagram for debugging dataflow problems.
- lattice
- Traits used to represent lattices for use as the domain of a dataflow analysis.
- results ๐
- Dataflow analysis results.
- visitor ๐
Structsยง
Enumsยง
- Effect ๐