introduce QueryRegionConstraints struct

This commit is contained in:
Niko Matsakis 2019-06-03 18:25:21 -04:00
parent 7e66a96d58
commit 09bba9b89d
7 changed files with 43 additions and 32 deletions

View File

@ -196,7 +196,15 @@ pub struct QueryResponse<'tcx, R> {
#[derive(Clone, Debug, Default, HashStable)]
pub struct QueryRegionConstraints<'tcx> {
outlives: Vec<QueryOutlivesConstraint<'tcx>>,
pub outlives: Vec<QueryOutlivesConstraint<'tcx>>,
}
impl QueryRegionConstraints<'_> {
/// Represents an empty (trivially true) set of region
/// constraints.
pub fn is_empty(&self) -> bool {
self.outlives.is_empty()
}
}
pub type Canonicalized<'tcx, V> = Canonical<'tcx, V>;

View File

@ -173,8 +173,8 @@ fn make_query_response<T>(
debug!("ambig_errors = {:#?}", ambig_errors);
let region_obligations = self.take_registered_region_obligations();
let outlives_constraints = self.with_region_constraints(|region_constraints| {
make_query_outlives(
let region_constraints = self.with_region_constraints(|region_constraints| {
make_query_region_constraints(
tcx,
region_obligations
.iter()
@ -191,9 +191,7 @@ fn make_query_response<T>(
Ok(QueryResponse {
var_values: inference_vars,
region_constraints: QueryRegionConstraints {
outlives: outlives_constraints,
},
region_constraints,
certainty,
value: answer,
})
@ -647,11 +645,11 @@ fn unify_canonical_vars(
/// Given the region obligations and constraints scraped from the infcx,
/// creates query region constraints.
pub fn make_query_outlives<'tcx>(
pub fn make_query_region_constraints<'tcx>(
tcx: TyCtxt<'tcx>,
outlives_obligations: impl Iterator<Item = (Ty<'tcx>, ty::Region<'tcx>)>,
region_constraints: &RegionConstraintData<'tcx>,
) -> Vec<QueryOutlivesConstraint<'tcx>> {
) -> QueryRegionConstraints<'tcx> {
let RegionConstraintData {
constraints,
verifys,
@ -690,5 +688,5 @@ pub fn make_query_outlives<'tcx>(
)
.collect();
outlives
QueryRegionConstraints { outlives }
}

View File

@ -3,7 +3,7 @@
use crate::traits::query::Fallible;
use crate::infer::canonical::query_response;
use crate::infer::canonical::QueryOutlivesConstraint;
use crate::infer::canonical::QueryRegionConstraints;
use std::rc::Rc;
use syntax::source_map::DUMMY_SP;
use crate::traits::{ObligationCause, TraitEngine, TraitEngineExt};
@ -39,7 +39,7 @@ impl<'tcx, F, R, G> super::TypeOp<'tcx> for CustomTypeOp<F, G>
fn fully_perform(
self,
infcx: &InferCtxt<'_, 'tcx>,
) -> Fallible<(Self::Output, Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>)> {
) -> Fallible<(Self::Output, Option<Rc<QueryRegionConstraints<'tcx>>>)> {
if cfg!(debug_assertions) {
info!("fully_perform({:?})", self);
}
@ -62,7 +62,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn scrape_region_constraints<'tcx, R>(
infcx: &InferCtxt<'_, 'tcx>,
op: impl FnOnce() -> Fallible<InferOk<'tcx, R>>,
) -> Fallible<(R, Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>)> {
) -> Fallible<(R, Option<Rc<QueryRegionConstraints<'tcx>>>)> {
let mut fulfill_cx = TraitEngine::new(infcx.tcx);
let dummy_body_id = ObligationCause::dummy().body_id;
@ -92,7 +92,7 @@ fn scrape_region_constraints<'tcx, R>(
let region_constraint_data = infcx.take_and_reset_region_constraints();
let outlives = query_response::make_query_outlives(
let region_constraints = query_response::make_query_region_constraints(
infcx.tcx,
region_obligations
.iter()
@ -101,9 +101,9 @@ fn scrape_region_constraints<'tcx, R>(
&region_constraint_data,
);
if outlives.is_empty() {
if region_constraints.is_empty() {
Ok((value, None))
} else {
Ok((value, Some(Rc::new(outlives))))
Ok((value, Some(Rc::new(region_constraints))))
}
}

View File

@ -1,6 +1,6 @@
use crate::infer::canonical::{
Canonical, Canonicalized, CanonicalizedQueryResponse, OriginalQueryValues,
QueryOutlivesConstraint, QueryResponse,
QueryRegionConstraints, QueryOutlivesConstraint, QueryResponse,
};
use crate::infer::{InferCtxt, InferOk};
use std::fmt;
@ -32,7 +32,7 @@ pub trait TypeOp<'tcx>: Sized + fmt::Debug {
fn fully_perform(
self,
infcx: &InferCtxt<'_, 'tcx>,
) -> Fallible<(Self::Output, Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>)>;
) -> Fallible<(Self::Output, Option<Rc<QueryRegionConstraints<'tcx>>>)>;
}
/// "Query type ops" are type ops that are implemented using a
@ -140,16 +140,16 @@ impl<'tcx, Q> TypeOp<'tcx> for ParamEnvAnd<'tcx, Q>
fn fully_perform(
self,
infcx: &InferCtxt<'_, 'tcx>,
) -> Fallible<(Self::Output, Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>)> {
let mut qrc = vec![];
let r = Q::fully_perform_into(self, infcx, &mut qrc)?;
) -> Fallible<(Self::Output, Option<Rc<QueryRegionConstraints<'tcx>>>)> {
let mut outlives = vec![];
let r = Q::fully_perform_into(self, infcx, &mut outlives)?;
// Promote the final query-region-constraints into a
// (optional) ref-counted vector:
let opt_qrc = if qrc.is_empty() {
let opt_qrc = if outlives.is_empty() {
None
} else {
Some(Rc::new(qrc))
Some(Rc::new(QueryRegionConstraints { outlives }))
};
Ok((r, opt_qrc))

View File

@ -2,7 +2,7 @@
use crate::borrow_check::nll::type_check::{Locations, MirTypeckRegionConstraints};
use crate::borrow_check::nll::universal_regions::UniversalRegions;
use crate::borrow_check::nll::ToRegionVid;
use rustc::infer::canonical::QueryOutlivesConstraint;
use rustc::infer::canonical::QueryRegionConstraints;
use rustc::infer::outlives::free_region_map::FreeRegionRelations;
use rustc::infer::region_constraints::GenericKind;
use rustc::infer::InferCtxt;
@ -288,6 +288,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
}
for data in constraint_sets {
let QueryRegionConstraints { outlives } = &*data;
constraint_conversion::ConstraintConversion::new(
self.infcx,
&self.universal_regions,
@ -297,7 +298,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
Locations::All(DUMMY_SP),
ConstraintCategory::Internal,
&mut self.constraints,
).convert_all(&data);
).convert_all(outlives);
}
CreateResult {
@ -311,7 +312,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
/// either the return type of the MIR or one of its arguments. At
/// the same time, compute and add any implied bounds that come
/// from this local.
fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>> {
fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<Rc<QueryRegionConstraints<'tcx>>> {
debug!("add_implied_bounds(ty={:?})", ty);
let (bounds, constraints) =
self.param_env

View File

@ -6,7 +6,7 @@
use crate::dataflow::indexes::MovePathIndex;
use crate::dataflow::move_paths::MoveData;
use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces};
use rustc::infer::canonical::QueryOutlivesConstraint;
use rustc::infer::canonical::QueryRegionConstraints;
use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, Body};
use rustc::traits::query::dropck_outlives::DropckOutlivesResult;
use rustc::traits::query::type_op::outlives::DropckOutlives;
@ -88,7 +88,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
struct DropData<'tcx> {
dropck_result: DropckOutlivesResult<'tcx>,
region_constraint_data: Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>,
region_constraint_data: Option<Rc<QueryRegionConstraints<'tcx>>>,
}
struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {

View File

@ -23,7 +23,7 @@
use either::Either;
use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::infer::canonical::QueryOutlivesConstraint;
use rustc::infer::canonical::QueryRegionConstraints;
use rustc::infer::outlives::env::RegionBoundPairs;
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@ -1093,13 +1093,15 @@ fn push_region_constraints(
&mut self,
locations: Locations,
category: ConstraintCategory,
data: &[QueryOutlivesConstraint<'tcx>],
data: &QueryRegionConstraints<'tcx>,
) {
debug!(
"push_region_constraints: constraints generated at {:?} are {:#?}",
locations, data
);
let QueryRegionConstraints { outlives } = data;
constraint_conversion::ConstraintConversion::new(
self.infcx,
self.borrowck_context.universal_regions,
@ -1109,7 +1111,7 @@ fn push_region_constraints(
locations,
category,
&mut self.borrowck_context.constraints,
).convert_all(&data);
).convert_all(outlives);
}
/// Convenient wrapper around `relate_tys::relate_types` -- see
@ -2508,10 +2510,12 @@ fn prove_closure_bounds(
location: Location,
) -> ty::InstantiatedPredicates<'tcx> {
if let Some(closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements {
let closure_constraints =
closure_region_requirements.apply_requirements(tcx, def_id, substs);
let closure_constraints = QueryRegionConstraints {
outlives: closure_region_requirements.apply_requirements(tcx, def_id, substs)
};
let bounds_mapping = closure_constraints
.outlives
.iter()
.enumerate()
.filter_map(|(idx, constraint)| {