rename from "in constraint" to "pick constraint"
This commit is contained in:
parent
c36205b48e
commit
02609b85e3
5 changed files with 44 additions and 39 deletions
|
@ -654,14 +654,14 @@ pub fn make_query_outlives<'tcx>(
|
||||||
constraints,
|
constraints,
|
||||||
verifys,
|
verifys,
|
||||||
givens,
|
givens,
|
||||||
in_constraints,
|
pick_constraints,
|
||||||
} = region_constraints;
|
} = region_constraints;
|
||||||
|
|
||||||
assert!(verifys.is_empty());
|
assert!(verifys.is_empty());
|
||||||
assert!(givens.is_empty());
|
assert!(givens.is_empty());
|
||||||
|
|
||||||
// FIXME(ndm) -- we have to think about what to do here, perhaps
|
// FIXME(ndm) -- we have to think about what to do here, perhaps
|
||||||
assert!(in_constraints.is_empty());
|
assert!(pick_constraints.is_empty());
|
||||||
|
|
||||||
let outlives: Vec<_> = constraints
|
let outlives: Vec<_> = constraints
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::infer::region_constraints::Constraint;
|
use crate::infer::region_constraints::Constraint;
|
||||||
use crate::infer::region_constraints::GenericKind;
|
use crate::infer::region_constraints::GenericKind;
|
||||||
use crate::infer::region_constraints::InConstraint;
|
use crate::infer::region_constraints::PickConstraint;
|
||||||
use crate::infer::region_constraints::RegionConstraintData;
|
use crate::infer::region_constraints::RegionConstraintData;
|
||||||
use crate::infer::region_constraints::VarInfos;
|
use crate::infer::region_constraints::VarInfos;
|
||||||
use crate::infer::region_constraints::VerifyBound;
|
use crate::infer::region_constraints::VerifyBound;
|
||||||
|
@ -118,7 +118,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
||||||
|
|
||||||
let graph = self.construct_graph();
|
let graph = self.construct_graph();
|
||||||
self.expand_givens(&graph);
|
self.expand_givens(&graph);
|
||||||
self.enforce_in_constraints(&graph, &mut var_data);
|
self.enforce_pick_constraints(&graph, &mut var_data);
|
||||||
self.expansion(&mut var_data);
|
self.expansion(&mut var_data);
|
||||||
self.collect_errors(&mut var_data, errors);
|
self.collect_errors(&mut var_data, errors);
|
||||||
self.collect_var_errors(&var_data, &graph, errors);
|
self.collect_var_errors(&var_data, &graph, errors);
|
||||||
|
@ -200,63 +200,63 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
||||||
/// - if `'o[i] <= 'b` is false, then `'o[i]` is not an option
|
/// - if `'o[i] <= 'b` is false, then `'o[i]` is not an option
|
||||||
///
|
///
|
||||||
/// Hopefully this narrows it down to just one option.
|
/// Hopefully this narrows it down to just one option.
|
||||||
fn enforce_in_constraints(
|
fn enforce_pick_constraints(
|
||||||
&self,
|
&self,
|
||||||
graph: &RegionGraph<'tcx>,
|
graph: &RegionGraph<'tcx>,
|
||||||
var_values: &mut LexicalRegionResolutions<'tcx>,
|
var_values: &mut LexicalRegionResolutions<'tcx>,
|
||||||
) {
|
) {
|
||||||
for in_constraint in &self.data.in_constraints {
|
for pick_constraint in &self.data.pick_constraints {
|
||||||
let _ = self.enforce_in_constraint(graph, in_constraint, var_values);
|
let _ = self.enforce_pick_constraint(graph, pick_constraint, var_values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enforce_in_constraint(
|
fn enforce_pick_constraint(
|
||||||
&self,
|
&self,
|
||||||
graph: &RegionGraph<'tcx>,
|
graph: &RegionGraph<'tcx>,
|
||||||
in_constraint: &InConstraint<'tcx>,
|
pick_constraint: &PickConstraint<'tcx>,
|
||||||
var_values: &mut LexicalRegionResolutions<'tcx>,
|
var_values: &mut LexicalRegionResolutions<'tcx>,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
debug!("enforce_in_constraint(in_constraint={:#?})", in_constraint);
|
debug!("enforce_pick_constraint(pick_constraint={:#?})", pick_constraint);
|
||||||
|
|
||||||
// the constraint is some inference variable (`vid`) which
|
// the constraint is some inference variable (`vid`) which
|
||||||
// must be equal to one of the options
|
// must be equal to one of the options
|
||||||
let vid = match in_constraint.region {
|
let pick_vid = match pick_constraint.pick_region {
|
||||||
ty::ReVar(vid) => *vid,
|
ty::ReVar(vid) => *vid,
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// find all the "bounds" -- that is, each region `b` such that
|
// find all the "bounds" -- that is, each region `b` such that
|
||||||
// `r0 <= b` must hold.
|
// `r0 <= b` must hold.
|
||||||
let (bounds, _) = self.collect_concrete_regions(graph, vid, OUTGOING, None);
|
let (pick_bounds, _) = self.collect_concrete_regions(graph, pick_vid, OUTGOING, None);
|
||||||
|
|
||||||
// get an iterator over the *available options* -- that is,
|
// get an iterator over the *available options* -- that is,
|
||||||
// each constraint regions `o` where `o <= b` for all the
|
// each constraint regions `o` where `o <= b` for all the
|
||||||
// bounds `b`.
|
// bounds `b`.
|
||||||
debug!("enforce_in_constraint: bounds={:#?}", bounds);
|
debug!("enforce_pick_constraint: bounds={:#?}", pick_bounds);
|
||||||
let mut options = in_constraint.in_regions.iter().filter(|option| {
|
let mut options = pick_constraint.option_regions.iter().filter(|option| {
|
||||||
bounds.iter().all(|bound| self.sub_concrete_regions(option, bound.region))
|
pick_bounds.iter().all(|bound| self.sub_concrete_regions(option, bound.region))
|
||||||
});
|
});
|
||||||
|
|
||||||
// if there >1 option, we only make a choice if there is a
|
// if there >1 option, we only make a choice if there is a
|
||||||
// single *least* choice -- i.e., some available region that
|
// single *least* choice -- i.e., some available region that
|
||||||
// is `<=` all the others.
|
// is `<=` all the others.
|
||||||
let mut least_choice = options.next().ok_or(())?;
|
let mut least_choice = options.next().ok_or(())?;
|
||||||
debug!("enforce_in_constraint: least_choice={:?}", least_choice);
|
debug!("enforce_pick_constraint: least_choice={:?}", least_choice);
|
||||||
for option in options {
|
for option in options {
|
||||||
debug!("enforce_in_constraint: option={:?}", option);
|
debug!("enforce_pick_constraint: option={:?}", option);
|
||||||
if !self.sub_concrete_regions(least_choice, option) {
|
if !self.sub_concrete_regions(least_choice, option) {
|
||||||
if self.sub_concrete_regions(option, least_choice) {
|
if self.sub_concrete_regions(option, least_choice) {
|
||||||
debug!("enforce_in_constraint: new least choice");
|
debug!("enforce_pick_constraint: new least choice");
|
||||||
least_choice = option;
|
least_choice = option;
|
||||||
} else {
|
} else {
|
||||||
debug!("enforce_in_constraint: no least choice");
|
debug!("enforce_pick_constraint: no least choice");
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("enforce_in_constraint: final least choice = {:?}", least_choice);
|
debug!("enforce_pick_constraint: final least choice = {:?}", least_choice);
|
||||||
*var_values.value_mut(vid) = VarValue::Value(least_choice);
|
*var_values.value_mut(pick_vid) = VarValue::Value(least_choice);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -907,7 +907,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
/// Require that the region `r` be equal to one of the regions in
|
/// Require that the region `r` be equal to one of the regions in
|
||||||
/// the set `regions`.
|
/// the set `regions`.
|
||||||
pub fn in_constraint(
|
pub fn pick_constraint(
|
||||||
&self,
|
&self,
|
||||||
origin: SubregionOrigin<'tcx>,
|
origin: SubregionOrigin<'tcx>,
|
||||||
region: ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
|
@ -915,7 +915,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
) {
|
) {
|
||||||
debug!("sub_regions({:?} <: {:?})", region, in_regions);
|
debug!("sub_regions({:?} <: {:?})", region, in_regions);
|
||||||
self.borrow_region_constraints()
|
self.borrow_region_constraints()
|
||||||
.in_constraint(origin, region, in_regions);
|
.pick_constraint(origin, region, in_regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subtype_predicate(
|
pub fn subtype_predicate(
|
||||||
|
|
|
@ -421,7 +421,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
|
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
|
||||||
tcx: self.tcx,
|
tcx: self.tcx,
|
||||||
op: |r| self.in_constraint(infer::CallReturn(span), r, &in_regions),
|
op: |r| self.pick_constraint(infer::CallReturn(span), r, &in_regions),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,10 +79,10 @@ pub struct RegionConstraintData<'tcx> {
|
||||||
/// be a region variable (or neither, as it happens).
|
/// be a region variable (or neither, as it happens).
|
||||||
pub constraints: BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
|
pub constraints: BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
|
||||||
|
|
||||||
/// Constraints of the form `R0 in [R1, ..., Rn]`, meaning that
|
/// Constraints of the form `pick R0 from [R1, ..., Rn]`, meaning that
|
||||||
/// `R0` must be equal to one of the regions `R1..Rn`. These occur
|
/// `R0` must be equal to one of the regions `R1..Rn`. These occur
|
||||||
/// with `impl Trait` quite frequently.
|
/// with `impl Trait` quite frequently.
|
||||||
pub in_constraints: Vec<InConstraint<'tcx>>,
|
pub pick_constraints: Vec<PickConstraint<'tcx>>,
|
||||||
|
|
||||||
/// A "verify" is something that we need to verify after inference
|
/// A "verify" is something that we need to verify after inference
|
||||||
/// is done, but which does not directly affect inference in any
|
/// is done, but which does not directly affect inference in any
|
||||||
|
@ -143,12 +143,17 @@ impl Constraint<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Requires that `region` must be equal to one of the regions in `in_regions`.
|
/// Requires that `region` must be equal to one of the regions in `option_regions`.
|
||||||
|
/// We often denote this using the syntax:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// pick R0 from [O1..On]
|
||||||
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct InConstraint<'tcx> {
|
pub struct PickConstraint<'tcx> {
|
||||||
pub origin: SubregionOrigin<'tcx>,
|
pub origin: SubregionOrigin<'tcx>,
|
||||||
pub region: Region<'tcx>,
|
pub pick_region: Region<'tcx>,
|
||||||
pub in_regions: Rc<Vec<Region<'tcx>>>,
|
pub option_regions: Rc<Vec<Region<'tcx>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `VerifyGenericBound(T, _, R, RS)`: the parameter type `T` (or
|
/// `VerifyGenericBound(T, _, R, RS)`: the parameter type `T` (or
|
||||||
|
@ -657,20 +662,20 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn in_constraint(
|
pub fn pick_constraint(
|
||||||
&mut self,
|
&mut self,
|
||||||
origin: SubregionOrigin<'tcx>,
|
origin: SubregionOrigin<'tcx>,
|
||||||
region: ty::Region<'tcx>,
|
pick_region: ty::Region<'tcx>,
|
||||||
in_regions: &Rc<Vec<ty::Region<'tcx>>>,
|
option_regions: &Rc<Vec<ty::Region<'tcx>>>,
|
||||||
) {
|
) {
|
||||||
debug!("in_constraint({:?} in {:#?})", region, in_regions);
|
debug!("pick_constraint({:?} in {:#?})", pick_region, option_regions);
|
||||||
|
|
||||||
if in_regions.iter().any(|&r| r == region) {
|
if option_regions.iter().any(|&r| r == pick_region) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.data.in_constraints.push(InConstraint {
|
self.data.pick_constraints.push(PickConstraint {
|
||||||
origin, region, in_regions: in_regions.clone()
|
origin, pick_region, option_regions: option_regions.clone()
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -938,10 +943,10 @@ impl<'tcx> RegionConstraintData<'tcx> {
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
let RegionConstraintData {
|
let RegionConstraintData {
|
||||||
constraints,
|
constraints,
|
||||||
in_constraints,
|
pick_constraints,
|
||||||
verifys,
|
verifys,
|
||||||
givens,
|
givens,
|
||||||
} = self;
|
} = self;
|
||||||
constraints.is_empty() && in_constraints.is_empty() && verifys.is_empty() && givens.is_empty()
|
constraints.is_empty() && pick_constraints.is_empty() && verifys.is_empty() && givens.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue