Remove ReClosureBound

This commit is contained in:
Matthew Jasper 2020-03-11 22:24:20 +00:00
parent 660326e979
commit c3b98813c4
20 changed files with 50 additions and 129 deletions

View File

@ -92,9 +92,6 @@ fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHas
ty::ReFree(ref free_region) => {
free_region.hash_stable(hcx, hasher);
}
ty::ReClosureBound(vid) => {
vid.hash_stable(hcx, hasher);
}
ty::ReVar(..) | ty::RePlaceholder(..) => {
bug!("StableHasher: unexpected region {:?}", *self)
}

View File

@ -88,34 +88,35 @@ pub struct ConstQualifs {
/// requirements are then verified and proved by the closure's
/// creating function. This struct encodes those requirements.
///
/// The requirements are listed as being between various
/// `RegionVid`. The 0th region refers to `'static`; subsequent region
/// vids refer to the free regions that appear in the closure (or
/// generator's) type, in order of appearance. (This numbering is
/// actually defined by the `UniversalRegions` struct in the NLL
/// region checker. See for example
/// `UniversalRegions::closure_mapping`.) Note that we treat the free
/// regions in the closure's type "as if" they were erased, so their
/// precise identity is not important, only their position.
/// The requirements are listed as being between various `RegionVid`. The 0th
/// region refers to `'static`; subsequent region vids refer to the free
/// regions that appear in the closure (or generator's) type, in order of
/// appearance. (This numbering is actually defined by the `UniversalRegions`
/// struct in the NLL region checker. See for example
/// `UniversalRegions::closure_mapping`.) Note the free regions in the
/// closure's signature and captures are erased.
///
/// Example: If type check produces a closure with the closure substs:
///
/// ```text
/// ClosureSubsts = [
/// 'a, // From the parent.
/// 'b,
/// i8, // the "closure kind"
/// for<'x> fn(&'a &'x u32) -> &'x u32, // the "closure signature"
/// &'a String, // some upvar
/// for<'x> fn(&'<erased> &'x u32) -> &'x u32, // the "closure signature"
/// &'<erased> String, // some upvar
/// ]
/// ```
///
/// here, there is one unique free region (`'a`) but it appears
/// twice. We would "renumber" each occurrence to a unique vid, as follows:
/// We would "renumber" each free region to a unique vid, as follows:
///
/// ```text
/// ClosureSubsts = [
/// '1, // From the parent.
/// '2,
/// i8, // the "closure kind"
/// for<'x> fn(&'1 &'x u32) -> &'x u32, // the "closure signature"
/// &'2 String, // some upvar
/// for<'x> fn(&'3 &'x u32) -> &'x u32, // the "closure signature"
/// &'4 String, // some upvar
/// ]
/// ```
///
@ -124,14 +125,12 @@ pub struct ConstQualifs {
/// can be extracted from its type and constrained to have the given
/// outlives relationship.
///
/// In some cases, we have to record outlives requirements between
/// types and regions as well. In that case, if those types include
/// any regions, those regions are recorded as `ReClosureBound`
/// instances assigned one of these same indices. Those regions will
/// be substituted away by the creator. We use `ReClosureBound` in
/// that case because the regions must be allocated in the global
/// `TyCtxt`, and hence we cannot use `ReVar` (which is what we use
/// internally within the rest of the NLL code).
/// In some cases, we have to record outlives requirements between types and
/// regions as well. In that case, if those types include any regions, those
/// regions are recorded using their external names (`ReStatic`,
/// `ReEarlyBound`, `ReFree`). We use these because in a query response we
/// cannot use `ReVar` (which is what we use internally within the rest of the
/// NLL code).
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub struct ClosureRegionRequirements<'tcx> {
/// The number of external regions defined on the closure. In our

View File

@ -1547,7 +1547,7 @@ fn region_should_not_be_omitted(&self, region: ty::Region<'_>) -> bool {
ty::ReVar(_) | ty::ReScope(_) | ty::ReErased => false,
ty::ReStatic | ty::ReEmpty(_) | ty::ReClosureBound(_) => true,
ty::ReStatic | ty::ReEmpty(_) => true,
}
}
@ -1659,12 +1659,6 @@ pub fn pretty_print_region(mut self, region: ty::Region<'_>) -> Result<Self, fmt
p!(write("'<empty:{:?}>", ui));
return Ok(self);
}
// The user should never encounter these in unsubstituted form.
ty::ReClosureBound(vid) => {
p!(write("{:?}", vid));
return Ok(self);
}
}
p!(write("'_"));

