create just one subuniverse per binder -- no need for more, really

This commit is contained in:
Niko Matsakis 2018-09-07 16:58:35 -04:00
parent f8dd084ef1
commit 4c2fc333f0
2 changed files with 37 additions and 69 deletions

View File

@ -591,9 +591,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
-> (T, PlaceholderMap<'tcx>)
where T : TypeFoldable<'tcx>
{
let new_universe = self.create_subuniverse();
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
self.universe.set(self.universe().subuniverse());
self.tcx.mk_region(ty::RePlaceholder(self.universe(), br))
self.tcx.mk_region(ty::RePlaceholder(new_universe, br))
});
debug!("skolemize_bound_regions(binder={:?}, result={:?}, map={:?})",
@ -795,7 +796,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let skol_regions: FxHashSet<_> = placeholder_map.values().cloned().collect();
self.borrow_region_constraints()
.pop_placeholders(
self.universe(),
&skol_regions,
&snapshot.region_constraints_snapshot,
);

View File

@ -10,19 +10,19 @@
//! See README.md
use self::UndoLogEntry::*;
use self::CombineMapType::*;
use self::UndoLogEntry::*;
use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
use super::unify_key;
use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::unify as ut;
use ty::{self, Ty, TyCtxt};
use ty::{Region, RegionVid};
use ty::ReStatic;
use ty::{self, Ty, TyCtxt};
use ty::{BrFresh, ReLateBound, ReVar};
use ty::{Region, RegionVid};
use std::collections::BTreeMap;
use std::{cmp, fmt, mem, u32};
@ -495,13 +495,12 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
}
}
pub fn new_region_var(&mut self,
universe: ty::UniverseIndex,
origin: RegionVariableOrigin) -> RegionVid {
let vid = self.var_infos.push(RegionVariableInfo {
origin,
universe,
});
pub fn new_region_var(
&mut self,
universe: ty::UniverseIndex,
origin: RegionVariableOrigin,
) -> RegionVid {
let vid = self.var_infos.push(RegionVariableInfo { origin, universe });
let u_vid = self.unification_table
.new_key(unify_key::RegionVidKey { min_vid: vid });
@ -511,8 +510,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
}
debug!(
"created new region variable {:?} with origin {:?}",
vid,
origin
vid, origin
);
return vid;
}
@ -533,45 +531,19 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
/// created in that time.
pub fn pop_placeholders(
&mut self,
skolemization_count: ty::UniverseIndex,
skols: &FxHashSet<ty::Region<'tcx>>,
placeholders: &FxHashSet<ty::Region<'tcx>>,
snapshot: &RegionSnapshot,
) {
debug!("pop_placeholders(skols={:?})", skols);
debug!("pop_placeholders(placeholders={:?})", placeholders);
assert!(self.in_snapshot());
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
assert!(
skolemization_count.as_usize() >= skols.len(),
"popping more placeholder variables than actually exist, \
sc now = {:?}, skols.len = {:?}",
skolemization_count,
skols.len()
);
let last_to_pop = skolemization_count.subuniverse();
let first_to_pop = ty::UniverseIndex::from(last_to_pop.as_u32() - skols.len() as u32);
debug_assert! {
skols.iter()
.all(|&k| match *k {
ty::RePlaceholder(universe, _) =>
universe >= first_to_pop &&
universe < last_to_pop,
_ =>
false
}),
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
first_to_pop,
last_to_pop,
skols
}
let constraints_to_kill: Vec<usize> = self.undo_log
.iter()
.enumerate()
.rev()
.filter(|&(_, undo_entry)| kill_constraint(skols, undo_entry))
.filter(|&(_, undo_entry)| kill_constraint(placeholders, undo_entry))
.map(|(index, _)| index)
.collect();
@ -583,20 +555,20 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
return;
fn kill_constraint<'tcx>(
skols: &FxHashSet<ty::Region<'tcx>>,
placeholders: &FxHashSet<ty::Region<'tcx>>,
undo_entry: &UndoLogEntry<'tcx>,
) -> bool {
match undo_entry {
&AddConstraint(Constraint::VarSubVar(..)) => false,
&AddConstraint(Constraint::RegSubVar(a, _)) => skols.contains(&a),
&AddConstraint(Constraint::VarSubReg(_, b)) => skols.contains(&b),
&AddConstraint(Constraint::RegSubVar(a, _)) => placeholders.contains(&a),
&AddConstraint(Constraint::VarSubReg(_, b)) => placeholders.contains(&b),
&AddConstraint(Constraint::RegSubReg(a, b)) => {
skols.contains(&a) || skols.contains(&b)
placeholders.contains(&a) || placeholders.contains(&b)
}
&AddGiven(..) => false,
&AddVerify(_) => false,
&AddCombination(_, ref two_regions) => {
skols.contains(&two_regions.a) || skols.contains(&two_regions.b)
placeholders.contains(&two_regions.a) || placeholders.contains(&two_regions.b)
}
&AddVar(..) | &OpenSnapshot | &Purged | &CommitedSnapshot => false,
}
@ -713,9 +685,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
// cannot add constraints once regions are resolved
debug!(
"RegionConstraintCollector: make_subregion({:?}, {:?}) due to {:?}",
sub,
sup,
origin
sub, sup, origin
);
match (sub, sup) {
@ -854,19 +824,19 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
match *region {
ty::ReScope(..) |
ty::ReStatic |
ty::ReEmpty |
ty::ReErased |
ty::ReFree(..) |
ty::ReEarlyBound(..) => ty::UniverseIndex::ROOT,
ty::ReScope(..)
| ty::ReStatic
| ty::ReEmpty
| ty::ReErased
| ty::ReFree(..)
| ty::ReEarlyBound(..) => ty::UniverseIndex::ROOT,
ty::RePlaceholder(universe, _) => universe,
ty::ReClosureBound(vid) |
ty::ReVar(vid) => self.var_universe(vid),
ty::ReLateBound(..) =>
bug!("universe(): encountered bound region {:?}", region),
ty::ReCanonical(..) =>
bug!("region_universe(): encountered canonical region {:?}", region),
ty::ReClosureBound(vid) | ty::ReVar(vid) => self.var_universe(vid),
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),
ty::ReCanonical(..) => bug!(
"region_universe(): encountered canonical region {:?}",
region
),
}
}
@ -897,9 +867,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
) -> FxHashSet<ty::Region<'tcx>> {
debug!(
"tainted(mark={:?}, r0={:?}, directions={:?})",
mark,
r0,
directions
mark, r0, directions
);
// `result_set` acts as a worklist: we explore all outgoing