Skip to content

Commit aeb3d10

Browse files
committed
address review comments
- move constraints to an Option - check `-Zpolonius=next` only once - rewrite fixme comments to make the actionable part clear
1 parent c75c517 commit aeb3d10

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn do_mir_borrowck<'tcx>(
322322
body,
323323
&regioncx,
324324
&borrow_set,
325-
&localized_outlives_constraints,
325+
localized_outlives_constraints,
326326
&opt_closure_req,
327327
);
328328

compiler/rustc_borrowck/src/nll.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(crate) struct NllOutput<'tcx> {
4848
pub nll_errors: RegionErrors<'tcx>,
4949

5050
/// When using `-Zpolonius=next`: the localized typeck and liveness constraints.
51-
pub localized_outlives_constraints: LocalizedOutlivesConstraintSet,
51+
pub localized_outlives_constraints: Option<LocalizedOutlivesConstraintSet>,
5252
}
5353

5454
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal
@@ -141,15 +141,12 @@ pub(crate) fn compute_regions<'a, 'tcx>(
141141

142142
// If requested for `-Zpolonius=next`, convert NLL constraints to localized outlives
143143
// constraints.
144-
let mut localized_outlives_constraints = LocalizedOutlivesConstraintSet::default();
145-
if infcx.tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {
146-
polonius::create_localized_constraints(
147-
&mut regioncx,
148-
infcx.infcx.tcx,
149-
body,
150-
&mut localized_outlives_constraints,
151-
);
152-
}
144+
let localized_outlives_constraints =
145+
if infcx.tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {
146+
Some(polonius::create_localized_constraints(&mut regioncx, body))
147+
} else {
148+
None
149+
};
153150

154151
// If requested: dump NLL facts, and run legacy polonius analysis.
155152
let polonius_output = all_facts.as_ref().and_then(|all_facts| {

compiler/rustc_borrowck/src/polonius/dump.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ pub(crate) fn dump_polonius_mir<'tcx>(
1818
body: &Body<'tcx>,
1919
regioncx: &RegionInferenceContext<'tcx>,
2020
borrow_set: &BorrowSet<'tcx>,
21-
localized_outlives_constraints: &LocalizedOutlivesConstraintSet,
21+
localized_outlives_constraints: Option<LocalizedOutlivesConstraintSet>,
2222
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
2323
) {
2424
let tcx = infcx.tcx;
2525
if !tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {
2626
return;
2727
}
2828

29+
let localized_outlives_constraints = localized_outlives_constraints
30+
.expect("missing localized constraints with `-Zpolonius=next`");
31+
2932
// We want the NLL extra comments printed by default in NLL MIR dumps (they were removed in
3033
// #112346). Specifying `-Z mir-include-spans` on the CLI still has priority: for example,
3134
// they're always disabled in mir-opt tests to make working with blessed dumps easier.
@@ -48,7 +51,7 @@ pub(crate) fn dump_polonius_mir<'tcx>(
4851
regioncx,
4952
closure_region_requirements,
5053
borrow_set,
51-
localized_outlives_constraints,
54+
&localized_outlives_constraints,
5255
pass_where,
5356
out,
5457
)

compiler/rustc_borrowck/src/polonius/mod.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub(crate) use dump::dump_polonius_mir;
4040
pub(crate) mod legacy;
4141

4242
use rustc_middle::mir::{Body, Location};
43-
use rustc_middle::ty::TyCtxt;
4443
use rustc_mir_dataflow::points::PointIndex;
4544

4645
use crate::RegionInferenceContext;
@@ -49,34 +48,31 @@ use crate::region_infer::values::LivenessValues;
4948
use crate::type_check::Locations;
5049
use crate::universal_regions::UniversalRegions;
5150

52-
/// When using `-Zpolonius=next`, fills the given constraint set by:
51+
/// Creates a constraint set for `-Zpolonius=next` by:
5352
/// - converting NLL typeck constraints to be localized
5453
/// - encoding liveness constraints
5554
pub(crate) fn create_localized_constraints<'tcx>(
5655
regioncx: &mut RegionInferenceContext<'tcx>,
57-
tcx: TyCtxt<'tcx>,
5856
body: &Body<'tcx>,
59-
localized_outlives_constraints: &mut LocalizedOutlivesConstraintSet,
60-
) {
61-
if !tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {
62-
return;
63-
}
64-
57+
) -> LocalizedOutlivesConstraintSet {
58+
let mut localized_outlives_constraints = LocalizedOutlivesConstraintSet::default();
6559
convert_typeck_constraints(
6660
body,
6761
regioncx.liveness_constraints(),
6862
regioncx.outlives_constraints(),
69-
localized_outlives_constraints,
63+
&mut localized_outlives_constraints,
7064
);
7165
create_liveness_constraints(
7266
body,
7367
regioncx.liveness_constraints(),
7468
regioncx.universal_regions(),
75-
localized_outlives_constraints,
69+
&mut localized_outlives_constraints,
7670
);
7771

7872
// FIXME: here, we can trace loan reachability in the constraint graph and record this as loan
7973
// liveness for the next step in the chain, the NLL loan scope and active loans computations.
74+
75+
localized_outlives_constraints
8076
}
8177

8278
/// Propagate loans throughout the subset graph at a given point (with some subtleties around the
@@ -90,8 +86,9 @@ fn convert_typeck_constraints<'tcx>(
9086
for outlives_constraint in outlives_constraints {
9187
match outlives_constraint.locations {
9288
Locations::All(_) => {
93-
// FIXME: for now, turn logical constraints holding at all points into physical
94-
// edges at every point in the graph. We can encode this into *traversal* instead.
89+
// For now, turn logical constraints holding at all points into physical edges at
90+
// every point in the graph.
91+
// FIXME: encode this into *traversal* instead.
9592
for (block, bb) in body.basic_blocks.iter_enumerated() {
9693
let statement_count = bb.statements.len();
9794
for statement_index in 0..=statement_count {
@@ -168,9 +165,10 @@ fn propagate_loans_between_points(
168165
localized_outlives_constraints: &mut LocalizedOutlivesConstraintSet,
169166
) {
170167
// Universal regions are semantically live at all points.
171-
// FIXME: We always have universal regions but they're not always (or often) involved in the
172-
// subset graph. So for now, we emit this edge, but we only need to emit edges for universal
173-
// regions that existential regions can actually reach.
168+
// Note: we always have universal regions but they're not always (or often) involved in the
169+
// subset graph. For now, we emit all their edges unconditionally, but some of these subgraphs
170+
// will be disconnected from the rest of the graph and thus, unnecessary.
171+
// FIXME: only emit the edges of universal regions that existential regions can reach.
174172
for region in universal_regions.universal_regions_iter() {
175173
localized_outlives_constraints.push(LocalizedOutlivesConstraint {
176174
source: region,

0 commit comments

Comments
 (0)