Skip to content

Commit 8c4ad4e

Browse files
committed
Auto merge of #54649 - nikomatsakis:universes-refactor-1, r=scalexm
adopt "placeholders" to represent universally quantified regions This does a few preliminary refactorings that lay some groundwork for moving towards universe integration. Two things, primarily: - Rename from "skolemized" to "placeholder" - When instantiating `for<'a, 'b, 'c>`, just create one universe for all 3 regions, and distinguish them from one another using the `BoundRegion`. - This is more accurate, and I think that in general we'll be moving towards a model of separating "binder" (universe, debruijn index) from "index within binder" in a number of places. - In principle, it feels the current setup of making lots of universes could lead to us doing the wrong thing, but I've actually not been able to come up with an example where this is so. r? @scalexm cc @arielb1
2 parents a57f1c9 + 85b9956 commit 8c4ad4e

File tree

34 files changed

+1883
-1547
lines changed

34 files changed

+1883
-1547
lines changed

src/librustc/ich/impls_ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ for ty::RegionKind {
131131
}
132132
ty::ReLateBound(..) |
133133
ty::ReVar(..) |
134-
ty::ReSkolemized(..) => {
134+
ty::RePlaceholder(..) => {
135135
bug!("StableHasher: unexpected region {:?}", *self)
136136
}
137137
}

src/librustc/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
224224
ty::ReEarlyBound(..)
225225
| ty::ReFree(_)
226226
| ty::ReScope(_)
227-
| ty::ReSkolemized(..)
227+
| ty::RePlaceholder(..)
228228
| ty::ReEmpty
229229
| ty::ReErased => {
230230
if self.canonicalize_region_mode.other_free_regions {

src/librustc/infer/combine.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,10 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
458458
return Ok(r);
459459
}
460460

461-
// Always make a fresh region variable for skolemized regions;
462-
// the higher-ranked decision procedures rely on this.
463-
ty::ReSkolemized(..) => { }
461+
// Always make a fresh region variable for placeholder
462+
// regions; the higher-ranked decision procedures rely on
463+
// this.
464+
ty::RePlaceholder(..) => { }
464465

465466
// For anything else, we make a region variable, unless we
466467
// are *equating*, in which case it's just wasteful.

src/librustc/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
142142

143143
ty::ReEmpty => ("the empty lifetime".to_owned(), None),
144144

145-
// FIXME(#13998) ReSkolemized should probably print like
145+
// FIXME(#13998) RePlaceholder should probably print like
146146
// ReFree rather than dumping Debug output on the user.
147147
//
148148
// We shouldn't really be having unification failures with ReVar
149149
// and ReLateBound though.
150-
ty::ReSkolemized(..) | ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
150+
ty::RePlaceholder(..) | ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
151151
(format!("lifetime {:?}", region), None)
152152
}
153153

src/librustc/infer/freshen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
107107
ty::ReFree(_) |
108108
ty::ReScope(_) |
109109
ty::ReVar(_) |
110-
ty::ReSkolemized(..) |
110+
ty::RePlaceholder(..) |
111111
ty::ReEmpty |
112112
ty::ReErased => {
113113
// replace all free regions with 'erased

src/librustc/infer/higher_ranked/README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ the same lifetime, but not the reverse.
7272
Here is the algorithm we use to perform the subtyping check:
7373

7474
1. Replace all bound regions in the subtype with new variables
75-
2. Replace all bound regions in the supertype with skolemized
76-
equivalents. A "skolemized" region is just a new fresh region
75+
2. Replace all bound regions in the supertype with placeholder
76+
equivalents. A "placeholder" region is just a new fresh region
7777
name.
7878
3. Check that the parameter and return types match as normal
79-
4. Ensure that no skolemized regions 'leak' into region variables
79+
4. Ensure that no placeholder regions 'leak' into region variables
8080
visible from "the outside"
8181

8282
Let's walk through some examples and see how this algorithm plays out.
@@ -95,7 +95,7 @@ like so:
9595
Here the upper case `&A` indicates a *region variable*, that is, a
9696
region whose value is being inferred by the system. I also replaced
9797
`&b` with `&x`---I'll use letters late in the alphabet (`x`, `y`, `z`)
98-
to indicate skolemized region names. We can assume they don't appear
98+
to indicate placeholder region names. We can assume they don't appear
9999
elsewhere. Note that neither the sub- nor the supertype bind any
100100
region names anymore (as indicated by the absence of `<` and `>`).
101101

@@ -133,7 +133,7 @@ match. This will ultimately require (as before) that `'a` <= `&x`
133133
must hold: but this does not hold. `self` and `x` are both distinct
134134
free regions. So the subtype check fails.
135135

136-
#### Checking for skolemization leaks
136+
#### Checking for placeholder leaks
137137

138138
You may be wondering about that mysterious last step in the algorithm.
139139
So far it has not been relevant. The purpose of that last step is to
@@ -159,7 +159,7 @@ Now we compare the return types, which are covariant, and hence we have:
159159

160160
fn(&'A T) <: for<'b> fn(&'b T)?
161161

162-
Here we skolemize the bound region in the supertype to yield:
162+
Here we replace the bound region in the supertype with a placeholder to yield:
163163

164164
fn(&'A T) <: fn(&'x T)?
165165

@@ -175,23 +175,23 @@ region `x` and think that everything is happy. In fact, this behavior
175175
is *necessary*, it was key to the first example we walked through.
176176

177177
The difference between this example and the first one is that the variable
178-
`A` already existed at the point where the skolemization occurred. In
178+
`A` already existed at the point where the placeholders were added. In
179179
the first example, you had two functions:
180180

181181
for<'a> fn(&'a T) <: for<'b> fn(&'b T)
182182

183183
and hence `&A` and `&x` were created "together". In general, the
184-
intention of the skolemized names is that they are supposed to be
184+
intention of the placeholder names is that they are supposed to be
185185
fresh names that could never be equal to anything from the outside.
186186
But when inference comes into play, we might not be respecting this
187187
rule.
188188

189189
So the way we solve this is to add a fourth step that examines the
190-
constraints that refer to skolemized names. Basically, consider a
190+
constraints that refer to placeholder names. Basically, consider a
191191
non-directed version of the constraint graph. Let `Tainted(x)` be the
192-
set of all things reachable from a skolemized variable `x`.
192+
set of all things reachable from a placeholder variable `x`.
193193
`Tainted(x)` should not contain any regions that existed before the
194-
step at which the skolemization was performed. So this case here
194+
step at which the placeholders were created. So this case here
195195
would fail because `&x` was created alone, but is relatable to `&A`.
196196

197197
## Computing the LUB and GLB

0 commit comments

Comments
 (0)