change skolemizations to use universe index
These changes were meant to be in 2b18d8fe9dc05415a8e6b7cadf879c7f7ebe020a (rebased from 12a230562ece9b0d29018a436676141054dc53b7), but I messed up the rebase a bit as the file had been moved.
This commit is contained in:
parent
17df455c2e
commit
755bdaa190
2 changed files with 34 additions and 24 deletions
10
src/Cargo.lock
generated
10
src/Cargo.lock
generated
|
@ -598,6 +598,14 @@ name = "either"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ena"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "endian-type"
|
name = "endian-type"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
@ -1866,6 +1874,7 @@ name = "rustc_data_structures"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"ena 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parking_lot 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parking_lot_core 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot_core 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2861,6 +2870,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
|
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
|
||||||
"checksum duct 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e45aa15fe0a8a8f511e6d834626afd55e49b62e5c8802e18328a87e8a8f6065c"
|
"checksum duct 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e45aa15fe0a8a8f511e6d834626afd55e49b62e5c8802e18328a87e8a8f6065c"
|
||||||
"checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3"
|
"checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3"
|
||||||
|
"checksum ena 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb80e4764284ff0ec7054cb05c557f5ba01ccf65ff0c265e981c0b303d0ffc"
|
||||||
"checksum endian-type 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
|
"checksum endian-type 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
|
||||||
"checksum enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180"
|
"checksum enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180"
|
||||||
"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f"
|
"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f"
|
||||||
|
|
|
@ -18,7 +18,7 @@ use super::unify_key;
|
||||||
|
|
||||||
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
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::{self, Ty, TyCtxt};
|
||||||
use ty::{Region, RegionVid};
|
use ty::{Region, RegionVid};
|
||||||
use ty::ReStatic;
|
use ty::ReStatic;
|
||||||
|
@ -48,7 +48,7 @@ pub struct RegionConstraintCollector<'tcx> {
|
||||||
glbs: CombineMap<'tcx>,
|
glbs: CombineMap<'tcx>,
|
||||||
|
|
||||||
/// Number of skolemized variables currently active.
|
/// Number of skolemized variables currently active.
|
||||||
skolemization_count: u32,
|
skolemization_count: ty::UniverseIndex,
|
||||||
|
|
||||||
/// Global counter used during the GLB algorithm to create unique
|
/// Global counter used during the GLB algorithm to create unique
|
||||||
/// names for fresh bound regions
|
/// names for fresh bound regions
|
||||||
|
@ -73,7 +73,7 @@ pub struct RegionConstraintCollector<'tcx> {
|
||||||
/// is iterating to a fixed point, because otherwise we sometimes
|
/// is iterating to a fixed point, because otherwise we sometimes
|
||||||
/// would wind up with a fresh stream of region variables that
|
/// would wind up with a fresh stream of region variables that
|
||||||
/// have been equated but appear distinct.
|
/// 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>;
|
pub type VarOrigins = IndexVec<RegionVid, RegionVariableOrigin>;
|
||||||
|
@ -232,8 +232,8 @@ type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
|
||||||
|
|
||||||
pub struct RegionSnapshot {
|
pub struct RegionSnapshot {
|
||||||
length: usize,
|
length: usize,
|
||||||
region_snapshot: unify::Snapshot<ty::RegionVid>,
|
region_snapshot: ut::Snapshot<ut::InPlace<ty::RegionVid>>,
|
||||||
skolemization_count: u32,
|
skolemization_count: ty::UniverseIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When working with skolemized regions, we often wish to find all of
|
/// When working with skolemized regions, we often wish to find all of
|
||||||
|
@ -277,10 +277,10 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
data: RegionConstraintData::default(),
|
data: RegionConstraintData::default(),
|
||||||
lubs: FxHashMap(),
|
lubs: FxHashMap(),
|
||||||
glbs: FxHashMap(),
|
glbs: FxHashMap(),
|
||||||
skolemization_count: 0,
|
skolemization_count: ty::UniverseIndex::ROOT,
|
||||||
bound_count: 0,
|
bound_count: 0,
|
||||||
undo_log: Vec::new(),
|
undo_log: Vec::new(),
|
||||||
unification_table: UnificationTable::new(),
|
unification_table: ut::UnificationTable::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
unification_table,
|
unification_table,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
assert_eq!(*skolemization_count, 0);
|
assert_eq!(skolemization_count.as_usize(), 0);
|
||||||
|
|
||||||
// Clear the tables of (lubs, glbs), so that we will create
|
// Clear the tables of (lubs, glbs), so that we will create
|
||||||
// fresh regions if we do a LUB operation. As it happens,
|
// fresh regions if we do a LUB operation. As it happens,
|
||||||
|
@ -342,7 +342,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
// un-unified" state. Note that when we unify `a` and `b`, we
|
// un-unified" state. Note that when we unify `a` and `b`, we
|
||||||
// also insert `a <= b` and a `b <= a` edges, so the
|
// also insert `a <= b` and a `b <= a` edges, so the
|
||||||
// `RegionConstraintData` contains the relationship here.
|
// `RegionConstraintData` contains the relationship here.
|
||||||
*unification_table = UnificationTable::new();
|
*unification_table = ut::UnificationTable::new();
|
||||||
for vid in var_origins.indices() {
|
for vid in var_origins.indices() {
|
||||||
unification_table.new_key(unify_key::RegionVidKey { min_vid: vid });
|
unification_table.new_key(unify_key::RegionVidKey { min_vid: vid });
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
|
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
|
||||||
assert!(
|
assert!(
|
||||||
self.skolemization_count == snapshot.skolemization_count,
|
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,
|
self.skolemization_count,
|
||||||
snapshot.skolemization_count
|
snapshot.skolemization_count
|
||||||
);
|
);
|
||||||
|
@ -479,9 +479,9 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
assert!(self.in_snapshot());
|
assert!(self.in_snapshot());
|
||||||
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
|
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
|
||||||
|
|
||||||
let sc = self.skolemization_count;
|
let universe = self.skolemization_count.subuniverse();
|
||||||
self.skolemization_count = sc + 1;
|
self.skolemization_count = universe;
|
||||||
tcx.mk_region(ReSkolemized(ty::SkolemizedRegionVid { index: sc }, br))
|
tcx.mk_region(ReSkolemized(universe, br))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes all the edges to/from the skolemized regions that are
|
/// Removes all the edges to/from the skolemized regions that are
|
||||||
|
@ -499,20 +499,20 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
assert!(self.in_snapshot());
|
assert!(self.in_snapshot());
|
||||||
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
|
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
|
||||||
assert!(
|
assert!(
|
||||||
self.skolemization_count as usize >= skols.len(),
|
self.skolemization_count.as_usize() >= skols.len(),
|
||||||
"popping more skolemized variables than actually exist, \
|
"popping more skolemized variables than actually exist, \
|
||||||
sc now = {}, skols.len = {}",
|
sc now = {}, skols.len = {}",
|
||||||
self.skolemization_count,
|
self.skolemization_count.as_usize(),
|
||||||
skols.len()
|
skols.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
let last_to_pop = self.skolemization_count;
|
let last_to_pop = self.skolemization_count.subuniverse();
|
||||||
let first_to_pop = last_to_pop - (skols.len() as u32);
|
let first_to_pop = ty::UniverseIndex::from(last_to_pop.as_u32() - (skols.len() as u32));
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
first_to_pop >= snapshot.skolemization_count,
|
first_to_pop >= snapshot.skolemization_count,
|
||||||
"popping more regions than snapshot contains, \
|
"popping more regions than snapshot contains, \
|
||||||
sc now = {}, sc then = {}, skols.len = {}",
|
sc now = {:?}, sc then = {:?}, skols.len = {}",
|
||||||
self.skolemization_count,
|
self.skolemization_count,
|
||||||
snapshot.skolemization_count,
|
snapshot.skolemization_count,
|
||||||
skols.len()
|
skols.len()
|
||||||
|
@ -520,13 +520,13 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
debug_assert! {
|
debug_assert! {
|
||||||
skols.iter()
|
skols.iter()
|
||||||
.all(|&k| match *k {
|
.all(|&k| match *k {
|
||||||
ty::ReSkolemized(index, _) =>
|
ty::ReSkolemized(universe, _) =>
|
||||||
index.index >= first_to_pop &&
|
universe >= first_to_pop &&
|
||||||
index.index < last_to_pop,
|
universe < last_to_pop,
|
||||||
_ =>
|
_ =>
|
||||||
false
|
false
|
||||||
}),
|
}),
|
||||||
"invalid skolemization keys or keys out of range ({}..{}): {:?}",
|
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
|
||||||
snapshot.skolemization_count,
|
snapshot.skolemization_count,
|
||||||
self.skolemization_count,
|
self.skolemization_count,
|
||||||
skols
|
skols
|
||||||
|
@ -776,7 +776,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||||
tcx: TyCtxt<'_, '_, 'tcx>,
|
tcx: TyCtxt<'_, '_, 'tcx>,
|
||||||
rid: RegionVid,
|
rid: RegionVid,
|
||||||
) -> ty::Region<'tcx> {
|
) -> 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))
|
tcx.mk_region(ty::ReVar(vid))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -861,7 +861,7 @@ impl fmt::Debug for RegionSnapshot {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"RegionSnapshot(length={},skolemization={})",
|
"RegionSnapshot(length={},skolemization={:?})",
|
||||||
self.length,
|
self.length,
|
||||||
self.skolemization_count
|
self.skolemization_count
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue