@@ -52,9 +52,10 @@ mod typeck_constraints;
5252
5353use std:: collections:: BTreeMap ;
5454
55+ use rustc_data_structures:: fx:: FxHashSet ;
5556use rustc_index:: bit_set:: SparseBitMatrix ;
5657use rustc_index:: interval:: SparseIntervalMatrix ;
57- use rustc_middle:: mir:: Body ;
58+ use rustc_middle:: mir:: { Body , Local } ;
5859use rustc_middle:: ty:: { RegionVid , TyCtxt } ;
5960use rustc_mir_dataflow:: points:: PointIndex ;
6061
@@ -75,24 +76,33 @@ pub(crate) struct PoloniusLivenessContext {
7576 /// The expected edge direction per live region: the kind of directed edge we'll create as
7677 /// liveness constraints depends on the variance of types with respect to each contained region.
7778 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 > ,
7885}
7986
8087/// This struct holds the data needed to create the Polonius localized constraints. Its data is
8188/// transferred and converted from the [PoloniusLivenessContext] at the end of MIR typeck.
8289pub ( crate ) struct PoloniusContext {
90+ /// The liveness data we recorded during MIR typeck.
91+ liveness_context : PoloniusLivenessContext ,
92+
8393 /// The set of regions that are live at a given point in the CFG, used to create localized
8494 /// outlives constraints between regions that are live at connected points in the CFG.
8595 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 > ,
9096}
9197
9298/// This struct holds the data needed by the borrowck error computation and diagnostics. Its data is
9399/// computed from the [PoloniusContext] when computing NLL regions.
94100pub ( crate ) struct PoloniusDiagnosticsContext {
101+ /// The localized outlives constraints that were computed in the main analysis.
95102 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 > ,
96106}
97107
98108/// The direction a constraint can flow into. Used to create liveness constraints according to
@@ -127,10 +137,7 @@ impl PoloniusContext {
127137 }
128138 }
129139
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 }
134141 }
135142
136143 /// Computes live loans using the set of loans model for `-Zpolonius=next`.
@@ -144,12 +151,15 @@ impl PoloniusContext {
144151 ///
145152 /// The constraint data will be used to compute errors and diagnostics.
146153 pub ( crate ) fn compute_loan_liveness < ' tcx > (
147- & self ,
154+ self ,
148155 tcx : TyCtxt < ' tcx > ,
149156 regioncx : & mut RegionInferenceContext < ' tcx > ,
150157 body : & Body < ' tcx > ,
151158 borrow_set : & BorrowSet < ' tcx > ,
152159 ) -> PoloniusDiagnosticsContext {
160+ let PoloniusLivenessContext { live_region_variances, boring_nll_locals } =
161+ self . liveness_context ;
162+
153163 let mut localized_outlives_constraints = LocalizedOutlivesConstraintSet :: default ( ) ;
154164 convert_typeck_constraints (
155165 tcx,
@@ -164,7 +174,7 @@ impl PoloniusContext {
164174 body,
165175 regioncx. liveness_constraints ( ) ,
166176 & self . live_regions ,
167- & self . live_region_variances ,
177+ & live_region_variances,
168178 regioncx. universal_regions ( ) ,
169179 & mut localized_outlives_constraints,
170180 ) ;
@@ -181,6 +191,6 @@ impl PoloniusContext {
181191 ) ;
182192 regioncx. record_live_loans ( live_loans) ;
183193
184- PoloniusDiagnosticsContext { localized_outlives_constraints }
194+ PoloniusDiagnosticsContext { localized_outlives_constraints, boring_nll_locals }
185195 }
186196}
0 commit comments