Skip to content

Commit a8437a0

Browse files
committedDec 7, 2017
Auto merge of #46509 - nikomatsakis:nll-master-to-rust-master-3, r=arielb1
closure handling for NLL This branch overhauls how we handle closures and universally quantified regions in the NLL code. The goal is to lay the groundwork for "region erasure" by the HIR-based type checker, as well as to avoid "crazy hacks" when it comes to closures. This means that when we type-check a closure, we cannot make use of *any* of the precise values of free regions in its signature, since those are inferred by the HIR type-checker. Therefore, the new code handles closures by: - Creating fresh regions for every free region that appears in the closure's type, which now includes both its signature and the types of all upvars. - This means that the closure is type-checked without knowing about the connections. - When we encounter some region relationship that we can't locally verify, we propagate it to the closure's creator. - During MIR typeck, the closure creators then validates those relationships. For a good example and explanation, see e.g. the test `src/test/nll/closure-requirements/propagate-despite-same-free-region.rs`. Upcoming changes in the next NLL PR (not included in this PR in order to keep it manageable): - Improvements to the MIR type checker so that it handles a lot of stuff presently overlooked - Refactor how we store region values to make it more efficient, better encapsulated - Propagate "type-outlives" relationships like `T: 'a` in a similar fashion to the one covered in this PR (still in the works, but close) - Improvements to error reporting (still in the works) r? @arielb1 or @pnkfelix
·
1.90.01.24.0
2 parents ee25791 + 1db58d7 commit a8437a0

File tree

79 files changed

+3288
-355
lines changed

Some content is hidden

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

79 files changed

+3288
-355
lines changed
 

‎src/librustc/ich/impls_mir.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,15 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for mir::Literal<'gcx> {
572572
}
573573

574574
impl_stable_hash_for!(struct mir::Location { block, statement_index });
575+
576+
impl_stable_hash_for!(struct mir::ClosureRegionRequirements {
577+
num_external_vids,
578+
outlives_requirements
579+
});
580+
581+
impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement {
582+
free_region,
583+
outlived_free_region,
584+
blame_span
585+
});
586+

‎src/librustc/ich/impls_ty.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ for ty::RegionKind {
8484
}
8585
}
8686

87+
impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::RegionVid {
88+
#[inline]
89+
fn hash_stable<W: StableHasherResult>(&self,
90+
hcx: &mut StableHashingContext<'gcx>,
91+
hasher: &mut StableHasher<W>) {
92+
use rustc_data_structures::indexed_vec::Idx;
93+
self.index().hash_stable(hcx, hasher);
94+
}
95+
}
96+
8797
impl<'gcx> HashStable<StableHashingContext<'gcx>>
8898
for ty::adjustment::AutoBorrow<'gcx> {
8999
fn hash_stable<W: StableHasherResult>(&self,

0 commit comments

Comments
 (0)
Please sign in to comment.