Skip to content

Commit 360cbf2

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 e904d56 commit 360cbf2

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
);
@@ -485,9 +485,9 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
485485
assert!(self.in_snapshot());
486486
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
487487

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

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

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

518518
assert!(
519519
first_to_pop >= snapshot.skolemization_count,
520520
"popping more regions than snapshot contains, \
521-
sc now = {}, sc then = {}, skols.len = {}",
521+
sc now = {:?}, sc then = {:?}, skols.len = {:?}",
522522
self.skolemization_count,
523523
snapshot.skolemization_count,
524524
skols.len()
525525
);
526526
debug_assert! {
527527
skols.iter()
528528
.all(|&k| match *k {
529-
ty::ReSkolemized(index, _) =>
530-
index.index >= first_to_pop &&
531-
index.index < last_to_pop,
529+
ty::ReSkolemized(universe, _) =>
530+
universe >= first_to_pop &&
531+
universe < last_to_pop,
532532
_ =>
533533
false
534534
}),
535-
"invalid skolemization keys or keys out of range ({}..{}): {:?}",
535+
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
536536
snapshot.skolemization_count,
537537
self.skolemization_count,
538538
skols
@@ -867,7 +867,7 @@ impl fmt::Debug for RegionSnapshot {
867867
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
868868
write!(
869869
f,
870-
"RegionSnapshot(length={},skolemization={})",
870+
"RegionSnapshot(length={},skolemization={:?})",
871871
self.length,
872872
self.skolemization_count
873873
)

src/librustc/ty/mod.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
6969
pub use self::sty::{ExistentialProjection, PolyExistentialProjection, Const};
7070
pub use self::sty::{BoundRegion, EarlyBoundRegion, FreeRegion, Region};
7171
pub use self::sty::RegionKind;
72-
pub use self::sty::{TyVid, IntVid, FloatVid, RegionVid, SkolemizedRegionVid};
72+
pub use self::sty::{TyVid, IntVid, FloatVid, RegionVid};
7373
pub use self::sty::BoundRegion::*;
7474
pub use self::sty::InferTy::*;
7575
pub use self::sty::RegionKind::*;
@@ -1370,7 +1370,7 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
13701370
/// type name in a non-zero universe is a skolemized type -- an
13711371
/// idealized representative of "types in general" that we use for
13721372
/// checking generic functions.
1373-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1373+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
13741374
pub struct UniverseIndex(u32);
13751375

13761376
impl UniverseIndex {
@@ -1390,7 +1390,21 @@ impl UniverseIndex {
13901390
/// region `'a`, but that region was not nameable from `U` because
13911391
/// it was not in scope there.
13921392
pub fn subuniverse(self) -> UniverseIndex {
1393-
UniverseIndex(self.0 + 1)
1393+
UniverseIndex(self.0.checked_add(1).unwrap())
1394+
}
1395+
1396+
pub fn as_u32(&self) -> u32 {
1397+
self.0
1398+
}
1399+
1400+
pub fn as_usize(&self) -> usize {
1401+
self.0 as usize
1402+
}
1403+
}
1404+
1405+
impl From<u32> for UniverseIndex {
1406+
fn from(index: u32) -> Self {
1407+
UniverseIndex(index)
13941408
}
13951409
}
13961410

src/librustc/ty/sty.rs

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

10221022
/// A skolemized region - basically the higher-ranked version of ReFree.
10231023
/// Should not exist after typeck.
1024-
ReSkolemized(SkolemizedRegionVid, BoundRegion),
1024+
ReSkolemized(ty::UniverseIndex, BoundRegion),
10251025

10261026
/// Empty lifetime is for data that is never accessed.
10271027
/// Bottom in the region lattice. We treat ReEmpty somewhat
@@ -1075,11 +1075,6 @@ newtype_index!(RegionVid
10751075
DEBUG_FORMAT = custom,
10761076
});
10771077

1078-
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
1079-
pub struct SkolemizedRegionVid {
1080-
pub index: u32,
1081-
}
1082-
10831078
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
10841079
pub enum InferTy {
10851080
TyVar(TyVid),

src/librustc/util/ppaux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,8 @@ define_print! {
808808
write!(f, "'?{}", c.index())
809809
}
810810

811-
ty::ReSkolemized(id, ref bound_region) => {
812-
write!(f, "ReSkolemized({}, {:?})", id.index, bound_region)
811+
ty::ReSkolemized(universe, ref bound_region) => {
812+
write!(f, "ReSkolemized({:?}, {:?})", universe, bound_region)
813813
}
814814

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

0 commit comments

Comments
 (0)