View File

@ -81,8 +81,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ty::ReEarlyBound(ref data) => write!(f, "ReEarlyBound({}, {})", data.index, data.name),
ty::ReClosureBound(ref vid) => write!(f, "ReClosureBound({:?})", vid),
ty::ReLateBound(binder_id, ref bound_region) => {
write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
}

View File

@ -1442,12 +1442,6 @@ pub enum RegionKind {
/// Erased region, used by trait selection, in MIR and during codegen.
ReErased,
/// These are regions bound in the "defining type" for a
/// closure. They are used ONLY as part of the
/// `ClosureRegionRequirements` that are produced by MIR borrowck.
/// See `ClosureRegionRequirements` for more details.
ReClosureBound(RegionVid),
}
impl<'tcx> rustc_serialize::UseSpecializedDecodable for Region<'tcx> {}
@ -1689,7 +1683,6 @@ pub fn has_name(&self) -> bool {
RegionKind::RePlaceholder(placeholder) => placeholder.name.is_named(),
RegionKind::ReEmpty(_) => false,
RegionKind::ReErased => false,
RegionKind::ReClosureBound(..) => false,
}
}
@ -1770,9 +1763,6 @@ pub fn type_flags(&self) -> TypeFlags {
ty::ReEmpty(_) | ty::ReStatic => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
}
ty::ReClosureBound(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
}
ty::ReLateBound(..) => {
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
}

View File

@ -336,10 +336,6 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
| ty::ReEmpty(_)
| ty::RePlaceholder(..)
| ty::ReErased => self.canonicalize_region_mode.canonicalize_free_region(self, r),
ty::ReClosureBound(..) => {
bug!("closure bound region encountered during canonicalization");
}
}
}

View File

@ -581,10 +581,6 @@ fn regions(
return Ok(r);
}
ty::ReClosureBound(..) => {
span_bug!(self.span, "encountered unexpected ReClosureBound: {:?}", r,);
}
ty::RePlaceholder(..)
| ty::ReVar(..)
| ty::ReEmpty(_)

View File

@ -152,11 +152,6 @@ pub(super) fn note_and_explain_region(
ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
(format!("lifetime {:?}", region), None)
}
// We shouldn't encounter an error message with ReClosureBound.
ty::ReClosureBound(..) => {
bug!("encountered unexpected ReClosureBound: {:?}", region,);
}
};
emit_msg_span(err, prefix, description, span, suffix);

View File

@ -135,10 +135,6 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
// replace all free regions with 'erased
self.tcx().lifetimes.re_erased
}
ty::ReClosureBound(..) => {
bug!("encountered unexpected region: {:?}", r,);
}
}
}

View File

@ -464,12 +464,7 @@ fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool {
/// term "concrete regions").
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
let r = match (a, b) {
(&ty::ReClosureBound(..), _)
| (_, &ty::ReClosureBound(..))
| (&ReLateBound(..), _)
| (_, &ReLateBound(..))
| (&ReErased, _)
| (_, &ReErased) => {
(&ReLateBound(..), _) | (_, &ReLateBound(..)) | (&ReErased, _) | (_, &ReErased) => {
bug!("cannot relate region: LUB({:?}, {:?})", a, b);
}

View File

@ -798,7 +798,7 @@ pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
| ty::ReEarlyBound(..) => ty::UniverseIndex::ROOT,
ty::ReEmpty(ui) => ui,
ty::RePlaceholder(placeholder) => placeholder.universe,
ty::ReClosureBound(vid) | ty::ReVar(vid) => self.var_universe(vid),
ty::ReVar(vid) => self.var_universe(vid),
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),
}
}

View File

@ -292,8 +292,7 @@ fn give_name_from_error_region(&self, fr: RegionVid) -> Option<RegionName> {
| ty::ReVar(..)
| ty::RePlaceholder(..)
| ty::ReEmpty(_)
| ty::ReErased
| ty::ReClosureBound(..) => None,
| ty::ReErased => None,
}
}

