From 3b5a7276d2ca4d3c5081db6b12114a93aeb5c822 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 5 Jun 2019 19:33:29 -0400 Subject: [PATCH] construct pick-constraints and give them to region inference --- src/librustc_mir/borrow_check/nll/mod.rs | 2 ++ .../borrow_check/nll/pick_constraints.rs | 8 +++++--- .../borrow_check/nll/region_infer/mod.rs | 6 ++++++ .../nll/type_check/constraint_conversion.rs | 17 ++++++++++++++++- .../borrow_check/nll/type_check/mod.rs | 4 ++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index 364d12aa395..380bfb52e3b 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -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, diff --git a/src/librustc_mir/borrow_check/nll/pick_constraints.rs b/src/librustc_mir/borrow_check/nll/pick_constraints.rs index 6bbd2e80527..b594a15b6d8 100644 --- a/src/librustc_mir/borrow_check/nll/pick_constraints.rs +++ b/src/librustc_mir/borrow_check/nll/pick_constraints.rs @@ -55,18 +55,20 @@ newtype_index! { } } -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); diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 4a44c41eb81..adee5bda425 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -1,6 +1,7 @@ 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 @@ impl<'tcx> RegionInferenceContext<'tcx> { universal_region_relations: Rc>, _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 @@ impl<'tcx> RegionInferenceContext<'tcx> { 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, diff --git a/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs b/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs index 0e7f6783823..c3bd4f6edf4 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs @@ -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); } } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 4b9c61068bd..ea7db309644 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -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 @@ crate struct MirTypeckRegionConstraints<'tcx> { crate outlives_constraints: OutlivesConstraintSet, + crate pick_constraints: PickConstraintSet<'tcx, RegionVid>, + crate closure_bounds_mapping: FxHashMap>,