Skip to content

Commit 755bdaa

Browse files
committed
change skolemizations to use universe index
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.
1 parent 17df455 commit 755bdaa

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

src/Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/infer/region_constraints/mod.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::unify_key;
1818

1919
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
2020
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
21-
use rustc_data_structures::unify::{self, UnificationTable};
21+
use rustc_data_structures::unify as ut;
2222
use ty::{self, Ty, TyCtxt};
2323
use ty::{Region, RegionVid};
2424
use ty::ReStatic;
@@ -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
@@ -73,7 +73,7 @@ pub struct RegionConstraintCollector<'tcx> {
7373
/// is iterating to a fixed point, because otherwise we sometimes
7474
/// would wind up with a fresh stream of region variables that
7575
/// have been equated but appear distinct.
76-
unification_table: UnificationTable<ty::RegionVid>,
76+
unification_table: ut::UnificationTable<ut::InPlace<ty::RegionVid>>,
7777
}
7878

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

233233
pub struct RegionSnapshot {
234234
length: usize,
235-
region_snapshot: unify::Snapshot<ty::RegionVid>,
236-
skolemization_count: u32,
235+
region_snapshot: ut::Snapshot<ut::InPlace<ty::RegionVid>>,
236+
skolemization_count: ty::UniverseIndex,
237237
}
238238

239239
/// When working with skolemized regions, we often wish to find all of
@@ -277,10 +277,10 @@ 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(),
283-
unification_table: UnificationTable::new(),
283+
unification_table: ut::UnificationTable::new(),
284284
}
285285
}
286286

@@ -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.as_usize(), 0);
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,
@@ -342,7 +342,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
342342
// un-unified" state. Note that when we unify `a` and `b`, we
343343
// also insert `a <= b` and a `b <= a` edges, so the
344344
// `RegionConstraintData` contains the relationship here.
345-
*unification_table = UnificationTable::new();
345+
*unification_table = ut::UnificationTable::new();
346346
for vid in var_origins.indices() {
347347
unification_table.new_key(unify_key::RegionVidKey { min_vid: vid });
348348
}
@@ -371,7 +371,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
371371
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
372372
assert!(
373373
self.skolemization_count == snapshot.skolemization_count,
374-
"failed to pop skolemized regions: {} now vs {} at start",
374+
"failed to pop skolemized regions: {:?} now vs {:?} at start",
375375
self.skolemization_count,
376376
snapshot.skolemization_count
377377
);
@@ -479,9 +479,9 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
479479
assert!(self.in_snapshot());
480480
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
481481

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

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

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

512512
assert!(
513513
first_to_pop >= snapshot.skolemization_count,
514514
"popping more regions than snapshot contains, \
515-
sc now = {}, sc then = {}, skols.len = {}",
515+
sc now = {:?}, sc then = {:?}, skols.len = {}",
516516
self.skolemization_count,
517517
snapshot.skolemization_count,
518518
skols.len()
519519
);
520520
debug_assert! {
521521
skols.iter()
522522
.all(|&k| match *k {
523-
ty::ReSkolemized(index, _) =>
524-
index.index >= first_to_pop &&
525-
index.index < last_to_pop,
523+
ty::ReSkolemized(universe, _) =>
524+
universe >= first_to_pop &&
525+
universe < last_to_pop,
526526
_ =>
527527
false
528528
}),
529-
"invalid skolemization keys or keys out of range ({}..{}): {:?}",
529+
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
530530
snapshot.skolemization_count,
531531
self.skolemization_count,
532532
skols
@@ -776,7 +776,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
776776
tcx: TyCtxt<'_, '_, 'tcx>,
777777
rid: RegionVid,
778778
) -> ty::Region<'tcx> {
779-
let vid = self.unification_table.find_value(rid).min_vid;
779+
let vid = self.unification_table.probe_value(rid).min_vid;
780780
tcx.mk_region(ty::ReVar(vid))
781781
}
782782

@@ -861,7 +861,7 @@ impl fmt::Debug for RegionSnapshot {
861861
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
862862
write!(
863863
f,
864-
"RegionSnapshot(length={},skolemization={})",
864+
"RegionSnapshot(length={},skolemization={:?})",
865865
self.length,
866866
self.skolemization_count
867867
)

0 commit comments

Comments
 (0)