Skip to content

Commit

Permalink
change skolemizations to use universe index
Browse files Browse the repository at this point in the history
These changes were meant to be in
2b18d8fe9dc05415a8e6b7cadf879c7f7ebe020a (rebased from
12a2305), but I messed up the rebase a
bit as the file had been moved.
  • Loading branch information
sgrif committed Mar 1, 2018
1 parent 17df455 commit 755bdaa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
10 changes: 10 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions src/librustc/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::unify_key;

use rustc_data_structures::indexed_vec::{IndexVec, Idx};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::unify::{self, UnificationTable};
use rustc_data_structures::unify as ut;
use ty::{self, Ty, TyCtxt};
use ty::{Region, RegionVid};
use ty::ReStatic;
Expand Down Expand Up @@ -48,7 +48,7 @@ pub struct RegionConstraintCollector<'tcx> {
glbs: CombineMap<'tcx>,

/// Number of skolemized variables currently active.
skolemization_count: u32,
skolemization_count: ty::UniverseIndex,

/// Global counter used during the GLB algorithm to create unique
/// names for fresh bound regions
Expand All @@ -73,7 +73,7 @@ pub struct RegionConstraintCollector<'tcx> {
/// is iterating to a fixed point, because otherwise we sometimes
/// would wind up with a fresh stream of region variables that
/// have been equated but appear distinct.
unification_table: UnificationTable<ty::RegionVid>,
unification_table: ut::UnificationTable<ut::InPlace<ty::RegionVid>>,
}

pub type VarOrigins = IndexVec<RegionVid, RegionVariableOrigin>;
Expand Down Expand Up @@ -232,8 +232,8 @@ type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;

pub struct RegionSnapshot {
length: usize,
region_snapshot: unify::Snapshot<ty::RegionVid>,
skolemization_count: u32,
region_snapshot: ut::Snapshot<ut::InPlace<ty::RegionVid>>,
skolemization_count: ty::UniverseIndex,
}

/// When working with skolemized regions, we often wish to find all of
Expand Down Expand Up @@ -277,10 +277,10 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
data: RegionConstraintData::default(),
lubs: FxHashMap(),
glbs: FxHashMap(),
skolemization_count: 0,
skolemization_count: ty::UniverseIndex::ROOT,
bound_count: 0,
undo_log: Vec::new(),
unification_table: UnificationTable::new(),
unification_table: ut::UnificationTable::new(),
}
}

Expand Down Expand Up @@ -329,7 +329,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
unification_table,
} = self;

assert_eq!(*skolemization_count, 0);
assert_eq!(skolemization_count.as_usize(), 0);

// Clear the tables of (lubs, glbs), so that we will create
// fresh regions if we do a LUB operation. As it happens,
Expand All @@ -342,7 +342,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
// un-unified" state. Note that when we unify `a` and `b`, we
// also insert `a <= b` and a `b <= a` edges, so the
// `RegionConstraintData` contains the relationship here.
*unification_table = UnificationTable::new();
*unification_table = ut::UnificationTable::new();
for vid in var_origins.indices() {
unification_table.new_key(unify_key::RegionVidKey { min_vid: vid });
}
Expand Down Expand Up @@ -371,7 +371,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
assert!(
self.skolemization_count == snapshot.skolemization_count,
"failed to pop skolemized regions: {} now vs {} at start",
"failed to pop skolemized regions: {:?} now vs {:?} at start",
self.skolemization_count,
snapshot.skolemization_count
);
Expand Down Expand Up @@ -479,9 +479,9 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
assert!(self.in_snapshot());
assert!(self.undo_log[snapshot.length] == OpenSnapshot);

let sc = self.skolemization_count;
self.skolemization_count = sc + 1;
tcx.mk_region(ReSkolemized(ty::SkolemizedRegionVid { index: sc }, br))
let universe = self.skolemization_count.subuniverse();
self.skolemization_count = universe;
tcx.mk_region(ReSkolemized(universe, br))
}

/// Removes all the edges to/from the skolemized regions that are
Expand All @@ -499,34 +499,34 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
assert!(self.in_snapshot());
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
assert!(
self.skolemization_count as usize >= skols.len(),
self.skolemization_count.as_usize() >= skols.len(),
"popping more skolemized variables than actually exist, \
sc now = {}, skols.len = {}",
self.skolemization_count,
self.skolemization_count.as_usize(),
skols.len()
);

let last_to_pop = self.skolemization_count;
let first_to_pop = last_to_pop - (skols.len() as u32);
let last_to_pop = self.skolemization_count.subuniverse();
let first_to_pop = ty::UniverseIndex::from(last_to_pop.as_u32() - (skols.len() as u32));

assert!(
first_to_pop >= snapshot.skolemization_count,
"popping more regions than snapshot contains, \
sc now = {}, sc then = {}, skols.len = {}",
sc now = {:?}, sc then = {:?}, skols.len = {}",
self.skolemization_count,
snapshot.skolemization_count,
skols.len()
);
debug_assert! {
skols.iter()
.all(|&k| match *k {
ty::ReSkolemized(index, _) =>
index.index >= first_to_pop &&
index.index < last_to_pop,
ty::ReSkolemized(universe, _) =>
universe >= first_to_pop &&
universe < last_to_pop,
_ =>
false
}),
"invalid skolemization keys or keys out of range ({}..{}): {:?}",
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
snapshot.skolemization_count,
self.skolemization_count,
skols
Expand Down Expand Up @@ -776,7 +776,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
tcx: TyCtxt<'_, '_, 'tcx>,
rid: RegionVid,
) -> ty::Region<'tcx> {
let vid = self.unification_table.find_value(rid).min_vid;
let vid = self.unification_table.probe_value(rid).min_vid;
tcx.mk_region(ty::ReVar(vid))
}

Expand Down Expand Up @@ -861,7 +861,7 @@ impl fmt::Debug for RegionSnapshot {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"RegionSnapshot(length={},skolemization={})",
"RegionSnapshot(length={},skolemization={:?})",
self.length,
self.skolemization_count
)
Expand Down

0 comments on commit 755bdaa

Please sign in to comment.