Skip to content

Commit 66520ff

Browse files
committed
change skolemizations to use universe index
This is sort of confusing "side step". All it does is to change the representation of a skolemized region. but the source of that universe index is not the inference context, which is what we eventually want, but rather an internal counter in the region inference context. We'll patch that up later. But doing this now ought to help with confusing diffs later.
1 parent ff17bd7 commit 66520ff

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

src/librustc/infer/region_constraints/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct RegionConstraintCollector<'tcx> {
4848
glbs: CombineMap<'tcx>,
4949

5050
/// Number of skolemized variables currently active.
51-
skolemization_count: u32,
51+
skolemization_count: ty::UniverseIndex,
5252

5353
/// Global counter used during the GLB algorithm to create unique
5454
/// names for fresh bound regions
@@ -233,7 +233,7 @@ type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
233233
pub struct RegionSnapshot {
234234
length: usize,
235235
region_snapshot: ut::Snapshot<ut::InPlace<ty::RegionVid>>,
236-
skolemization_count: u32,
236+
skolemization_count: ty::UniverseIndex,
237237
}
238238

239239
/// When working with skolemized regions, we often wish to find all of
@@ -277,7 +277,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
277277
data: RegionConstraintData::default(),
278278
lubs: FxHashMap(),
279279
glbs: FxHashMap(),
280-
skolemization_count: 0,
280+
skolemization_count: ty::UniverseIndex::ROOT,
281281
bound_count: 0,
282282
undo_log: Vec::new(),
283283
unification_table: ut::UnificationTable::new(),
@@ -329,7 +329,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
329329
unification_table,
330330
} = self;
331331

332-
assert_eq!(*skolemization_count, 0);
332+
assert_eq!(*skolemization_count, ty::UniverseIndex::ROOT);
333333

334334
// Clear the tables of (lubs, glbs), so that we will create
335335
// fresh regions if we do a LUB operation. As it happens,
@@ -375,7 +375,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
375375
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
376376
assert!(
377377
self.skolemization_count == snapshot.skolemization_count,
378-
"failed to pop skolemized regions: {} now vs {} at start",
378+
"failed to pop skolemized regions: {:?} now vs {:?} at start",
379379
self.skolemization_count,
380380
snapshot.skolemization_count
381381
);
@@ -483,9 +483,9 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
483483
assert!(self.in_snapshot());
484484
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
485485

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

491491
/// Removes all the edges to/from the skolemized regions that are
@@ -503,34 +503,34 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
503503
assert!(self.in_snapshot());
504504
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
505505
assert!(
506-
self.skolemization_count as usize >= skols.len(),
506+
self.skolemization_count.as_usize() >= skols.len(),
507507
"popping more skolemized variables than actually exist, \
508-
sc now = {}, skols.len = {}",
508+
sc now = {:?}, skols.len = {:?}",
509509
self.skolemization_count,
510510
skols.len()
511511
);
512512

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

516516
assert!(
517517
first_to_pop >= snapshot.skolemization_count,
518518
"popping more regions than snapshot contains, \
519-
sc now = {}, sc then = {}, skols.len = {}",
519+
sc now = {:?}, sc then = {:?}, skols.len = {:?}",
520520
self.skolemization_count,
521521
snapshot.skolemization_count,
522522
skols.len()
523523
);
524524
debug_assert! {
525525
skols.iter()
526526
.all(|&k| match *k {
527-
ty::ReSkolemized(index, _) =>
528-
index.index >= first_to_pop &&
529-
index.index < last_to_pop,
527+
ty::ReSkolemized(universe, _) =>
528+
universe >= first_to_pop &&
529+
universe < last_to_pop,
530530
_ =>
531531
false
532532
}),
533-
"invalid skolemization keys or keys out of range ({}..{}): {:?}",
533+
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
534534
snapshot.skolemization_count,
535535
self.skolemization_count,
536536
skols
@@ -865,7 +865,7 @@ impl fmt::Debug for RegionSnapshot {
865865
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
866866
write!(
867867
f,
868-
"RegionSnapshot(length={},skolemization={})",
868+
"RegionSnapshot(length={},skolemization={:?})",
869869
self.length,
870870
self.skolemization_count
871871
)

src/librustc/ty/mod.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
6767
pub use self::sty::{ExistentialProjection, PolyExistentialProjection, Const};
6868
pub use self::sty::{BoundRegion, EarlyBoundRegion, FreeRegion, Region};
6969
pub use self::sty::RegionKind;
70-
pub use self::sty::{TyVid, IntVid, FloatVid, RegionVid, SkolemizedRegionVid};
70+
pub use self::sty::{TyVid, IntVid, FloatVid, RegionVid};
7171
pub use self::sty::BoundRegion::*;
7272
pub use self::sty::InferTy::*;
7373
pub use self::sty::RegionKind::*;
@@ -1328,7 +1328,7 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
13281328
/// type name in a non-zero universe is a skolemized type -- an
13291329
/// idealized representative of "types in general" that we use for
13301330
/// checking generic functions.
1331-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1331+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
13321332
pub struct UniverseIndex(u32);
13331333

13341334
impl UniverseIndex {
@@ -1348,7 +1348,21 @@ impl UniverseIndex {
13481348
/// region `'a`, but that region was not nameable from `U` because
13491349
/// it was not in scope there.
13501350
pub fn subuniverse(self) -> UniverseIndex {
1351-
UniverseIndex(self.0 + 1)
1351+
UniverseIndex(self.0.checked_add(1).unwrap())
1352+
}
1353+
1354+
pub fn as_u32(&self) -> u32 {
1355+
self.0
1356+
}
1357+
1358+
pub fn as_usize(&self) -> usize {
1359+
self.0 as usize
1360+
}
1361+
}
1362+
1363+
impl From<u32> for UniverseIndex {
1364+
fn from(index: u32) -> Self {
1365+
UniverseIndex(index)
13521366
}
13531367
}
13541368

src/librustc/ty/sty.rs

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

10291029
/// A skolemized region - basically the higher-ranked version of ReFree.
10301030
/// Should not exist after typeck.
1031-
ReSkolemized(SkolemizedRegionVid, BoundRegion),
1031+
ReSkolemized(ty::UniverseIndex, BoundRegion),
10321032

10331033
/// Empty lifetime is for data that is never accessed.
10341034
/// Bottom in the region lattice. We treat ReEmpty somewhat
@@ -1082,11 +1082,6 @@ newtype_index!(RegionVid
10821082
DEBUG_FORMAT = custom,
10831083
});
10841084

1085-
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
1086-
pub struct SkolemizedRegionVid {
1087-
pub index: u32,
1088-
}
1089-
10901085
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
10911086
pub enum InferTy {
10921087
TyVar(TyVid),

src/librustc/util/ppaux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,8 @@ define_print! {
792792
write!(f, "'?{}", c.index())
793793
}
794794

795-
ty::ReSkolemized(id, ref bound_region) => {
796-
write!(f, "ReSkolemized({}, {:?})", id.index, bound_region)
795+
ty::ReSkolemized(universe, ref bound_region) => {
796+
write!(f, "ReSkolemized({:?}, {:?})", universe, bound_region)
797797
}
798798

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

0 commit comments

Comments
 (0)