@@ -37,6 +37,7 @@ mod constraints;
37
37
mod dump;
38
38
pub ( crate ) mod legacy;
39
39
mod liveness_constraints;
40
+ mod loan_liveness;
40
41
mod typeck_constraints;
41
42
42
43
use std:: collections:: BTreeMap ;
@@ -49,8 +50,12 @@ use rustc_mir_dataflow::points::PointIndex;
49
50
pub ( crate ) use self :: constraints:: * ;
50
51
pub ( crate ) use self :: dump:: dump_polonius_mir;
51
52
use self :: liveness_constraints:: create_liveness_constraints;
53
+ use self :: loan_liveness:: compute_loan_liveness;
52
54
use 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 > ;
54
59
55
60
/// This struct holds the data needed to create the Polonius localized constraints.
56
61
pub ( crate ) struct PoloniusContext {
@@ -82,14 +87,20 @@ impl PoloniusContext {
82
87
Self { live_region_variances : BTreeMap :: new ( ) , live_regions : None }
83
88
}
84
89
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:
86
93
/// - converting NLL typeck constraints to be localized
87
94
/// - 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 > (
89
99
& self ,
90
100
tcx : TyCtxt < ' tcx > ,
91
101
regioncx : & RegionInferenceContext < ' tcx > ,
92
102
body : & Body < ' tcx > ,
103
+ borrow_set : & BorrowSet < ' tcx > ,
93
104
) -> LocalizedOutlivesConstraintSet {
94
105
let mut localized_outlives_constraints = LocalizedOutlivesConstraintSet :: default ( ) ;
95
106
convert_typeck_constraints (
@@ -113,8 +124,19 @@ impl PoloniusContext {
113
124
& mut localized_outlives_constraints,
114
125
) ;
115
126
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.
118
140
119
141
localized_outlives_constraints
120
142
}
0 commit comments