@@ -37,6 +37,7 @@ mod constraints;
3737mod dump;
3838pub ( crate ) mod legacy;
3939mod liveness_constraints;
40+ mod loan_liveness;
4041mod typeck_constraints;
4142
4243use std:: collections:: BTreeMap ;
@@ -49,8 +50,12 @@ use rustc_mir_dataflow::points::PointIndex;
4950pub ( crate ) use self :: constraints:: * ;
5051pub ( crate ) use self :: dump:: dump_polonius_mir;
5152use self :: liveness_constraints:: create_liveness_constraints;
53+ use self :: loan_liveness:: compute_loan_liveness;
5254use self :: typeck_constraints:: convert_typeck_constraints;
53- use crate :: RegionInferenceContext ;
55+ use crate :: dataflow:: BorrowIndex ;
56+ use crate :: { BorrowSet , RegionInferenceContext } ;
57+
58+ pub ( crate ) type LiveLoans = SparseBitMatrix < PointIndex , BorrowIndex > ;
5459
5560/// This struct holds the data needed to create the Polonius localized constraints.
5661pub ( crate ) struct PoloniusContext {
@@ -82,14 +87,20 @@ impl PoloniusContext {
8287 Self { live_region_variances : BTreeMap :: new ( ) , live_regions : None }
8388 }
8489
85- /// Creates a constraint set for `-Zpolonius=next` by:
90+ /// Computes live loans using the set of loans model for `-Zpolonius=next`.
91+ ///
92+ /// First, creates a constraint graph combining regions and CFG points, by:
8693 /// - converting NLL typeck constraints to be localized
8794 /// - encoding liveness constraints
88- pub ( crate ) fn create_localized_constraints < ' tcx > (
95+ ///
96+ /// Then, this graph is traversed, and combined with kills, reachability is recorded as loan
97+ /// liveness, to be used by the loan scope and active loans computations.
98+ pub ( crate ) fn compute_loan_liveness < ' tcx > (
8999 & self ,
90100 tcx : TyCtxt < ' tcx > ,
91101 regioncx : & RegionInferenceContext < ' tcx > ,
92102 body : & Body < ' tcx > ,
103+ borrow_set : & BorrowSet < ' tcx > ,
93104 ) -> LocalizedOutlivesConstraintSet {
94105 let mut localized_outlives_constraints = LocalizedOutlivesConstraintSet :: default ( ) ;
95106 convert_typeck_constraints (
@@ -113,8 +124,19 @@ impl PoloniusContext {
113124 & mut localized_outlives_constraints,
114125 ) ;
115126
116- // FIXME: here, we can trace loan reachability in the constraint graph and record this as loan
117- // liveness for the next step in the chain, the NLL loan scope and active loans computations.
127+ // Now that we have a complete graph, we can compute reachability to trace the liveness of
128+ // loans for the next step in the chain, the NLL loan scope and active loans computations.
129+ let mut live_loans = LiveLoans :: new ( borrow_set. len ( ) ) ;
130+ compute_loan_liveness (
131+ tcx,
132+ body,
133+ regioncx. liveness_constraints ( ) ,
134+ borrow_set,
135+ & localized_outlives_constraints,
136+ & mut live_loans,
137+ ) ;
138+ // FIXME: record the live loans in the regioncx's liveness constraints, where the
139+ // location-insensitive variant's data is stored.
118140
119141 localized_outlives_constraints
120142 }
0 commit comments