@@ -60,9 +60,10 @@ pub use self::visitor::{BorrowckFlowState, BorrowckResults};
60
60
/// This trait specifies the lattice on which this analysis operates (the domain) as well as its
61
61
/// initial value at the entry point of each basic block.
62
62
pub trait AnalysisDomain < ' tcx > {
63
+ /// The type that holds the dataflow state at any given point in the program.
63
64
type Domain : Clone + JoinSemiLattice ;
64
65
65
- /// The direction of this analyis . Either `Forward` or `Backward`.
66
+ /// The direction of this analysis . Either `Forward` or `Backward`.
66
67
type Direction : Direction = Forward ;
67
68
68
69
/// A descriptive name for this analysis. Used only for debugging.
@@ -71,10 +72,10 @@ pub trait AnalysisDomain<'tcx> {
71
72
/// suitable as part of a filename.
72
73
const NAME : & ' static str ;
73
74
75
+ /// The initial value of the dataflow state upon entry to each basic block.
74
76
fn bottom_value ( & self , body : & mir:: Body < ' tcx > ) -> Self :: Domain ;
75
77
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`.
78
79
///
79
80
/// For backward analyses, initial state besides the bottom value is not yet supported. Trying
80
81
/// to mutate the initial state will result in a panic.
@@ -86,6 +87,21 @@ pub trait AnalysisDomain<'tcx> {
86
87
}
87
88
88
89
/// 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.
89
105
pub trait Analysis < ' tcx > : AnalysisDomain < ' tcx > {
90
106
/// Updates the current dataflow state with the effect of evaluating a statement.
91
107
fn apply_statement_effect (
0 commit comments