From f277b394af03284bea7fad45838f7dbc570cf634 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 23 Jul 2018 22:10:18 +0300 Subject: [PATCH] generate extra liveness constraints before regioncx is created --- .../borrow_check/nll/constraint_generation.rs | 15 +++++++------ src/librustc_mir/borrow_check/nll/mod.rs | 21 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/constraint_generation.rs b/src/librustc_mir/borrow_check/nll/constraint_generation.rs index f274f8e9189..3074782c867 100644 --- a/src/librustc_mir/borrow_check/nll/constraint_generation.rs +++ b/src/librustc_mir/borrow_check/nll/constraint_generation.rs @@ -12,7 +12,7 @@ use borrow_check::borrow_set::BorrowSet; use borrow_check::location::LocationTable; use borrow_check::nll::ToRegionVid; use borrow_check::nll::facts::AllFacts; -use borrow_check::nll::region_infer::RegionInferenceContext; +use borrow_check::nll::region_infer::values::{RegionValueElements, RegionValues}; use rustc::infer::InferCtxt; use rustc::mir::visit::TyContext; use rustc::mir::visit::Visitor; @@ -20,11 +20,12 @@ use rustc::mir::{BasicBlock, BasicBlockData, Location, Mir, Place, Rvalue}; use rustc::mir::{Local, Statement, Terminator}; use rustc::ty::fold::TypeFoldable; use rustc::ty::subst::Substs; -use rustc::ty::{self, CanonicalTy, ClosureSubsts, GeneratorSubsts}; +use rustc::ty::{self, CanonicalTy, ClosureSubsts, GeneratorSubsts, RegionVid}; pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>( infcx: &InferCtxt<'cx, 'gcx, 'tcx>, - regioncx: &mut RegionInferenceContext<'tcx>, + elements: &RegionValueElements, + liveness_constraints: &mut RegionValues, all_facts: &mut Option, location_table: &LocationTable, mir: &Mir<'tcx>, @@ -33,9 +34,10 @@ pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>( let mut cg = ConstraintGeneration { borrow_set, infcx, - regioncx, + liveness_constraints, location_table, all_facts, + elements, }; for (bb, data) in mir.basic_blocks().iter_enumerated() { @@ -48,8 +50,9 @@ struct ConstraintGeneration<'cg, 'cx: 'cg, 'gcx: 'tcx, 'tcx: 'cx> { infcx: &'cg InferCtxt<'cx, 'gcx, 'tcx>, all_facts: &'cg mut Option, location_table: &'cg LocationTable, - regioncx: &'cg mut RegionInferenceContext<'tcx>, + liveness_constraints: &'cg mut RegionValues, borrow_set: &'cg BorrowSet<'tcx>, + elements: &'cg RegionValueElements, } impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx, 'tcx> { @@ -202,7 +205,7 @@ impl<'cx, 'cg, 'gcx, 'tcx> ConstraintGeneration<'cx, 'cg, 'gcx, 'tcx> { .tcx .for_each_free_region(&live_ty, |live_region| { let vid = live_region.to_region_vid(); - self.regioncx.add_live_element(vid, location); + self.liveness_constraints.add_element(&self.elements, vid, location); }); } } diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index edc701bad1e..b9967c2be43 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -136,10 +136,21 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( // base constraints generated by the type-check. let var_origins = infcx.take_region_var_origins(); let MirTypeckRegionConstraints { - liveness_constraints, + mut liveness_constraints, outlives_constraints, type_tests, } = constraint_sets; + + constraint_generation::generate_constraints( + infcx, + &elements, + &mut liveness_constraints, + &mut all_facts, + location_table, + &mir, + borrow_set, + ); + let mut regioncx = RegionInferenceContext::new( var_origins, universal_regions, @@ -151,14 +162,6 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( ); // Generate various additional constraints. - constraint_generation::generate_constraints( - infcx, - &mut regioncx, - &mut all_facts, - location_table, - &mir, - borrow_set, - ); invalidation::generate_invalidates( infcx, &mut all_facts,