Skip to content

Commit 05f67ca

Browse files
committedOct 15, 2018
remove the sub/super terminology for universes
Instead, we talk about: - creating the "next" universe - universes "extending" one another - and `u1.can_name(u2)`, meaning that `u1` contains all names from `u2`
1 parent f419077 commit 05f67ca

File tree

6 files changed

+39
-38
lines changed

6 files changed

+39
-38
lines changed
 

Diff for: ‎src/librustc/infer/higher_ranked/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
593593
where
594594
T : TypeFoldable<'tcx>,
595595
{
596-
let new_universe = self.create_superuniverse();
596+
let next_universe = self.create_next_universe();
597597

598598
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
599599
self.tcx.mk_region(ty::RePlaceholder(ty::Placeholder {
600-
universe: new_universe,
600+
universe: next_universe,
601601
name: br,
602602
}))
603603
});

Diff for: ‎src/librustc/infer/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1489,13 +1489,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14891489
self.universe.get()
14901490
}
14911491

1492-
/// Create and return a new subunivese of the current universe;
1493-
/// update `self.universe` to that new universe. At present,
1494-
/// used only in the NLL subtyping code, which uses the new
1495-
/// universe-based scheme instead of the more limited leak-check
1496-
/// scheme.
1497-
pub fn create_superuniverse(&self) -> ty::UniverseIndex {
1498-
let u = self.universe.get().superuniverse();
1492+
/// Create and return a fresh universe that extends all previous
1493+
/// universes. Updates `self.universe` to that new universe.
1494+
pub fn create_next_universe(&self) -> ty::UniverseIndex {
1495+
let u = self.universe.get().next_universe();
14991496
self.universe.set(u);
15001497
u
15011498
}

Diff for: ‎src/librustc/ty/mod.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -1457,10 +1457,10 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
14571457
/// "Universes" are used during type- and trait-checking in the
14581458
/// presence of `for<..>` binders to control what sets of names are
14591459
/// visible. Universes are arranged into a tree: the root universe
1460-
/// contains names that are always visible. But when you enter into
1461-
/// some superuniverse, then it may add names that are only visible
1462-
/// within that subtree (but it can still name the names of its
1463-
/// ancestor universes).
1460+
/// contains names that are always visible. Each child then adds a new
1461+
/// set of names that are visible, in addition to those of its parent.
1462+
/// We say that the child universe "extends" the parent universe with
1463+
/// new names.
14641464
///
14651465
/// To make this more concrete, consider this program:
14661466
///
@@ -1472,11 +1472,11 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
14721472
/// ```
14731473
///
14741474
/// The struct name `Foo` is in the root universe U0. But the type
1475-
/// parameter `T`, introduced on `bar`, is in a superuniverse U1 --
1476-
/// i.e., within `bar`, we can name both `T` and `Foo`, but outside of
1477-
/// `bar`, we cannot name `T`. Then, within the type of `y`, the
1478-
/// region `'a` is in a superuniverse U2 of U1, because we can name it
1479-
/// inside the fn type but not outside.
1475+
/// parameter `T`, introduced on `bar`, is in an extended universe U1
1476+
/// -- i.e., within `bar`, we can name both `T` and `Foo`, but outside
1477+
/// of `bar`, we cannot name `T`. Then, within the type of `y`, the
1478+
/// region `'a` is in a universe U2 that extends U1, because we can
1479+
/// name it inside the fn type but not outside.
14801480
///
14811481
/// Universes are used to do type- and trait-checking around these
14821482
/// "forall" binders (also called **universal quantification**). The
@@ -1500,24 +1500,28 @@ impl_stable_hash_for!(struct UniverseIndex { private });
15001500
impl UniverseIndex {
15011501
pub const ROOT: UniverseIndex = UniverseIndex::from_u32_const(0);
15021502

1503-
/// A "superuniverse" corresponds to being inside a `forall` quantifier.
1504-
/// So, for example, suppose we have this type in universe `U`:
1503+
/// Returns the "next" universe index in order -- this new index
1504+
/// is considered to extend all previous universes. This
1505+
/// corresponds to entering a `forall` quantifier. So, for
1506+
/// example, suppose we have this type in universe `U`:
15051507
///
15061508
/// ```
15071509
/// for<'a> fn(&'a u32)
15081510
/// ```
15091511
///
15101512
/// Once we "enter" into this `for<'a>` quantifier, we are in a
1511-
/// superuniverse of `U` -- in this new universe, we can name the
1512-
/// region `'a`, but that region was not nameable from `U` because
1513-
/// it was not in scope there.
1514-
pub fn superuniverse(self) -> UniverseIndex {
1513+
/// new universe that extends `U` -- in this new universe, we can
1514+
/// name the region `'a`, but that region was not nameable from
1515+
/// `U` because it was not in scope there.
1516+
pub fn next_universe(self) -> UniverseIndex {
15151517
UniverseIndex::from_u32(self.private.checked_add(1).unwrap())
15161518
}
15171519

1518-
/// True if the names in this universe are a subset of the names in `other`.
1519-
pub fn is_subset_of(self, other: UniverseIndex) -> bool {
1520-
self.private <= other.private
1520+
/// True if `self` can name a name from `other` -- in other words,
1521+
/// if the set of names in `self` is a superset of those in
1522+
/// `other`.
1523+
pub fn can_name(self, other: UniverseIndex) -> bool {
1524+
self.private >= other.private
15211525
}
15221526
}
15231527

Diff for: ‎src/librustc_mir/borrow_check/nll/region_infer/mod.rs

+5-5
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 superuniverse.
115+
/// the variable for `'a` in a fresh universe that extends ROOT.
116116
universe: ty::UniverseIndex,
117117

118118
/// If this is 'static or an early-bound region, then this is
@@ -339,11 +339,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
339339

340340
NLLRegionVariableOrigin::Placeholder(placeholder) => {
341341
// Each placeholder region is only visible from
342-
// its universe `ui` and its superuniverses. So we
342+
// its universe `ui` and its extensions. So we
343343
// can't just add it into `scc` unless the
344344
// universe of the scc can name this region.
345345
let scc_universe = self.scc_universes[scc];
346-
if placeholder.universe.is_subset_of(scc_universe) {
346+
if scc_universe.can_name(placeholder.universe) {
347347
self.scc_values.add_element(scc, placeholder);
348348
} else {
349349
self.add_incompatible_universe(scc);
@@ -541,7 +541,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
541541
// Quick check: if scc_b's declared universe is a subset of
542542
// scc_a's declared univese (typically, both are ROOT), then
543543
// it cannot contain any problematic universe elements.
544-
if self.scc_universes[scc_b].is_subset_of(universe_a) {
544+
if universe_a.can_name(self.scc_universes[scc_b]) {
545545
return true;
546546
}
547547

@@ -550,7 +550,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
550550
// from universe_a
551551
self.scc_values
552552
.placeholders_contained_in(scc_b)
553-
.all(|p| p.universe.is_subset_of(universe_a))
553+
.all(|p| universe_a.can_name(p.universe))
554554
}
555555

556556
/// Extend `scc` so that it can outlive some placeholder region

Diff for: ‎src/librustc_mir/borrow_check/nll/region_infer/values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ crate enum RegionElement {
148148
/// a lifetime parameter).
149149
RootUniversalRegion(RegionVid),
150150

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

Diff for: ‎src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs

+4-4
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_superuniverse(&mut self) -> ty::UniverseIndex;
162+
fn create_next_universe(&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_superuniverse(&mut self) -> ty::UniverseIndex {
222-
self.infcx.create_superuniverse()
221+
fn create_next_universe(&mut self) -> ty::UniverseIndex {
222+
self.infcx.create_next_universe()
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_superuniverse();
327+
let universe = delegate.create_next_universe();
328328
lazy_universe = Some(universe);
329329
universe
330330
});

0 commit comments

Comments
 (0)
Please sign in to comment.