View File

@ -940,8 +940,9 @@ fn try_promote_type_test(
/// inference variables with some region from the closure
/// signature -- this is not always possible, so this is a
/// fallible process. Presuming we do find a suitable region, we
/// will represent it with a `ReClosureBound`, which is a
/// `RegionKind` variant that can be allocated in the gcx.
/// will use it's *external name*, which will be a `RegionKind`
/// variant that can be used in query responses such as
/// `ReEarlyBound`.
fn try_promote_type_test_subject(
&self,
infcx: &InferCtxt<'_, 'tcx>,
@ -991,14 +992,14 @@ fn try_promote_type_test_subject(
// find an equivalent.
let upper_bound = self.non_local_universal_upper_bound(region_vid);
if self.region_contains(region_vid, upper_bound) {
tcx.mk_region(ty::ReClosureBound(upper_bound))
self.definitions[upper_bound].external_name.unwrap_or(r)
} else {
// In the case of a failure, use a `ReVar`
// result. This will cause the `lift` later on to
// fail.
// In the case of a failure, use a `ReVar` result. This will
// cause the `has_local_value` later on to return `None`.
r
}
});
debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
// `has_local_value` will only be true if we failed to promote some region.
@ -2029,15 +2030,6 @@ fn apply_requirements(
closure_def_id: DefId,
closure_substs: SubstsRef<'tcx>,
) -> Vec<QueryOutlivesConstraint<'tcx>>;
fn subst_closure_mapping<T>(
&self,
tcx: TyCtxt<'tcx>,
closure_mapping: &IndexVec<RegionVid, ty::Region<'tcx>>,
value: &T,
) -> T
where
T: TypeFoldable<'tcx>;
}
impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx> {
@ -2094,7 +2086,6 @@ fn apply_requirements(
}
ClosureOutlivesSubject::Ty(ty) => {
let ty = self.subst_closure_mapping(tcx, closure_mapping, &ty);
debug!(
"apply_requirements: ty={:?} \
outlived_region={:?} \
@ -2107,22 +2098,4 @@ fn apply_requirements(
})
.collect()
}
fn subst_closure_mapping<T>(
&self,
tcx: TyCtxt<'tcx>,
closure_mapping: &IndexVec<RegionVid, ty::Region<'tcx>>,
value: &T,
) -> T
where
T: TypeFoldable<'tcx>,
{
tcx.fold_regions(value, &mut false, |r, _depth| {
if let ty::ReClosureBound(vid) = r {
closure_mapping[*vid]
} else {
bug!("subst_closure_mapping: encountered non-closure bound free region {:?}", r)
}
})
}
}

View File

