Skip to content

Commit 12a2305

Browse files
committed
change skolemizations to use universe index
1 parent de2dcd6 commit 12a2305

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

src/librustc/infer/region_inference/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
216216

217217
lubs: RefCell<CombineMap<'tcx>>,
218218
glbs: RefCell<CombineMap<'tcx>>,
219-
skolemization_count: Cell<u32>,
219+
skolemization_count: Cell<ty::UniverseIndex>,
220220
bound_count: Cell<u32>,
221221

222222
/// The undo log records actions that might later be undone.
@@ -240,7 +240,7 @@ pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
240240
pub struct RegionSnapshot {
241241
length: usize,
242242
region_snapshot: ut::Snapshot<ut::InPlace<ty::RegionVid>>,
243-
skolemization_count: u32,
243+
skolemization_count: ty::UniverseIndex,
244244
}
245245

246246
/// When working with skolemized regions, we often wish to find all of
@@ -362,7 +362,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
362362
givens: RefCell::new(FxHashSet()),
363363
lubs: RefCell::new(FxHashMap()),
364364
glbs: RefCell::new(FxHashMap()),
365-
skolemization_count: Cell::new(0),
365+
skolemization_count: Cell::new(ty::UniverseIndex::ROOT),
366366
bound_count: Cell::new(0),
367367
undo_log: RefCell::new(Vec::new()),
368368
unification_table: RefCell::new(ut::UnificationTable::new()),
@@ -389,7 +389,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
389389
assert!(self.undo_log.borrow().len() > snapshot.length);
390390
assert!((*self.undo_log.borrow())[snapshot.length] == OpenSnapshot);
391391
assert!(self.skolemization_count.get() == snapshot.skolemization_count,
392-
"failed to pop skolemized regions: {} now vs {} at start",
392+
"failed to pop skolemized regions: {:?} now vs {:?} at start",
393393
self.skolemization_count.get(),
394394
snapshot.skolemization_count);
395395

@@ -501,9 +501,9 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
501501
assert!(self.in_snapshot());
502502
assert!(self.undo_log.borrow()[snapshot.length] == OpenSnapshot);
503503

504-
let sc = self.skolemization_count.get();
505-
self.skolemization_count.set(sc + 1);
506-
self.tcx.mk_region(ReSkolemized(ty::SkolemizedRegionVid { index: sc }, br))
504+
let universe = self.skolemization_count.get().subuniverse();
505+
self.skolemization_count.set(universe);
506+
self.tcx.mk_region(ReSkolemized(universe, br))
507507
}
508508

509509
/// Removes all the edges to/from the skolemized regions that are
@@ -517,31 +517,31 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
517517

518518
assert!(self.in_snapshot());
519519
assert!(self.undo_log.borrow()[snapshot.length] == OpenSnapshot);
520-
assert!(self.skolemization_count.get() as usize >= skols.len(),
520+
assert!(self.skolemization_count.get().as_usize() >= skols.len(),
521521
"popping more skolemized variables than actually exist, \
522522
sc now = {}, skols.len = {}",
523-
self.skolemization_count.get(),
523+
self.skolemization_count.get().as_usize(),
524524
skols.len());
525525

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

529529
assert!(first_to_pop >= snapshot.skolemization_count,
530530
"popping more regions than snapshot contains, \
531-
sc now = {}, sc then = {}, skols.len = {}",
531+
sc now = {:?}, sc then = {:?}, skols.len = {}",
532532
self.skolemization_count.get(),
533533
snapshot.skolemization_count,
534534
skols.len());
535535
debug_assert! {
536536
skols.iter()
537537
.all(|&k| match *k {
538-
ty::ReSkolemized(index, _) =>
539-
index.index >= first_to_pop &&
540-
index.index < last_to_pop,
538+
ty::ReSkolemized(universe, _) =>
539+
universe >= first_to_pop &&
540+
universe < last_to_pop,
541541
_ =>
542542
false
543543
}),
544-
"invalid skolemization keys or keys out of range ({}..{}): {:?}",
544+
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
545545
snapshot.skolemization_count,
546546
self.skolemization_count.get(),
547547
skols
@@ -1523,7 +1523,7 @@ impl<'tcx> fmt::Debug for RegionAndOrigin<'tcx> {
15231523

15241524
impl fmt::Debug for RegionSnapshot {
15251525
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1526-
write!(f, "RegionSnapshot(length={},skolemization={})",
1526+
write!(f, "RegionSnapshot(length={},skolemization={:?})",
15271527
self.length, self.skolemization_count)
15281528
}
15291529
}

src/librustc/ty/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
6868
pub use self::sty::{ExistentialProjection, PolyExistentialProjection, Const};
6969
pub use self::sty::{BoundRegion, EarlyBoundRegion, FreeRegion, Region};
7070
pub use self::sty::RegionKind;
71-
pub use self::sty::{TyVid, IntVid, FloatVid, RegionVid, SkolemizedRegionVid};
71+
pub use self::sty::{TyVid, IntVid, FloatVid, RegionVid};
7272
pub use self::sty::BoundRegion::*;
7373
pub use self::sty::InferTy::*;
7474
pub use self::sty::RegionKind::*;
@@ -1275,7 +1275,7 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
12751275
/// type name in a non-zero universe is a skolemized type -- an
12761276
/// idealized representative of "types in general" that we use for
12771277
/// checking generic functions.
1278-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1278+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
12791279
pub struct UniverseIndex(u32);
12801280

12811281
impl UniverseIndex {
@@ -1295,7 +1295,19 @@ impl UniverseIndex {
12951295
/// region `'a`, but that region was not nameable from `U` because
12961296
/// it was not in scope there.
12971297
pub fn subuniverse(self) -> UniverseIndex {
1298-
UniverseIndex(self.0 + 1)
1298+
UniverseIndex(self.0.checked_add(1).unwrap())
1299+
}
1300+
1301+
pub fn from(v: u32) -> UniverseIndex {
1302+
UniverseIndex(v)
1303+
}
1304+
1305+
pub fn as_u32(&self) -> u32 {
1306+
self.0
1307+
}
1308+
1309+
pub fn as_usize(&self) -> usize {
1310+
self.0 as usize
12991311
}
13001312

13011313
/// Gets the "depth" of this universe in the universe tree. This

src/librustc/ty/sty.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ pub enum RegionKind {
854854

855855
/// A skolemized region - basically the higher-ranked version of ReFree.
856856
/// Should not exist after typeck.
857-
ReSkolemized(SkolemizedRegionVid, BoundRegion),
857+
ReSkolemized(ty::UniverseIndex, BoundRegion),
858858

859859
/// Empty lifetime is for data that is never accessed.
860860
/// Bottom in the region lattice. We treat ReEmpty somewhat
@@ -898,11 +898,6 @@ pub struct RegionVid {
898898
pub index: u32,
899899
}
900900

901-
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
902-
pub struct SkolemizedRegionVid {
903-
pub index: u32,
904-
}
905-
906901
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
907902
pub enum InferTy {
908903
TyVar(TyVid),

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ define_print! {
762762
}
763763

764764
ty::ReSkolemized(id, ref bound_region) => {
765-
write!(f, "ReSkolemized({}, {:?})", id.index, bound_region)
765+
write!(f, "ReSkolemized({:?}, {:?})", id, bound_region)
766766
}
767767

768768
ty::ReEmpty => write!(f, "ReEmpty"),

0 commit comments

Comments
 (0)