@@ -60,9 +60,10 @@ pub use self::visitor::{BorrowckFlowState, BorrowckResults};
6060/// This trait specifies the lattice on which this analysis operates (the domain) as well as its
6161/// initial value at the entry point of each basic block.
6262pub trait AnalysisDomain < ' tcx > {
63+ /// The type that holds the dataflow state at any given point in the program.
6364 type Domain : Clone + JoinSemiLattice ;
6465
65- /// The direction of this analyis . Either `Forward` or `Backward`.
66+ /// The direction of this analysis . Either `Forward` or `Backward`.
6667 type Direction : Direction = Forward ;
6768
6869 /// A descriptive name for this analysis. Used only for debugging.
@@ -71,10 +72,10 @@ pub trait AnalysisDomain<'tcx> {
7172 /// suitable as part of a filename.
7273 const NAME : & ' static str ;
7374
75+ /// The initial value of the dataflow state upon entry to each basic block.
7476 fn bottom_value ( & self , body : & mir:: Body < ' tcx > ) -> Self :: Domain ;
7577
76- /// Mutates the entry set of the `START_BLOCK` to contain the initial state for dataflow
77- /// analysis.
78+ /// Mutates the initial value of the dataflow state upon entry to the `START_BLOCK`.
7879 ///
7980 /// For backward analyses, initial state besides the bottom value is not yet supported. Trying
8081 /// to mutate the initial state will result in a panic.
@@ -86,6 +87,21 @@ pub trait AnalysisDomain<'tcx> {
8687}
8788
8889/// A dataflow problem with an arbitrarily complex transfer function.
90+ ///
91+ /// # Convergence
92+ ///
93+ /// When implementing this trait directly (not via [`GenKillAnalysis`]), it's possible to choose a
94+ /// transfer function such that the analysis does not reach fixpoint. To guarantee convergence,
95+ /// your transfer functions must maintain the following invariant:
96+ ///
97+ /// > If the dataflow state **before** some point in the program changes to be greater
98+ /// than the prior state **before** that point, the dataflow state **after** that point must
99+ /// also change to be greater than the prior state **after** that point.
100+ ///
101+ /// This invariant guarantees that the dataflow state at a given point in the program increases
102+ /// monotonically until fixpoint is reached. Note that this monotonicity requirement only applies
103+ /// to the same point in the program at different points in time. The dataflow state at a given
104+ /// point in the program may or may not be greater than the state at any preceding point.
89105pub trait Analysis < ' tcx > : AnalysisDomain < ' tcx > {
90106 /// Updates the current dataflow state with the effect of evaluating a statement.
91107 fn apply_statement_effect (
0 commit comments