diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-10-08 07:17:36 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-10-15 11:42:07 -0400 |
| commit | 05f67ca1a27a9e69cd99d540a0241759b83cc1bd (patch) | |
| tree | 22604c02aafae4ac00de9c8ba9c99e9370e8a308 /src/librustc | |
| parent | f4190778119383fa15758030cbf038e276a095f6 (diff) | |
| download | rust-05f67ca1a27a9e69cd99d540a0241759b83cc1bd.tar.gz rust-05f67ca1a27a9e69cd99d540a0241759b83cc1bd.zip | |
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`
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/infer/higher_ranked/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc/infer/mod.rs | 11 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 40 |
3 files changed, 28 insertions, 27 deletions
diff --git a/src/librustc/infer/higher_ranked/mod.rs b/src/librustc/infer/higher_ranked/mod.rs index 884aa956556..ae1892caa74 100644 --- a/src/librustc/infer/higher_ranked/mod.rs +++ b/src/librustc/infer/higher_ranked/mod.rs @@ -593,11 +593,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { where T : TypeFoldable<'tcx>, { - let new_universe = self.create_superuniverse(); + let next_universe = self.create_next_universe(); let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| { self.tcx.mk_region(ty::RePlaceholder(ty::Placeholder { - universe: new_universe, + universe: next_universe, name: br, })) }); diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 95ecec7d0d5..ef9886e06d4 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -1489,13 +1489,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.universe.get() } - /// Create and return a new subunivese of the current universe; - /// update `self.universe` to that new universe. At present, - /// used only in the NLL subtyping code, which uses the new - /// universe-based scheme instead of the more limited leak-check - /// scheme. - pub fn create_superuniverse(&self) -> ty::UniverseIndex { - let u = self.universe.get().superuniverse(); + /// Create and return a fresh universe that extends all previous + /// universes. Updates `self.universe` to that new universe. + pub fn create_next_universe(&self) -> ty::UniverseIndex { + let u = self.universe.get().next_universe(); self.universe.set(u); u } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 853b49098b9..4135d499c58 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1457,10 +1457,10 @@ impl<'tcx> InstantiatedPredicates<'tcx> { /// "Universes" are used during type- and trait-checking in the /// presence of `for<..>` binders to control what sets of names are /// visible. Universes are arranged into a tree: the root universe -/// contains names that are always visible. But when you enter into -/// some superuniverse, then it may add names that are only visible -/// within that subtree (but it can still name the names of its -/// ancestor universes). +/// contains names that are always visible. Each child then adds a new +/// set of names that are visible, in addition to those of its parent. +/// We say that the child universe "extends" the parent universe with +/// new names. /// /// To make this more concrete, consider this program: /// @@ -1472,11 +1472,11 @@ impl<'tcx> InstantiatedPredicates<'tcx> { /// ``` /// /// The struct name `Foo` is in the root universe U0. But the type -/// parameter `T`, introduced on `bar`, is in a superuniverse U1 -- -/// i.e., within `bar`, we can name both `T` and `Foo`, but outside of -/// `bar`, we cannot name `T`. Then, within the type of `y`, the -/// region `'a` is in a superuniverse U2 of U1, because we can name it -/// inside the fn type but not outside. +/// parameter `T`, introduced on `bar`, is in an extended universe U1 +/// -- i.e., within `bar`, we can name both `T` and `Foo`, but outside +/// of `bar`, we cannot name `T`. Then, within the type of `y`, the +/// region `'a` is in a universe U2 that extends U1, because we can +/// name it inside the fn type but not outside. /// /// Universes are used to do type- and trait-checking around these /// "forall" binders (also called **universal quantification**). The @@ -1500,24 +1500,28 @@ impl_stable_hash_for!(struct UniverseIndex { private }); impl UniverseIndex { pub const ROOT: UniverseIndex = UniverseIndex::from_u32_const(0); - /// A "superuniverse" corresponds to being inside a `forall` quantifier. - /// So, for example, suppose we have this type in universe `U`: + /// Returns the "next" universe index in order -- this new index + /// is considered to extend all previous universes. This + /// corresponds to entering a `forall` quantifier. So, for + /// example, suppose we have this type in universe `U`: /// /// ``` /// for<'a> fn(&'a u32) /// ``` /// /// Once we "enter" into this `for<'a>` quantifier, we are in a - /// superuniverse of `U` -- in this new universe, we can name the - /// region `'a`, but that region was not nameable from `U` because - /// it was not in scope there. - pub fn superuniverse(self) -> UniverseIndex { + /// new universe that extends `U` -- in this new universe, we can + /// name the region `'a`, but that region was not nameable from + /// `U` because it was not in scope there. + pub fn next_universe(self) -> UniverseIndex { UniverseIndex::from_u32(self.private.checked_add(1).unwrap()) } - /// True if the names in this universe are a subset of the names in `other`. - pub fn is_subset_of(self, other: UniverseIndex) -> bool { - self.private <= other.private + /// True if `self` can name a name from `other` -- in other words, + /// if the set of names in `self` is a superset of those in + /// `other`. + pub fn can_name(self, other: UniverseIndex) -> bool { + self.private >= other.private } } |