@ -823,11 +823,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
// The regions that we expect from borrow checking.
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReEmpty(ty::UniverseIndex::ROOT) => {}
ty::ReEmpty(_)
| ty::RePlaceholder(_)
| ty::ReVar(_)
| ty::ReScope(_)
| ty::ReClosureBound(_) => {
ty::ReEmpty(_) | ty::RePlaceholder(_) | ty::ReVar(_) | ty::ReScope(_) => {
// All of the regions in the type should either have been
// erased by writeback, or mapped back to named regions by
// borrow checking.

View File

@ -170,7 +170,6 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
// These regions don't appear in types from type declarations:
RegionKind::ReErased
| RegionKind::ReClosureBound(..)
| RegionKind::ReScope(..)
| RegionKind::ReVar(..)
| RegionKind::RePlaceholder(..)

View File

@ -449,7 +449,6 @@ fn add_constraints_from_region(
}
ty::ReFree(..)
| ty::ReClosureBound(..)
| ty::ReScope(..)
| ty::ReVar(..)
| ty::RePlaceholder(..)

View File

@ -450,7 +450,6 @@ fn clean(&self, cx: &DocContext<'_>) -> Option<Lifetime> {
| ty::ReVar(..)
| ty::RePlaceholder(..)
| ty::ReEmpty(_)
| ty::ReClosureBound(_)
| ty::ReErased => {
debug!("cannot clean region {:?}", self);
None

View File

@ -108,7 +108,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)),
]
= note: number of external vids: 4
= note: where <T as Anything<ReClosureBound('_#2r)>>::AssocType: '_#3r
= note: where <T as Anything<ReEarlyBound(1, 'b)>>::AssocType: '_#3r
note: no external requirements
--> $DIR/projection-one-region-closure.rs:62:1

View File

@ -90,7 +90,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)),
]
= note: number of external vids: 4
= note: where <T as Anything<ReClosureBound('_#2r)>>::AssocType: '_#3r
= note: where <T as Anything<ReEarlyBound(1, 'b)>>::AssocType: '_#3r
note: no external requirements
--> $DIR/projection-one-region-trait-bound-closure.rs:52:1

View File

@ -10,7 +10,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
]
= note: late-bound region is '_#4r
= note: number of external vids: 5
= note: where <T as Anything<ReClosureBound('_#1r), ReClosureBound('_#2r)>>::AssocType: '_#3r
= note: where <T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType: '_#3r
note: no external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:34:1
@ -26,13 +26,13 @@ LL | | }
|
= note: defining type: no_relationships_late::<'_#1r, '_#2r, T>
error[E0309]: the associated type `<T as Anything<'_#5r, '_#6r>>::AssocType` may not live long enough
error[E0309]: the associated type `<T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType` may not live long enough
--> $DIR/projection-two-region-trait-bound-closure.rs:38:29
|
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as Anything<'_#5r, '_#6r>>::AssocType: 'a`...
= help: consider adding an explicit lifetime bound `<T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType: 'a`...
note: external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:48:29
@ -45,7 +45,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
extern "rust-call" fn((std::cell::Cell<&'_#4r ()>, T)),
]
= note: number of external vids: 5
= note: where <T as Anything<ReClosureBound('_#2r), ReClosureBound('_#3r)>>::AssocType: '_#4r
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: '_#4r
note: no external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:43:1
@ -61,13 +61,13 @@ LL | | }
|
= note: defining type: no_relationships_early::<'_#1r, '_#2r, '_#3r, T>
error[E0309]: the associated type `<T as Anything<'_#6r, '_#7r>>::AssocType` may not live long enough
error[E0309]: the associated type `<T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType` may not live long enough
--> $DIR/projection-two-region-trait-bound-closure.rs:48:29
|
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as Anything<'_#6r, '_#7r>>::AssocType: 'a`...
= help: consider adding an explicit lifetime bound `<T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: 'a`...
note: external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:61:29
@ -80,7 +80,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
extern "rust-call" fn((std::cell::Cell<&'_#4r ()>, T)),
]
= note: number of external vids: 5
= note: where <T as Anything<ReClosureBound('_#2r), ReClosureBound('_#3r)>>::AssocType: '_#4r
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: '_#4r
note: no external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:53:1
@ -107,7 +107,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
extern "rust-call" fn((std::cell::Cell<&'_#4r ()>, T)),
]
= note: number of external vids: 5
= note: where <T as Anything<ReClosureBound('_#2r), ReClosureBound('_#3r)>>::AssocType: '_#4r
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: '_#4r
note: no external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:65:1
@ -134,7 +134,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
extern "rust-call" fn((std::cell::Cell<&'_#4r ()>, T)),
]
= note: number of external vids: 5
= note: where <T as Anything<ReClosureBound('_#2r), ReClosureBound('_#3r)>>::AssocType: '_#4r
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: '_#4r
note: no external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:74:1
@ -162,7 +162,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
]
= note: late-bound region is '_#3r
= note: number of external vids: 4
= note: where <T as Anything<ReClosureBound('_#1r), ReClosureBound('_#1r)>>::AssocType: '_#2r
= note: where <T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(0, 'b)>>::AssocType: '_#2r
note: no external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:83:1
@ -202,7 +202,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T)),
]
= note: number of external vids: 4
= note: where <T as Anything<ReClosureBound('_#2r), ReClosureBound('_#2r)>>::AssocType: '_#3r
= note: where <T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(1, 'b)>>::AssocType: '_#3r
note: no external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:92:1
@ -229,7 +229,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T)),
]
= note: number of external vids: 3
= note: where <T as Anything<ReClosureBound('_#1r), ReClosureBound('_#1r)>>::AssocType: '_#2r
= note: where <T as Anything<ReEarlyBound(0, 'a), ReEarlyBound(0, 'a)>>::AssocType: '_#2r
note: no external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:101:1