提交 3b5a7276 编写于 作者: N Niko Matsakis

construct pick-constraints and give them to region inference

上级 d9596692
......@@ -130,6 +130,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
placeholder_index_to_region: _,
mut liveness_constraints,
outlives_constraints,
pick_constraints,
closure_bounds_mapping,
type_tests,
} = constraints;
......@@ -151,6 +152,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
universal_region_relations,
body,
outlives_constraints,
pick_constraints,
closure_bounds_mapping,
type_tests,
liveness_constraints,
......
......@@ -55,18 +55,20 @@
}
}
impl<'tcx> PickConstraintSet<'tcx, ty::RegionVid> {
crate fn new() -> Self {
impl Default for PickConstraintSet<'tcx, ty::RegionVid> {
fn default() -> Self {
Self {
first_constraints: Default::default(),
constraints: Default::default(),
option_regions: Default::default(),
}
}
}
impl<'tcx> PickConstraintSet<'tcx, ty::RegionVid> {
crate fn push_constraint(
&mut self,
p_c: PickConstraint<'tcx>,
p_c: &PickConstraint<'tcx>,
mut to_region_vid: impl FnMut(ty::Region<'tcx>) -> ty::RegionVid,
) {
let pick_region_vid: ty::RegionVid = to_region_vid(p_c.pick_region);
......
use super::universal_regions::UniversalRegions;
use crate::borrow_check::nll::constraints::graph::NormalConstraintGraph;
use crate::borrow_check::nll::constraints::{ConstraintSccIndex, OutlivesConstraintSet, OutlivesConstraint};
use crate::borrow_check::nll::pick_constraints::PickConstraintSet;
use crate::borrow_check::nll::region_infer::values::{
PlaceholderIndices, RegionElement, ToElementIndex
};
......@@ -187,6 +188,7 @@ pub(crate) fn new(
universal_region_relations: Rc<UniversalRegionRelations<'tcx>>,
_body: &Body<'tcx>,
outlives_constraints: OutlivesConstraintSet,
pick_constraints: PickConstraintSet<'tcx, RegionVid>,
closure_bounds_mapping: FxHashMap<
Location,
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
......@@ -218,6 +220,10 @@ pub(crate) fn new(
let scc_representatives = Self::compute_scc_representatives(&constraint_sccs, &definitions);
let _pick_constraints_scc = pick_constraints.into_mapped( // TODO
|r| constraint_sccs.scc(r),
);
let mut result = Self {
definitions,
liveness_constraints,
......
......@@ -51,7 +51,22 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
}
pub(super) fn convert_all(&mut self, query_constraints: &QueryRegionConstraints<'tcx>) {
for query_constraint in &query_constraints.outlives {
let QueryRegionConstraints { outlives, pick_constraints } = query_constraints;
// Annoying: to invoke `self.to_region_vid`, we need access to
// `self.constraints`, but we also want to be mutating
// `self.pick_constraints`. For now, just swap out the value
// we want and replace at the end.
let mut tmp = std::mem::replace(&mut self.constraints.pick_constraints, Default::default());
for pick_constraint in pick_constraints {
tmp.push_constraint(
pick_constraint,
|r| self.to_region_vid(r),
);
}
self.constraints.pick_constraints = tmp;
for query_constraint in outlives {
self.convert(query_constraint);
}
}
......
......@@ -5,6 +5,7 @@
use crate::borrow_check::borrow_set::BorrowSet;
use crate::borrow_check::location::LocationTable;
use crate::borrow_check::nll::constraints::{OutlivesConstraintSet, OutlivesConstraint};
use crate::borrow_check::nll::pick_constraints::PickConstraintSet;
use crate::borrow_check::nll::facts::AllFacts;
use crate::borrow_check::nll::region_infer::values::LivenessValues;
use crate::borrow_check::nll::region_infer::values::PlaceholderIndex;
......@@ -128,6 +129,7 @@ pub(crate) fn type_check<'tcx>(
placeholder_index_to_region: IndexVec::default(),
liveness_constraints: LivenessValues::new(elements.clone()),
outlives_constraints: OutlivesConstraintSet::default(),
pick_constraints: PickConstraintSet::default(),
closure_bounds_mapping: Default::default(),
type_tests: Vec::default(),
};
......@@ -886,6 +888,8 @@ struct BorrowCheckContext<'a, 'tcx> {
crate outlives_constraints: OutlivesConstraintSet,
crate pick_constraints: PickConstraintSet<'tcx, RegionVid>,
crate closure_bounds_mapping:
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册