Skip to content

Commit a8fc140

Browse files
committed
create context for errors and diagnostics for last borrowck phase
1 parent 6054a33 commit a8fc140

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn do_mir_borrowck<'tcx>(
198198
polonius_output,
199199
opt_closure_req,
200200
nll_errors,
201-
localized_outlives_constraints,
201+
polonius_diagnostics,
202202
} = nll::compute_regions(
203203
&infcx,
204204
free_regions,
@@ -329,7 +329,7 @@ fn do_mir_borrowck<'tcx>(
329329
body,
330330
&regioncx,
331331
&borrow_set,
332-
localized_outlives_constraints,
332+
polonius_diagnostics,
333333
&opt_closure_req,
334334
);
335335

compiler/rustc_borrowck/src/nll.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use tracing::{debug, instrument};
2727
use crate::borrow_set::BorrowSet;
2828
use crate::consumers::ConsumerOptions;
2929
use crate::diagnostics::{BorrowckDiagnosticsBuffer, RegionErrors};
30-
use crate::polonius::LocalizedOutlivesConstraintSet;
30+
use crate::polonius::PoloniusDiagnosticsContext;
3131
use crate::polonius::legacy::{
3232
PoloniusFacts, PoloniusFactsExt, PoloniusLocationTable, PoloniusOutput,
3333
};
@@ -46,8 +46,9 @@ pub(crate) struct NllOutput<'tcx> {
4646
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
4747
pub nll_errors: RegionErrors<'tcx>,
4848

49-
/// When using `-Zpolonius=next`: the localized typeck and liveness constraints.
50-
pub localized_outlives_constraints: Option<LocalizedOutlivesConstraintSet>,
49+
/// When using `-Zpolonius=next`: the data used to compute errors and diagnostics, e.g.
50+
/// localized typeck and liveness constraints.
51+
pub polonius_diagnostics: Option<PoloniusDiagnosticsContext>,
5152
}
5253

5354
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal
@@ -144,7 +145,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
144145

145146
// If requested for `-Zpolonius=next`, convert NLL constraints to localized outlives constraints
146147
// and use them to compute loan liveness.
147-
let localized_outlives_constraints = polonius_context.as_ref().map(|polonius_context| {
148+
let polonius_diagnostics = polonius_context.as_ref().map(|polonius_context| {
148149
polonius_context.compute_loan_liveness(infcx.tcx, &mut regioncx, body, borrow_set)
149150
});
150151

@@ -188,7 +189,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
188189
polonius_output,
189190
opt_closure_req: closure_region_requirements,
190191
nll_errors,
191-
localized_outlives_constraints,
192+
polonius_diagnostics,
192193
}
193194
}
194195

compiler/rustc_borrowck/src/polonius/dump.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use rustc_session::config::MirIncludeSpans;
1212

1313
use crate::borrow_set::BorrowSet;
1414
use crate::constraints::OutlivesConstraint;
15-
use crate::polonius::{LocalizedOutlivesConstraint, LocalizedOutlivesConstraintSet};
15+
use crate::polonius::{
16+
LocalizedOutlivesConstraint, LocalizedOutlivesConstraintSet, PoloniusDiagnosticsContext,
17+
};
1618
use crate::region_infer::values::LivenessValues;
1719
use crate::type_check::Locations;
1820
use crate::{BorrowckInferCtxt, RegionInferenceContext};
@@ -23,7 +25,7 @@ pub(crate) fn dump_polonius_mir<'tcx>(
2325
body: &Body<'tcx>,
2426
regioncx: &RegionInferenceContext<'tcx>,
2527
borrow_set: &BorrowSet<'tcx>,
26-
localized_outlives_constraints: Option<LocalizedOutlivesConstraintSet>,
28+
polonius_diagnostics: Option<PoloniusDiagnosticsContext>,
2729
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
2830
) {
2931
let tcx = infcx.tcx;
@@ -35,8 +37,8 @@ pub(crate) fn dump_polonius_mir<'tcx>(
3537
return;
3638
}
3739

38-
let localized_outlives_constraints = localized_outlives_constraints
39-
.expect("missing localized constraints with `-Zpolonius=next`");
40+
let polonius_diagnostics_context =
41+
polonius_diagnostics.expect("missing diagnostics context with `-Zpolonius=next`");
4042

4143
let _: io::Result<()> = try {
4244
let mut file = create_dump_file(tcx, "html", false, "polonius", &0, body)?;
@@ -45,7 +47,7 @@ pub(crate) fn dump_polonius_mir<'tcx>(
4547
body,
4648
regioncx,
4749
borrow_set,
48-
localized_outlives_constraints,
50+
polonius_diagnostics_context.localized_outlives_constraints,
4951
closure_region_requirements,
5052
&mut file,
5153
)?;

compiler/rustc_borrowck/src/polonius/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
//! 2) once that is done, variance data is transferred, and the NLL region liveness is converted to
4040
//! the polonius shape. That's the main [PoloniusContext].
4141
//! 3) during region inference, that data and the NLL outlives constraints are used to create the
42-
//! localized outlives constraints, as described above.
43-
//! 4) transfer these constraints back to the main borrowck procedure: it handles computing errors
44-
//! and diagnostics, debugging and MIR dumping concerns.
42+
//! localized outlives constraints, as described above. That's the [PoloniusDiagnosticsContext].
43+
//! 4) transfer this back to the main borrowck procedure: it handles computing errors and
44+
//! diagnostics, debugging and MIR dumping concerns.
4545
4646
mod constraints;
4747
mod dump;
@@ -89,6 +89,12 @@ pub(crate) struct PoloniusContext {
8989
live_region_variances: BTreeMap<RegionVid, ConstraintDirection>,
9090
}
9191

92+
/// This struct holds the data needed by the borrowck error computation and diagnostics. Its data is
93+
/// computed from the [PoloniusContext] when computing NLL regions.
94+
pub(crate) struct PoloniusDiagnosticsContext {
95+
localized_outlives_constraints: LocalizedOutlivesConstraintSet,
96+
}
97+
9298
/// The direction a constraint can flow into. Used to create liveness constraints according to
9399
/// variance.
94100
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -135,13 +141,15 @@ impl PoloniusContext {
135141
///
136142
/// Then, this graph is traversed, and combined with kills, reachability is recorded as loan
137143
/// liveness, to be used by the loan scope and active loans computations.
144+
///
145+
/// The constraint data will be used to compute errors and diagnostics.
138146
pub(crate) fn compute_loan_liveness<'tcx>(
139147
&self,
140148
tcx: TyCtxt<'tcx>,
141149
regioncx: &mut RegionInferenceContext<'tcx>,
142150
body: &Body<'tcx>,
143151
borrow_set: &BorrowSet<'tcx>,
144-
) -> LocalizedOutlivesConstraintSet {
152+
) -> PoloniusDiagnosticsContext {
145153
let mut localized_outlives_constraints = LocalizedOutlivesConstraintSet::default();
146154
convert_typeck_constraints(
147155
tcx,
@@ -173,6 +181,6 @@ impl PoloniusContext {
173181
);
174182
regioncx.record_live_loans(live_loans);
175183

176-
localized_outlives_constraints
184+
PoloniusDiagnosticsContext { localized_outlives_constraints }
177185
}
178186
}

0 commit comments

Comments
 (0)