Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8498c5f

Browse files
committedFeb 7, 2020
Auto merge of #65232 - nikomatsakis:lazy-norm-anon-const-push-2, r=matthewjasper
replace the leak check with universes, take 2 This PR is an attempt to revive the "universe-based region check", which is an important step towards lazy normalization. Unlike before, we also modify the definition of `'empty` so that it is indexed by a universe. This sidesteps some of the surprising effects we saw before -- at the core, we no longer think that `exists<'a> { forall<'b> { 'b: 'a } }` is solveable. The new region lattice looks like this: ``` static ----------+-----...------+ (greatest) | | | early-bound and | | free regions | | | | | scope regions | | | | | empty(root) placeholder(U1) | | / | | / placeholder(Un) empty(U1) -- / | / ... / | / empty(Un) -------- (smallest) ``` This PR has three effects: * It changes a fair number of error messages, I think for the better. * It fixes a number of bugs. The old algorithm was too conservative and caused us to reject legal subtypings. * It also causes two regressions (things that used to compile, but now do not). * `coherence-subtyping.rs` gets an additional error. This is expected. * `issue-57639.rs` regresses as before, for the reasons covered in #57639. Both of the regressions stem from the same underlying property: without the leak check, the instantaneous "subtype" check is not able to tell whether higher-ranked subtyping will succeed or not. In both cases, we might be able to fix the problem by doing a 'leak-check like change' at some later point (e.g., as part of coherence). This is a draft PR because: * I didn't finish ripping out the leak-check completely. * We might want to consider a crater run before landing this. * We might want some kind of design meeting to cover the overall strategy. * I just remembered I never finished 100% integrating this into the canonicalization code. * I should also review what happens in NLL region checking -- it probably still has a notion of bottom (empty set). r? @matthewjasper
2 parents a29424a + 4b3c66d commit 8498c5f

File tree

45 files changed

+613
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+613
-207
lines changed
 

‎src/librustc/ich/impls_ty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
6363
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
6464
mem::discriminant(self).hash_stable(hcx, hasher);
6565
match *self {
66-
ty::ReErased | ty::ReStatic | ty::ReEmpty => {
66+
ty::ReErased | ty::ReStatic => {
6767
// No variant fields to hash for these ...
6868
}
69+
ty::ReEmpty(universe) => {
70+
universe.hash_stable(hcx, hasher);
71+
}
6972
ty::ReLateBound(db, ty::BrAnon(i)) => {
7073
db.hash_stable(hcx, hasher);
7174
i.hash_stable(hcx, hasher);

‎src/librustc/infer/canonical/canonicalizer.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,29 @@ impl CanonicalizeRegionMode for CanonicalizeQueryResponse {
167167
r: ty::Region<'tcx>,
168168
) -> ty::Region<'tcx> {
169169
match r {
170-
ty::ReFree(_) | ty::ReEmpty | ty::ReErased | ty::ReStatic | ty::ReEarlyBound(..) => r,
170+
ty::ReFree(_)
171+
| ty::ReErased
172+
| ty::ReStatic
173+
| ty::ReEmpty(ty::UniverseIndex::ROOT)
174+
| ty::ReEarlyBound(..) => r,
175+
171176
ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
172177
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderRegion(*placeholder) },
173178
r,
174179
),
180+
175181
ty::ReVar(vid) => {
176182
let universe = canonicalizer.region_var_universe(*vid);
177183
canonicalizer.canonical_var_for_region(
178184
CanonicalVarInfo { kind: CanonicalVarKind::Region(universe) },
179185
r,
180186
)
181187
}
188+
189+
ty::ReEmpty(ui) => {
190+
bug!("canonicalizing 'empty in universe {:?}", ui) // FIXME
191+
}
192+
182193
_ => {
183194
// Other than `'static` or `'empty`, the query
184195
// response should be executing in a fully
@@ -213,7 +224,7 @@ impl CanonicalizeRegionMode for CanonicalizeUserTypeAnnotation {
213224
r: ty::Region<'tcx>,
214225
) -> ty::Region<'tcx> {
215226
match r {
216-
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReErased | ty::ReEmpty | ty::ReStatic => r,
227+
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReErased | ty::ReStatic => r,
217228
ty::ReVar(_) => canonicalizer.canonical_var_for_region_in_root_universe(r),
218229
_ => {
219230
// We only expect region names that the user can type.
@@ -320,8 +331,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
320331
| ty::ReEarlyBound(..)
321332
| ty::ReFree(_)
322333
| ty::ReScope(_)
334+
| ty::ReEmpty(_)
323335
| ty::RePlaceholder(..)
324-
| ty::ReEmpty
325336
| ty::ReErased => self.canonicalize_region_mode.canonicalize_free_region(self, r),
326337

327338
ty::ReClosureBound(..) => {

0 commit comments

Comments
 (0)
Please sign in to comment.