Rename various things to "implications"

This commit is contained in:
Niko Matsakis 2015-02-04 10:48:29 -05:00
parent df92fe3c96
commit 92d65ab2e9
2 changed files with 36 additions and 46 deletions

View File

@ -10,8 +10,6 @@
// #![warn(deprecated_mode)]
pub use self::WfConstraint::*;
use astconv::object_region_bounds;
use middle::infer::GenericKind;
use middle::subst::{ParamSpace, Subst, Substs};
@ -24,37 +22,37 @@ use util::ppaux::Repr;
// Helper functions related to manipulating region types.
pub enum WfConstraint<'tcx> {
RegionSubRegionConstraint(Option<Ty<'tcx>>, ty::Region, ty::Region),
RegionSubGenericConstraint(Option<Ty<'tcx>>, ty::Region, GenericKind<'tcx>),
pub enum Implication<'tcx> {
RegionSubRegion(Option<Ty<'tcx>>, ty::Region, ty::Region),
RegionSubGeneric(Option<Ty<'tcx>>, ty::Region, GenericKind<'tcx>),
}
struct Wf<'a, 'tcx: 'a> {
struct Implicator<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,
stack: Vec<(ty::Region, Option<Ty<'tcx>>)>,
out: Vec<WfConstraint<'tcx>>,
out: Vec<Implication<'tcx>>,
}
/// This routine computes the well-formedness constraints that must hold for the type `ty` to
/// appear in a context with lifetime `outer_region`
pub fn region_wf_constraints<'tcx>(
pub fn implications<'tcx>(
tcx: &ty::ctxt<'tcx>,
ty: Ty<'tcx>,
outer_region: ty::Region)
-> Vec<WfConstraint<'tcx>>
-> Vec<Implication<'tcx>>
{
let mut stack = Vec::new();
stack.push((outer_region, None));
let mut wf = Wf { tcx: tcx,
let mut wf = Implicator { tcx: tcx,
stack: stack,
out: Vec::new() };
wf.accumulate_from_ty(ty);
wf.out
}
impl<'a, 'tcx> Wf<'a, 'tcx> {
impl<'a, 'tcx> Implicator<'a, 'tcx> {
fn accumulate_from_ty(&mut self, ty: Ty<'tcx>) {
debug!("Wf::accumulate_from_ty(ty={})",
debug!("accumulate_from_ty(ty={})",
ty.repr(self.tcx));
match ty.sty {
@ -197,7 +195,7 @@ impl<'a, 'tcx> Wf<'a, 'tcx> {
opt_ty: Option<Ty<'tcx>>,
r_a: ty::Region,
r_b: ty::Region) {
self.out.push(RegionSubRegionConstraint(opt_ty, r_a, r_b));
self.out.push(Implication::RegionSubRegion(opt_ty, r_a, r_b));
}
/// Pushes a constraint that `param_ty` must outlive the top region on the stack.
@ -211,7 +209,7 @@ impl<'a, 'tcx> Wf<'a, 'tcx> {
fn push_projection_constraint_from_top(&mut self,
projection_ty: &ty::ProjectionTy<'tcx>) {
let &(region, opt_ty) = self.stack.last().unwrap();
self.out.push(RegionSubGenericConstraint(
self.out.push(Implication::RegionSubGeneric(
opt_ty, region, GenericKind::Projection(projection_ty.clone())));
}
@ -220,7 +218,7 @@ impl<'a, 'tcx> Wf<'a, 'tcx> {
region: ty::Region,
opt_ty: Option<Ty<'tcx>>,
param_ty: ty::ParamTy) {
self.out.push(RegionSubGenericConstraint(
self.out.push(Implication::RegionSubGeneric(
opt_ty, region, GenericKind::Param(param_ty)));
}
@ -372,22 +370,22 @@ impl<'a, 'tcx> Wf<'a, 'tcx> {
for &r_d in &required_region_bounds {
// Each of these is an instance of the `'c <= 'b`
// constraint above
self.out.push(RegionSubRegionConstraint(Some(ty), r_d, r_c));
self.out.push(Implication::RegionSubRegion(Some(ty), r_d, r_c));
}
}
}
impl<'tcx> Repr<'tcx> for WfConstraint<'tcx> {
impl<'tcx> Repr<'tcx> for Implication<'tcx> {
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
match *self {
RegionSubRegionConstraint(_, ref r_a, ref r_b) => {
format!("RegionSubRegionConstraint({}, {})",
Implication::RegionSubRegion(_, ref r_a, ref r_b) => {
format!("RegionSubRegion({}, {})",
r_a.repr(tcx),
r_b.repr(tcx))
}
RegionSubGenericConstraint(_, ref r, ref p) => {
format!("RegionSubGenericConstraint({}, {})",
Implication::RegionSubGeneric(_, ref r, ref p) => {
format!("RegionSubGeneric({}, {})",
r.repr(tcx),
p.repr(tcx))
}

View File

@ -335,25 +335,21 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
debug!("relate_free_regions(t={})", ty.repr(tcx));
let body_scope = CodeExtent::from_node_id(body_id);
let body_scope = ty::ReScope(body_scope);
let constraints =
implicator::region_wf_constraints(
tcx,
ty,
body_scope);
for constraint in &constraints {
debug!("constraint: {}", constraint.repr(tcx));
match *constraint {
implicator::RegionSubRegionConstraint(_,
let implications = implicator::implications(tcx, ty, body_scope);
for implication in implications {
debug!("implication: {}", implication.repr(tcx));
match implication {
implicator::Implication::RegionSubRegion(_,
ty::ReFree(free_a),
ty::ReFree(free_b)) => {
tcx.region_maps.relate_free_regions(free_a, free_b);
}
implicator::RegionSubRegionConstraint(_,
implicator::Implication::RegionSubRegion(_,
ty::ReFree(free_a),
ty::ReInfer(ty::ReVar(vid_b))) => {
self.fcx.inh.infcx.add_given(free_a, vid_b);
}
implicator::RegionSubRegionConstraint(..) => {
implicator::Implication::RegionSubRegion(..) => {
// In principle, we could record (and take
// advantage of) every relationship here, but
// we are also free not to -- it simply means
@ -364,8 +360,8 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
// relationship that arises here, but
// presently we do not.)
}
implicator::RegionSubGenericConstraint(_, r_a, ref generic_b) => {
debug!("RegionSubGenericConstraint: {} <= {}",
implicator::Implication::RegionSubGeneric(_, r_a, ref generic_b) => {
debug!("RegionSubGeneric: {} <= {}",
r_a.repr(tcx), generic_b.repr(tcx));
self.region_bound_pairs.push((r_a, generic_b.clone()));
@ -1481,25 +1477,21 @@ pub fn type_must_outlive<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
ty.repr(rcx.tcx()),
region.repr(rcx.tcx()));
let constraints =
implicator::region_wf_constraints(
rcx.tcx(),
ty,
region);
for constraint in &constraints {
debug!("constraint: {}", constraint.repr(rcx.tcx()));
match *constraint {
implicator::RegionSubRegionConstraint(None, r_a, r_b) => {
let implications = implicator::implications(rcx.tcx(), ty, region);
for implication in implications {
debug!("implication: {}", implication.repr(rcx.tcx()));
match implication {
implicator::Implication::RegionSubRegion(None, r_a, r_b) => {
rcx.fcx.mk_subr(origin.clone(), r_a, r_b);
}
implicator::RegionSubRegionConstraint(Some(ty), r_a, r_b) => {
implicator::Implication::RegionSubRegion(Some(ty), r_a, r_b) => {
let o1 = infer::ReferenceOutlivesReferent(ty, origin.span());
rcx.fcx.mk_subr(o1, r_a, r_b);
}
implicator::RegionSubGenericConstraint(None, r_a, ref generic_b) => {
implicator::Implication::RegionSubGeneric(None, r_a, ref generic_b) => {
generic_must_outlive(rcx, origin.clone(), r_a, generic_b);
}
implicator::RegionSubGenericConstraint(Some(ty), r_a, ref generic_b) => {
implicator::Implication::RegionSubGeneric(Some(ty), r_a, ref generic_b) => {
let o1 = infer::ReferenceOutlivesReferent(ty, origin.span());
generic_must_outlive(rcx, o1, r_a, generic_b);
}