Skip to content

Commit

Permalink
Remove ReClosureBound
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Mar 23, 2020
1 parent 660326e commit c3b9881
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 129 deletions.
3 changes: 0 additions & 3 deletions src/librustc/ich/impls_ty.rs
Expand Up @@ -92,9 +92,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
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)
}
Expand Down
49 changes: 24 additions & 25 deletions src/librustc/mir/query.rs
Expand Up @@ -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 = [
/// i8, // the "closure kind"
/// for<'x> fn(&'a &'x u32) -> &'x u32, // the "closure signature"
/// &'a String, // some upvar
/// 'a, // From the parent.
/// 'b,
/// i8, // the "closure kind"
/// 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 = [
/// i8, // the "closure kind"
/// for<'x> fn(&'1 &'x u32) -> &'x u32, // the "closure signature"
/// &'2 String, // some upvar
/// '1, // From the parent.
/// '2,
/// i8, // the "closure kind"
/// for<'x> fn(&'3 &'x u32) -> &'x u32, // the "closure signature"
/// &'4 String, // some upvar
/// ]
/// ```
///
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/librustc/ty/print/pretty.rs
Expand Up @@ -1547,7 +1547,7 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {

ty::ReVar(_) | ty::ReScope(_) | ty::ReErased => false,

ty::ReStatic | ty::ReEmpty(_) | ty::ReClosureBound(_) => true,
ty::ReStatic | ty::ReEmpty(_) => true,
}
}

Expand Down Expand Up @@ -1659,12 +1659,6 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, F> {
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("'_"));
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/ty/structural_impls.rs
Expand Up @@ -81,8 +81,6 @@ impl fmt::Debug for ty::RegionKind {
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)
}
Expand Down
10 changes: 0 additions & 10 deletions src/librustc/ty/sty.rs
Expand Up @@ -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> {}
Expand Down Expand Up @@ -1689,7 +1683,6 @@ impl RegionKind {
RegionKind::RePlaceholder(placeholder) => placeholder.name.is_named(),
RegionKind::ReEmpty(_) => false,
RegionKind::ReErased => false,
RegionKind::ReClosureBound(..) => false,
}
}

Expand Down Expand Up @@ -1770,9 +1763,6 @@ impl RegionKind {
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;
}
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_infer/infer/canonical/canonicalizer.rs
Expand Up @@ -336,10 +336,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, '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");
}
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/librustc_infer/infer/combine.rs
Expand Up @@ -581,10 +581,6 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
return Ok(r);
}

ty::ReClosureBound(..) => {
span_bug!(self.span, "encountered unexpected ReClosureBound: {:?}", r,);
}

ty::RePlaceholder(..)
| ty::ReVar(..)
| ty::ReEmpty(_)
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_infer/infer/error_reporting/mod.rs
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_infer/infer/freshen.rs
Expand Up @@ -135,10 +135,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
// replace all free regions with 'erased
self.tcx().lifetimes.re_erased
}

ty::ReClosureBound(..) => {
bug!("encountered unexpected region: {:?}", r,);
}
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/librustc_infer/infer/lexical_region_resolve/mod.rs
Expand Up @@ -464,12 +464,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
/// 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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/region_constraints/mod.rs
Expand Up @@ -798,7 +798,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
| 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),
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/borrow_check/diagnostics/region_name.rs
Expand Up @@ -292,8 +292,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
| ty::ReVar(..)
| ty::RePlaceholder(..)
| ty::ReEmpty(_)
| ty::ReErased
| ty::ReClosureBound(..) => None,
| ty::ReErased => None,
}
}

Expand Down
41 changes: 7 additions & 34 deletions src/librustc_mir/borrow_check/region_infer/mod.rs
Expand Up @@ -940,8 +940,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// 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>,
Expand Down Expand Up @@ -991,14 +992,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// 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.
Expand Down Expand Up @@ -2029,15 +2030,6 @@ pub trait ClosureRegionRequirementsExt<'tcx> {
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> {
Expand Down Expand Up @@ -2094,7 +2086,6 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
}

ClosureOutlivesSubject::Ty(ty) => {
let ty = self.subst_closure_mapping(tcx, closure_mapping, &ty);
debug!(
"apply_requirements: ty={:?} \
outlived_region={:?} \
Expand All @@ -2107,22 +2098,4 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
})
.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)
}
})
}
}
6 changes: 1 addition & 5 deletions src/librustc_trait_selection/opaque_types.rs
Expand Up @@ -823,11 +823,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'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.
Expand Down
1 change: 0 additions & 1 deletion src/librustc_typeck/outlives/utils.rs
Expand Up @@ -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(..)
Expand Down
1 change: 0 additions & 1 deletion src/librustc_typeck/variance/constraints.rs
Expand Up @@ -449,7 +449,6 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
}

ty::ReFree(..)
| ty::ReClosureBound(..)
| ty::ReScope(..)
| ty::ReVar(..)
| ty::RePlaceholder(..)
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -450,7 +450,6 @@ impl Clean<Option<Lifetime>> for ty::RegionKind {
| ty::ReVar(..)
| ty::RePlaceholder(..)
| ty::ReEmpty(_)
| ty::ReClosureBound(_)
| ty::ReErased => {
debug!("cannot clean region {:?}", self);
None
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit c3b9881

Please sign in to comment.