Skip to content

Commit 3b5a727

Browse files
committed
construct pick-constraints and give them to region inference
1 parent d959669 commit 3b5a727

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

src/librustc_mir/borrow_check/nll/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
130130
placeholder_index_to_region: _,
131131
mut liveness_constraints,
132132
outlives_constraints,
133+
pick_constraints,
133134
closure_bounds_mapping,
134135
type_tests,
135136
} = constraints;
@@ -151,6 +152,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
151152
universal_region_relations,
152153
body,
153154
outlives_constraints,
155+
pick_constraints,
154156
closure_bounds_mapping,
155157
type_tests,
156158
liveness_constraints,

src/librustc_mir/borrow_check/nll/pick_constraints.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,20 @@ newtype_index! {
5555
}
5656
}
5757

58-
impl<'tcx> PickConstraintSet<'tcx, ty::RegionVid> {
59-
crate fn new() -> Self {
58+
impl Default for PickConstraintSet<'tcx, ty::RegionVid> {
59+
fn default() -> Self {
6060
Self {
6161
first_constraints: Default::default(),
6262
constraints: Default::default(),
6363
option_regions: Default::default(),
6464
}
6565
}
66+
}
6667

68+
impl<'tcx> PickConstraintSet<'tcx, ty::RegionVid> {
6769
crate fn push_constraint(
6870
&mut self,
69-
p_c: PickConstraint<'tcx>,
71+
p_c: &PickConstraint<'tcx>,
7072
mut to_region_vid: impl FnMut(ty::Region<'tcx>) -> ty::RegionVid,
7173
) {
7274
let pick_region_vid: ty::RegionVid = to_region_vid(p_c.pick_region);

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::universal_regions::UniversalRegions;
22
use crate::borrow_check::nll::constraints::graph::NormalConstraintGraph;
33
use crate::borrow_check::nll::constraints::{ConstraintSccIndex, OutlivesConstraintSet, OutlivesConstraint};
4+
use crate::borrow_check::nll::pick_constraints::PickConstraintSet;
45
use crate::borrow_check::nll::region_infer::values::{
56
PlaceholderIndices, RegionElement, ToElementIndex
67
};
@@ -187,6 +188,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
187188
universal_region_relations: Rc<UniversalRegionRelations<'tcx>>,
188189
_body: &Body<'tcx>,
189190
outlives_constraints: OutlivesConstraintSet,
191+
pick_constraints: PickConstraintSet<'tcx, RegionVid>,
190192
closure_bounds_mapping: FxHashMap<
191193
Location,
192194
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
@@ -218,6 +220,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
218220

219221
let scc_representatives = Self::compute_scc_representatives(&constraint_sccs, &definitions);
220222

223+
let _pick_constraints_scc = pick_constraints.into_mapped( // TODO
224+
|r| constraint_sccs.scc(r),
225+
);
226+
221227
let mut result = Self {
222228
definitions,
223229
liveness_constraints,

src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,22 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
5151
}
5252

5353
pub(super) fn convert_all(&mut self, query_constraints: &QueryRegionConstraints<'tcx>) {
54-
for query_constraint in &query_constraints.outlives {
54+
let QueryRegionConstraints { outlives, pick_constraints } = query_constraints;
55+
56+
// Annoying: to invoke `self.to_region_vid`, we need access to
57+
// `self.constraints`, but we also want to be mutating
58+
// `self.pick_constraints`. For now, just swap out the value
59+
// we want and replace at the end.
60+
let mut tmp = std::mem::replace(&mut self.constraints.pick_constraints, Default::default());
61+
for pick_constraint in pick_constraints {
62+
tmp.push_constraint(
63+
pick_constraint,
64+
|r| self.to_region_vid(r),
65+
);
66+
}
67+
self.constraints.pick_constraints = tmp;
68+
69+
for query_constraint in outlives {
5570
self.convert(query_constraint);
5671
}
5772
}

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use crate::borrow_check::borrow_set::BorrowSet;
66
use crate::borrow_check::location::LocationTable;
77
use crate::borrow_check::nll::constraints::{OutlivesConstraintSet, OutlivesConstraint};
8+
use crate::borrow_check::nll::pick_constraints::PickConstraintSet;
89
use crate::borrow_check::nll::facts::AllFacts;
910
use crate::borrow_check::nll::region_infer::values::LivenessValues;
1011
use crate::borrow_check::nll::region_infer::values::PlaceholderIndex;
@@ -128,6 +129,7 @@ pub(crate) fn type_check<'tcx>(
128129
placeholder_index_to_region: IndexVec::default(),
129130
liveness_constraints: LivenessValues::new(elements.clone()),
130131
outlives_constraints: OutlivesConstraintSet::default(),
132+
pick_constraints: PickConstraintSet::default(),
131133
closure_bounds_mapping: Default::default(),
132134
type_tests: Vec::default(),
133135
};
@@ -886,6 +888,8 @@ crate struct MirTypeckRegionConstraints<'tcx> {
886888

887889
crate outlives_constraints: OutlivesConstraintSet,
888890

891+
crate pick_constraints: PickConstraintSet<'tcx, RegionVid>,
892+
889893
crate closure_bounds_mapping:
890894
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
891895

0 commit comments

Comments
 (0)