@@ -52,9 +52,10 @@ mod typeck_constraints;
52
52
53
53
use std:: collections:: BTreeMap ;
54
54
55
+ use rustc_data_structures:: fx:: FxHashSet ;
55
56
use rustc_index:: bit_set:: SparseBitMatrix ;
56
57
use rustc_index:: interval:: SparseIntervalMatrix ;
57
- use rustc_middle:: mir:: Body ;
58
+ use rustc_middle:: mir:: { Body , Local } ;
58
59
use rustc_middle:: ty:: { RegionVid , TyCtxt } ;
59
60
use rustc_mir_dataflow:: points:: PointIndex ;
60
61
@@ -75,24 +76,33 @@ pub(crate) struct PoloniusLivenessContext {
75
76
/// The expected edge direction per live region: the kind of directed edge we'll create as
76
77
/// liveness constraints depends on the variance of types with respect to each contained region.
77
78
live_region_variances : BTreeMap < RegionVid , ConstraintDirection > ,
79
+
80
+ /// The regions that outlive free regions are used to distinguish relevant live locals from
81
+ /// boring locals. A boring local is one whose type contains only such regions. Polonius
82
+ /// currently has more boring locals than NLLs so we record the latter to use in errors and
83
+ /// diagnostics, to focus on the locals we consider relevant and match NLL diagnostics.
84
+ pub ( crate ) boring_nll_locals : FxHashSet < Local > ,
78
85
}
79
86
80
87
/// This struct holds the data needed to create the Polonius localized constraints. Its data is
81
88
/// transferred and converted from the [PoloniusLivenessContext] at the end of MIR typeck.
82
89
pub ( crate ) struct PoloniusContext {
90
+ /// The liveness data we recorded during MIR typeck.
91
+ liveness_context : PoloniusLivenessContext ,
92
+
83
93
/// The set of regions that are live at a given point in the CFG, used to create localized
84
94
/// outlives constraints between regions that are live at connected points in the CFG.
85
95
live_regions : SparseBitMatrix < PointIndex , RegionVid > ,
86
-
87
- /// The expected edge direction per live region: the kind of directed edge we'll create as
88
- /// liveness constraints depends on the variance of types with respect to each contained region.
89
- live_region_variances : BTreeMap < RegionVid , ConstraintDirection > ,
90
96
}
91
97
92
98
/// This struct holds the data needed by the borrowck error computation and diagnostics. Its data is
93
99
/// computed from the [PoloniusContext] when computing NLL regions.
94
100
pub ( crate ) struct PoloniusDiagnosticsContext {
101
+ /// The localized outlives constraints that were computed in the main analysis.
95
102
localized_outlives_constraints : LocalizedOutlivesConstraintSet ,
103
+
104
+ /// The liveness data computed during MIR typeck: [PoloniusLivenessContext::boring_nll_locals].
105
+ pub ( crate ) boring_nll_locals : FxHashSet < Local > ,
96
106
}
97
107
98
108
/// The direction a constraint can flow into. Used to create liveness constraints according to
@@ -127,10 +137,7 @@ impl PoloniusContext {
127
137
}
128
138
}
129
139
130
- PoloniusContext {
131
- live_regions : live_regions_per_point,
132
- live_region_variances : liveness_context. live_region_variances ,
133
- }
140
+ PoloniusContext { live_regions : live_regions_per_point, liveness_context }
134
141
}
135
142
136
143
/// Computes live loans using the set of loans model for `-Zpolonius=next`.
@@ -144,12 +151,15 @@ impl PoloniusContext {
144
151
///
145
152
/// The constraint data will be used to compute errors and diagnostics.
146
153
pub ( crate ) fn compute_loan_liveness < ' tcx > (
147
- & self ,
154
+ self ,
148
155
tcx : TyCtxt < ' tcx > ,
149
156
regioncx : & mut RegionInferenceContext < ' tcx > ,
150
157
body : & Body < ' tcx > ,
151
158
borrow_set : & BorrowSet < ' tcx > ,
152
159
) -> PoloniusDiagnosticsContext {
160
+ let PoloniusLivenessContext { live_region_variances, boring_nll_locals } =
161
+ self . liveness_context ;
162
+
153
163
let mut localized_outlives_constraints = LocalizedOutlivesConstraintSet :: default ( ) ;
154
164
convert_typeck_constraints (
155
165
tcx,
@@ -164,7 +174,7 @@ impl PoloniusContext {
164
174
body,
165
175
regioncx. liveness_constraints ( ) ,
166
176
& self . live_regions ,
167
- & self . live_region_variances ,
177
+ & live_region_variances,
168
178
regioncx. universal_regions ( ) ,
169
179
& mut localized_outlives_constraints,
170
180
) ;
@@ -181,6 +191,6 @@ impl PoloniusContext {
181
191
) ;
182
192
regioncx. record_live_loans ( live_loans) ;
183
193
184
- PoloniusDiagnosticsContext { localized_outlives_constraints }
194
+ PoloniusDiagnosticsContext { localized_outlives_constraints, boring_nll_locals }
185
195
}
186
196
}
0 commit comments