Skip to content

Commit 2ce7b61

Browse files
Explain motivation for GenKill trait
1 parent be730e1 commit 2ce7b61

File tree

1 file changed

+12
-4
lines changed
  • src/librustc_mir/dataflow/generic

1 file changed

+12
-4
lines changed

src/librustc_mir/dataflow/generic/mod.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
//! There is another interface for dataflow in the compiler in `librustc_mir/dataflow/mod.rs`. The
44
//! interface in this module will eventually [replace that one][design-meeting].
55
//!
6-
//! To actually use this framework, you must implement either the `Analysis` or the
7-
//! `GenKillAnalysis` trait. If your transfer function can be expressed with only gen/kill
8-
//! operations, prefer `GenKillAnalysis` as it will perform better. Create an `Engine` using the
9-
//! appropriate constructor and call `iterate_to_fixpoint`. You can use a `ResultsCursor` to
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
1010
//! inspect the fixpoint solution to your dataflow problem.
1111
//!
1212
//! ```ignore(cross-crate-imports)
@@ -273,6 +273,14 @@ where
273273
}
274274

275275
/// The legal operations for a transfer function in a gen/kill problem.
276+
///
277+
/// This abstraction exists because there are two different contexts in which we call the methods in
278+
/// `GenKillAnalysis`. Sometimes we need to store a single transfer function that can be efficiently
279+
/// applied multiple times, such as when computing the cumulative transfer function for each block.
280+
/// These cases require a `GenKillSet`, which in turn requires two `BitSet`s of storage. Oftentimes,
281+
/// however, we only need to apply an effect once. In *these* cases, it is more efficient to pass the
282+
/// `BitSet` representing the state vector directly into the `*_effect` methods as opposed to
283+
/// building up a `GenKillSet` and then throwing it away.
276284
pub trait GenKill<T> {
277285
/// Inserts `elem` into the state vector.
278286
fn gen(&mut self, elem: T);

0 commit comments

Comments
 (0)