split ReInfer into ReVar and ReSkolemized
this should reduce the size of ty::Region to 24 bytes (from 32), and they are treated differently in most cases anyway.
This commit is contained in:
parent
797d0ba59c
commit
316510f5e2
15 changed files with 65 additions and 76 deletions
|
@ -271,7 +271,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
|
|||
ty::ReEmpty => {
|
||||
mywrite!(w, "e");
|
||||
}
|
||||
ty::ReInfer(_) => {
|
||||
ty::ReVar(_) | ty::ReSkolemized(..) => {
|
||||
// these should not crop up after typeck
|
||||
cx.diag.handler().bug("cannot encode region variables");
|
||||
}
|
||||
|
|
|
@ -498,7 +498,7 @@ impl tr for ty::Region {
|
|||
ty::ReScope(scope) => {
|
||||
ty::ReScope(scope.tr(dcx))
|
||||
}
|
||||
ty::ReEmpty | ty::ReStatic | ty::ReInfer(..) => {
|
||||
ty::ReEmpty | ty::ReStatic | ty::ReVar(..) | ty::ReSkolemized(..) => {
|
||||
*self
|
||||
}
|
||||
ty::ReFree(ref fr) => {
|
||||
|
|
|
@ -340,14 +340,14 @@ impl<'cx, 'tcx> ty_fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
|
|||
|
||||
// Always make a fresh region variable for skolemized regions;
|
||||
// the higher-ranked decision procedures rely on this.
|
||||
ty::ReInfer(ty::ReSkolemized(..)) => { }
|
||||
ty::ReSkolemized(..) => { }
|
||||
|
||||
// For anything else, we make a region variable, unless we
|
||||
// are *equating*, in which case it's just wasteful.
|
||||
ty::ReEmpty |
|
||||
ty::ReStatic |
|
||||
ty::ReScope(..) |
|
||||
ty::ReInfer(ty::ReVar(..)) |
|
||||
ty::ReVar(..) |
|
||||
ty::ReFree(..) => {
|
||||
if !self.make_region_vars {
|
||||
return r;
|
||||
|
|
|
@ -196,9 +196,12 @@ impl<'tcx> ty::ctxt<'tcx> {
|
|||
|
||||
ty::ReEarlyBound(ref data) => (data.name.to_string(), None),
|
||||
|
||||
// I believe these cases should not occur (except when debugging,
|
||||
// perhaps)
|
||||
ty::ReInfer(_) | ty::ReLateBound(..) => {
|
||||
// FIXME(#13998) ReSkolemized should probably print like
|
||||
// ReFree rather than dumping Debug output on the user.
|
||||
//
|
||||
// We shouldn't really be having unification failures with ReVar
|
||||
// and ReLateBound through.
|
||||
ty::ReSkolemized(..) | ty::ReVar(_) | ty::ReLateBound(..) => {
|
||||
(format!("lifetime {:?}", region), None)
|
||||
}
|
||||
};
|
||||
|
|
|
@ -95,7 +95,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
|||
ty::ReStatic |
|
||||
ty::ReFree(_) |
|
||||
ty::ReScope(_) |
|
||||
ty::ReInfer(_) |
|
||||
ty::ReVar(_) |
|
||||
ty::ReSkolemized(..) |
|
||||
ty::ReEmpty => {
|
||||
// replace all free regions with 'static
|
||||
ty::ReStatic
|
||||
|
|
|
@ -335,7 +335,7 @@ fn var_ids<'a, 'tcx>(fields: &CombineFields<'a, 'tcx>,
|
|||
-> Vec<ty::RegionVid> {
|
||||
map.iter()
|
||||
.map(|(_, r)| match *r {
|
||||
ty::ReInfer(ty::ReVar(r)) => { r }
|
||||
ty::ReVar(r) => { r }
|
||||
r => {
|
||||
fields.tcx().sess.span_bug(
|
||||
fields.trace.origin.span(),
|
||||
|
@ -347,7 +347,7 @@ fn var_ids<'a, 'tcx>(fields: &CombineFields<'a, 'tcx>,
|
|||
|
||||
fn is_var_in_set(new_vars: &[ty::RegionVid], r: ty::Region) -> bool {
|
||||
match r {
|
||||
ty::ReInfer(ty::ReVar(ref v)) => new_vars.iter().any(|x| x == v),
|
||||
ty::ReVar(ref v) => new_vars.iter().any(|x| x == v),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
@ -443,7 +443,7 @@ impl<'a,'tcx> InferCtxtExt for InferCtxt<'a,'tcx> {
|
|||
}
|
||||
|
||||
region_vars.retain(|®ion_vid| {
|
||||
let r = ty::ReInfer(ty::ReVar(region_vid));
|
||||
let r = ty::ReVar(region_vid);
|
||||
!escaping_region_vars.contains(&r)
|
||||
});
|
||||
|
||||
|
@ -561,7 +561,7 @@ pub fn leak_check<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
|
|||
// Each skolemized should only be relatable to itself
|
||||
// or new variables:
|
||||
match tainted_region {
|
||||
ty::ReInfer(ty::ReVar(vid)) => {
|
||||
ty::ReVar(vid) => {
|
||||
if new_vars.iter().any(|&x| x == vid) { continue; }
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -1059,7 +1059,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region {
|
||||
ty::ReInfer(ty::ReVar(self.region_vars.new_region_var(origin)))
|
||||
ty::ReVar(self.region_vars.new_region_var(origin))
|
||||
}
|
||||
|
||||
pub fn region_vars_for_defs(&self,
|
||||
|
|
|
@ -25,7 +25,7 @@ use middle::free_region::FreeRegionMap;
|
|||
use middle::region;
|
||||
use middle::ty::{self, Ty, TypeError};
|
||||
use middle::ty::{BoundRegion, FreeRegion, Region, RegionVid};
|
||||
use middle::ty::{ReEmpty, ReStatic, ReInfer, ReFree, ReEarlyBound};
|
||||
use middle::ty::{ReEmpty, ReStatic, ReFree, ReEarlyBound};
|
||||
use middle::ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
|
||||
use middle::ty_relate::RelateResult;
|
||||
use util::common::indenter;
|
||||
|
@ -373,7 +373,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
|
||||
let sc = self.skolemization_count.get();
|
||||
self.skolemization_count.set(sc + 1);
|
||||
ReInfer(ReSkolemized(sc, br))
|
||||
ReSkolemized(sc, br)
|
||||
}
|
||||
|
||||
pub fn new_bound(&self, debruijn: ty::DebruijnIndex) -> Region {
|
||||
|
@ -510,13 +510,13 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
(_, ReStatic) => {
|
||||
// all regions are subregions of static, so we can ignore this
|
||||
}
|
||||
(ReInfer(ReVar(sub_id)), ReInfer(ReVar(sup_id))) => {
|
||||
(ReVar(sub_id), ReVar(sup_id)) => {
|
||||
self.add_constraint(ConstrainVarSubVar(sub_id, sup_id), origin);
|
||||
}
|
||||
(r, ReInfer(ReVar(sup_id))) => {
|
||||
(r, ReVar(sup_id)) => {
|
||||
self.add_constraint(ConstrainRegSubVar(r, sup_id), origin);
|
||||
}
|
||||
(ReInfer(ReVar(sub_id)), r) => {
|
||||
(ReVar(sub_id), r) => {
|
||||
self.add_constraint(ConstrainVarSubReg(sub_id, r), origin);
|
||||
}
|
||||
_ => {
|
||||
|
@ -621,7 +621,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
let vars = TwoRegions { a: a, b: b };
|
||||
match self.combine_map(t).borrow().get(&vars) {
|
||||
Some(&c) => {
|
||||
return ReInfer(ReVar(c));
|
||||
return ReVar(c);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
@ -630,10 +630,10 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
if self.in_snapshot() {
|
||||
self.undo_log.borrow_mut().push(AddCombination(t, vars));
|
||||
}
|
||||
relate(self, a, ReInfer(ReVar(c)));
|
||||
relate(self, b, ReInfer(ReVar(c)));
|
||||
relate(self, a, ReVar(c));
|
||||
relate(self, b, ReVar(c));
|
||||
debug!("combine_vars() c={:?}", c);
|
||||
ReInfer(ReVar(c))
|
||||
ReVar(c)
|
||||
}
|
||||
|
||||
pub fn vars_created_since_snapshot(&self, mark: &RegionSnapshot)
|
||||
|
@ -672,22 +672,22 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
&AddConstraint(ConstrainVarSubVar(a, b)) => {
|
||||
consider_adding_bidirectional_edges(
|
||||
&mut result_set, r,
|
||||
ReInfer(ReVar(a)), ReInfer(ReVar(b)));
|
||||
ReVar(a), ReVar(b));
|
||||
}
|
||||
&AddConstraint(ConstrainRegSubVar(a, b)) => {
|
||||
consider_adding_bidirectional_edges(
|
||||
&mut result_set, r,
|
||||
a, ReInfer(ReVar(b)));
|
||||
a, ReVar(b));
|
||||
}
|
||||
&AddConstraint(ConstrainVarSubReg(a, b)) => {
|
||||
consider_adding_bidirectional_edges(
|
||||
&mut result_set, r,
|
||||
ReInfer(ReVar(a)), b);
|
||||
ReVar(a), b);
|
||||
}
|
||||
&AddGiven(a, b) => {
|
||||
consider_adding_bidirectional_edges(
|
||||
&mut result_set, r,
|
||||
ReFree(a), ReInfer(ReVar(b)));
|
||||
ReFree(a), ReVar(b));
|
||||
}
|
||||
&AddVerify(i) => {
|
||||
match (*self.verifys.borrow())[i] {
|
||||
|
@ -775,7 +775,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
r // everything lives longer than empty
|
||||
}
|
||||
|
||||
(ReInfer(ReVar(v_id)), _) | (_, ReInfer(ReVar(v_id))) => {
|
||||
(ReVar(v_id), _) | (_, ReVar(v_id)) => {
|
||||
self.tcx.sess.span_bug(
|
||||
(*self.var_origins.borrow())[v_id.index as usize].span(),
|
||||
&format!("lub_concrete_regions invoked with \
|
||||
|
@ -818,8 +818,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
|
||||
// For these types, we cannot define any additional
|
||||
// relationship:
|
||||
(ReInfer(ReSkolemized(..)), _) |
|
||||
(_, ReInfer(ReSkolemized(..))) => {
|
||||
(ReSkolemized(..), _) |
|
||||
(_, ReSkolemized(..)) => {
|
||||
if a == b {a} else {ReStatic}
|
||||
}
|
||||
}
|
||||
|
@ -853,8 +853,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
Ok(ReEmpty)
|
||||
}
|
||||
|
||||
(ReInfer(ReVar(v_id)), _) |
|
||||
(_, ReInfer(ReVar(v_id))) => {
|
||||
(ReVar(v_id), _) |
|
||||
(_, ReVar(v_id)) => {
|
||||
self.tcx.sess.span_bug(
|
||||
(*self.var_origins.borrow())[v_id.index as usize].span(),
|
||||
&format!("glb_concrete_regions invoked with \
|
||||
|
@ -890,8 +890,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
|
||||
// For these types, we cannot define any additional
|
||||
// relationship:
|
||||
(ReInfer(ReSkolemized(..)), _) |
|
||||
(_, ReInfer(ReSkolemized(..))) => {
|
||||
(ReSkolemized(..), _) |
|
||||
(_, ReSkolemized(..)) => {
|
||||
if a == b {
|
||||
Ok(a)
|
||||
} else {
|
||||
|
@ -1632,7 +1632,7 @@ impl<'tcx> fmt::Debug for Verify<'tcx> {
|
|||
|
||||
fn normalize(values: &Vec<VarValue>, r: ty::Region) -> ty::Region {
|
||||
match r {
|
||||
ty::ReInfer(ReVar(rid)) => lookup(values, rid),
|
||||
ty::ReVar(rid) => lookup(values, rid),
|
||||
_ => r
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
|
|||
|
||||
fn fold_region(&mut self, r: ty::Region) -> ty::Region {
|
||||
match r {
|
||||
ty::ReInfer(ty::ReVar(rid)) => self.infcx.region_vars.resolve_var(rid),
|
||||
ty::ReVar(rid) => self.infcx.region_vars.resolve_var(rid),
|
||||
_ => r,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#![allow(non_camel_case_types)]
|
||||
|
||||
pub use self::InferTy::*;
|
||||
pub use self::InferRegion::*;
|
||||
pub use self::ImplOrTraitItemId::*;
|
||||
pub use self::ClosureKind::*;
|
||||
pub use self::Variance::*;
|
||||
|
@ -1529,7 +1528,11 @@ pub enum Region {
|
|||
ReStatic,
|
||||
|
||||
/// A region variable. Should not exist after typeck.
|
||||
ReInfer(InferRegion),
|
||||
ReVar(RegionVid),
|
||||
|
||||
/// A skolemized region - basically the higher-ranked version of ReFree.
|
||||
/// Should not exist after typeck.
|
||||
ReSkolemized(u32, BoundRegion),
|
||||
|
||||
/// Empty lifetime is for data that is never accessed.
|
||||
/// Bottom in the region lattice. We treat ReEmpty somewhat
|
||||
|
@ -1648,7 +1651,7 @@ impl Region {
|
|||
|
||||
pub fn needs_infer(&self) -> bool {
|
||||
match *self {
|
||||
ty::ReInfer(..) => true,
|
||||
ty::ReVar(..) | ty::ReSkolemized(..) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
@ -2187,29 +2190,6 @@ pub enum UnconstrainedNumeric {
|
|||
}
|
||||
|
||||
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, Hash, Debug, Copy)]
|
||||
pub enum InferRegion {
|
||||
ReVar(RegionVid),
|
||||
ReSkolemized(u32, BoundRegion)
|
||||
}
|
||||
|
||||
impl cmp::PartialEq for InferRegion {
|
||||
fn eq(&self, other: &InferRegion) -> bool {
|
||||
match ((*self), *other) {
|
||||
(ReVar(rva), ReVar(rvb)) => {
|
||||
rva == rvb
|
||||
}
|
||||
(ReSkolemized(rva, _), ReSkolemized(rvb, _)) => {
|
||||
rva == rvb
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
fn ne(&self, other: &InferRegion) -> bool {
|
||||
!((*self) == (*other))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TyVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "_#{}t", self.index)
|
||||
|
@ -3722,7 +3702,8 @@ impl FlagComputation {
|
|||
|
||||
fn add_region(&mut self, r: Region) {
|
||||
match r {
|
||||
ty::ReInfer(_) => { self.add_flags(TypeFlags::HAS_RE_INFER); }
|
||||
ty::ReVar(..) |
|
||||
ty::ReSkolemized(..) => { self.add_flags(TypeFlags::HAS_RE_INFER); }
|
||||
ty::ReLateBound(debruijn, _) => { self.add_depth(debruijn.depth); }
|
||||
ty::ReEarlyBound(..) => { self.add_flags(TypeFlags::HAS_RE_EARLY_BOUND); }
|
||||
ty::ReStatic => {}
|
||||
|
@ -5728,7 +5709,7 @@ impl<'tcx> ctxt<'tcx> {
|
|||
self.note_and_explain_region("concrete lifetime that was found is ",
|
||||
conc_region, "");
|
||||
}
|
||||
RegionsOverlyPolymorphic(_, ty::ReInfer(ty::ReVar(_))) => {
|
||||
RegionsOverlyPolymorphic(_, ty::ReVar(_)) => {
|
||||
// don't bother to print out the message below for
|
||||
// inference variables, it's not very illuminating.
|
||||
}
|
||||
|
@ -6479,7 +6460,8 @@ impl<'tcx> ctxt<'tcx> {
|
|||
ReLateBound(..) |
|
||||
ReFree(..) |
|
||||
ReScope(..) |
|
||||
ReInfer(..) => {
|
||||
ReVar(..) |
|
||||
ReSkolemized(..) => {
|
||||
tcx.sess.bug("unexpected region found when hashing a type")
|
||||
}
|
||||
}
|
||||
|
@ -7338,8 +7320,9 @@ impl HasTypeFlags for Region {
|
|||
}
|
||||
}
|
||||
if flags.intersects(TypeFlags::HAS_RE_INFER) {
|
||||
if let ty::ReInfer(_) = *self {
|
||||
return true;
|
||||
match *self {
|
||||
ty::ReVar(_) | ty::ReSkolemized(..) => { return true }
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
false
|
||||
|
|
|
@ -13,7 +13,7 @@ use middle::def_id::DefId;
|
|||
use middle::subst::{self, Subst};
|
||||
use middle::ty::{BoundRegion, BrAnon, BrNamed};
|
||||
use middle::ty::{ReEarlyBound, BrFresh, ctxt};
|
||||
use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty};
|
||||
use middle::ty::{ReFree, ReScope, ReStatic, Region, ReEmpty};
|
||||
use middle::ty::{ReSkolemized, ReVar, BrEnv};
|
||||
use middle::ty::{TyBool, TyChar, TyStruct, TyEnum};
|
||||
use middle::ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyBareFn};
|
||||
|
@ -413,11 +413,11 @@ impl fmt::Debug for ty::Region {
|
|||
|
||||
ty::ReStatic => write!(f, "ReStatic"),
|
||||
|
||||
ty::ReInfer(ReVar(ref vid)) => {
|
||||
ty::ReVar(ref vid) => {
|
||||
write!(f, "{:?}", vid)
|
||||
}
|
||||
|
||||
ty::ReInfer(ReSkolemized(id, ref bound_region)) => {
|
||||
ty::ReSkolemized(id, ref bound_region) => {
|
||||
write!(f, "ReSkolemized({}, {:?})", id, bound_region)
|
||||
}
|
||||
|
||||
|
@ -442,11 +442,11 @@ impl fmt::Display for ty::Region {
|
|||
}
|
||||
ty::ReLateBound(_, br) |
|
||||
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
|
||||
ty::ReInfer(ReSkolemized(_, br)) => {
|
||||
ty::ReSkolemized(_, br) => {
|
||||
write!(f, "{}", br)
|
||||
}
|
||||
ty::ReScope(_) |
|
||||
ty::ReInfer(ReVar(_)) => Ok(()),
|
||||
ty::ReVar(_) => Ok(()),
|
||||
ty::ReStatic => write!(f, "'static"),
|
||||
ty::ReEmpty => write!(f, "'<empty>"),
|
||||
}
|
||||
|
|
|
@ -377,7 +377,8 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
|
|||
ty::ReEmpty |
|
||||
ty::ReLateBound(..) |
|
||||
ty::ReEarlyBound(..) |
|
||||
ty::ReInfer(..) => {
|
||||
ty::ReVar(..) |
|
||||
ty::ReSkolemized(..) => {
|
||||
self.tcx().sess.span_bug(
|
||||
cmt.span,
|
||||
&format!("invalid borrow lifetime: {:?}",
|
||||
|
|
|
@ -428,7 +428,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
|
|||
debug!("implication: {:?}", implication);
|
||||
match implication {
|
||||
ImpliedBound::RegionSubRegion(ty::ReFree(free_a),
|
||||
ty::ReInfer(ty::ReVar(vid_b))) => {
|
||||
ty::ReVar(vid_b)) => {
|
||||
self.fcx.inh.infcx.add_given(free_a, vid_b);
|
||||
}
|
||||
ImpliedBound::RegionSubParam(r_a, param_b) => {
|
||||
|
|
|
@ -1025,8 +1025,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
// methods or in fn types.
|
||||
}
|
||||
|
||||
ty::ReFree(..) | ty::ReScope(..) | ty::ReInfer(..) |
|
||||
ty::ReEmpty => {
|
||||
ty::ReFree(..) | ty::ReScope(..) | ty::ReVar(..) |
|
||||
ty::ReSkolemized(..) | ty::ReEmpty => {
|
||||
// We don't expect to see anything but 'static or bound
|
||||
// regions when visiting member types or method types.
|
||||
self.tcx()
|
||||
|
|
|
@ -772,7 +772,8 @@ impl Clean<Option<Lifetime>> for ty::Region {
|
|||
ty::ReLateBound(..) |
|
||||
ty::ReFree(..) |
|
||||
ty::ReScope(..) |
|
||||
ty::ReInfer(..) |
|
||||
ty::ReVar(..) |
|
||||
ty::ReSkolemized(..) |
|
||||
ty::ReEmpty(..) => None
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue