Skip to content

Commit 460915b

Browse files
committed
make UniverseIndex hashable, rename "sub-" to "superuniverse"
The only name was silly. U1 can contain everything from U0 *plus* more things.
1 parent 28df2bf commit 460915b

File tree

7 files changed

+28
-25
lines changed

7 files changed

+28
-25
lines changed

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
593593
where
594594
T : TypeFoldable<'tcx>,
595595
{
596-
let new_universe = self.create_subuniverse();
596+
let new_universe = self.create_superuniverse();
597597

598598
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
599599
self.tcx.mk_region(ty::RePlaceholder(ty::Placeholder {

src/librustc/infer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,12 +1494,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14941494
}
14951495

14961496
/// Create and return a new subunivese of the current universe;
1497-
/// update `self.universe` to that new subuniverse. At present,
1497+
/// update `self.universe` to that new universe. At present,
14981498
/// used only in the NLL subtyping code, which uses the new
14991499
/// universe-based scheme instead of the more limited leak-check
15001500
/// scheme.
1501-
pub fn create_subuniverse(&self) -> ty::UniverseIndex {
1502-
let u = self.universe.get().subuniverse();
1501+
pub fn create_superuniverse(&self) -> ty::UniverseIndex {
1502+
let u = self.universe.get().superuniverse();
15031503
self.universe.set(u);
15041504
u
15051505
}

src/librustc/ty/mod.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
14571457
/// presence of `for<..>` binders to control what sets of names are
14581458
/// visible. Universes are arranged into a tree: the root universe
14591459
/// contains names that are always visible. But when you enter into
1460-
/// some subuniverse, then it may add names that are only visible
1460+
/// some superuniverse, then it may add names that are only visible
14611461
/// within that subtree (but it can still name the names of its
14621462
/// ancestor universes).
14631463
///
@@ -1471,10 +1471,10 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
14711471
/// ```
14721472
///
14731473
/// The struct name `Foo` is in the root universe U0. But the type
1474-
/// parameter `T`, introduced on `bar`, is in a subuniverse U1 --
1474+
/// parameter `T`, introduced on `bar`, is in a superuniverse U1 --
14751475
/// i.e., within `bar`, we can name both `T` and `Foo`, but outside of
14761476
/// `bar`, we cannot name `T`. Then, within the type of `y`, the
1477-
/// region `'a` is in a subuniverse U2 of U1, because we can name it
1477+
/// region `'a` is in a superuniverse U2 of U1, because we can name it
14781478
/// inside the fn type but not outside.
14791479
///
14801480
/// Universes are used to do type- and trait-checking around these
@@ -1489,52 +1489,54 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
14891489
/// type -- an idealized representative of "types in general" that we
14901490
/// use for checking generic functions.
14911491
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
1492-
pub struct UniverseIndex(u32);
1492+
pub struct UniverseIndex { private: u32 }
1493+
1494+
impl_stable_hash_for!(struct UniverseIndex { private });
14931495

14941496
impl UniverseIndex {
14951497
/// The root universe, where things that the user defined are
14961498
/// visible.
1497-
pub const ROOT: Self = UniverseIndex(0);
1499+
pub const ROOT: Self = UniverseIndex { private: 0 };
14981500

14991501
/// The "max universe" -- this isn't really a valid universe, but
15001502
/// it's useful sometimes as a "starting value" when you are
15011503
/// taking the minimum of a (non-empty!) set of universes.
1502-
pub const MAX: Self = UniverseIndex(::std::u32::MAX);
1504+
pub const MAX: Self = UniverseIndex { private: ::std::u32::MAX };
15031505

15041506
/// Creates a universe index from the given integer. Not to be
15051507
/// used lightly lest you pick a bad value. But sometimes we
15061508
/// convert universe indices into integers and back for various
15071509
/// reasons.
15081510
pub fn from_u32(index: u32) -> Self {
1509-
UniverseIndex(index)
1511+
UniverseIndex { private: index }
15101512
}
15111513

1512-
/// A "subuniverse" corresponds to being inside a `forall` quantifier.
1514+
/// A "superuniverse" corresponds to being inside a `forall` quantifier.
15131515
/// So, for example, suppose we have this type in universe `U`:
15141516
///
15151517
/// ```
15161518
/// for<'a> fn(&'a u32)
15171519
/// ```
15181520
///
15191521
/// Once we "enter" into this `for<'a>` quantifier, we are in a
1520-
/// subuniverse of `U` -- in this new universe, we can name the
1522+
/// superuniverse of `U` -- in this new universe, we can name the
15211523
/// region `'a`, but that region was not nameable from `U` because
15221524
/// it was not in scope there.
1523-
pub fn subuniverse(self) -> UniverseIndex {
1524-
UniverseIndex(self.0.checked_add(1).unwrap())
1525+
pub fn superuniverse(self) -> UniverseIndex {
1526+
UniverseIndex::from_u32(self.private.checked_add(1).unwrap())
15251527
}
15261528

15271529
/// True if the names in this universe are a subset of the names in `other`.
15281530
pub fn is_subset_of(self, other: UniverseIndex) -> bool {
1529-
self.0 <= other.0
1531+
self.private <= other.private
15301532
}
15311533

15321534
pub fn as_u32(&self) -> u32 {
1533-
self.0
1535+
self.private
15341536
}
15351537

15361538
pub fn as_usize(&self) -> usize {
1537-
self.0 as usize
1539+
self.private as usize
15381540
}
15391541
}
15401542

@@ -1546,7 +1548,7 @@ impl fmt::Debug for UniverseIndex {
15461548

15471549
impl From<u32> for UniverseIndex {
15481550
fn from(index: u32) -> Self {
1549-
UniverseIndex(index)
1551+
UniverseIndex::from_u32(index)
15501552
}
15511553
}
15521554

src/librustc/ty/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ CloneTypeFoldableAndLiftImpls! {
5757
::ty::ClosureKind,
5858
::ty::IntVarValue,
5959
::ty::ParamTy,
60+
::ty::UniverseIndex,
6061
::ty::Variance,
6162
::syntax_pos::Span,
6263
}

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct RegionDefinition<'tcx> {
112112
/// Which universe is this region variable defined in? This is
113113
/// most often `ty::UniverseIndex::ROOT`, but when we encounter
114114
/// forall-quantifiers like `for<'a> { 'a = 'b }`, we would create
115-
/// the variable for `'a` in a subuniverse.
115+
/// the variable for `'a` in a superuniverse.
116116
universe: ty::UniverseIndex,
117117

118118
/// If this is 'static or an early-bound region, then this is

src/librustc_mir/borrow_check/nll/region_infer/values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ crate enum RegionElement {
148148
/// a lifetime parameter).
149149
RootUniversalRegion(RegionVid),
150150

151-
/// A subuniverse from a subuniverse (e.g., instantiated from a
151+
/// A superuniverse from a superuniverse (e.g., instantiated from a
152152
/// `for<'a> fn(&'a u32)` type).
153153
PlaceholderRegion(ty::Placeholder),
154154
}

src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ trait TypeRelatingDelegate<'tcx> {
159159
fn push_outlives(&mut self, sup: ty::Region<'tcx>, sub: ty::Region<'tcx>);
160160

161161
/// Creates a new universe index. Used when instantiating placeholders.
162-
fn next_subuniverse(&mut self) -> ty::UniverseIndex;
162+
fn next_superuniverse(&mut self) -> ty::UniverseIndex;
163163

164164
/// Creates a new region variable representing a higher-ranked
165165
/// region that is instantiated existentially. This creates an
@@ -218,8 +218,8 @@ impl NllTypeRelatingDelegate<'me, 'bccx, 'gcx, 'tcx> {
218218
}
219219

220220
impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, '_, 'tcx> {
221-
fn next_subuniverse(&mut self) -> ty::UniverseIndex {
222-
self.infcx.create_subuniverse()
221+
fn next_superuniverse(&mut self) -> ty::UniverseIndex {
222+
self.infcx.create_superuniverse()
223223
}
224224

225225
fn next_existential_region_var(&mut self) -> ty::Region<'tcx> {
@@ -324,7 +324,7 @@ where
324324
// new universe for the placeholders we will make
325325
// from here out.
326326
let universe = lazy_universe.unwrap_or_else(|| {
327-
let universe = delegate.next_subuniverse();
327+
let universe = delegate.next_superuniverse();
328328
lazy_universe = Some(universe);
329329
universe
330330
});

0 commit comments

Comments
 (0)