Remove ReEmpty

This commit is contained in:
Jack Huey 2022-06-26 15:40:45 -04:00
parent dd0335a27f
commit 1ca9eb8ec3
27 changed files with 64 additions and 256 deletions

View file

@ -357,11 +357,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
ty::BoundRegionKind::BrAnon(_) => None,
},
ty::ReLateBound(..)
| ty::ReVar(..)
| ty::RePlaceholder(..)
| ty::ReEmpty(_)
| ty::ReErased => None,
ty::ReLateBound(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => None,
}
}

View file

@ -486,9 +486,9 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
ty::ReErased => return r,
// The regions that we expect from borrow checking.
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReEmpty(ty::UniverseIndex::ROOT) => {}
ty::ReEarlyBound(_) | ty::ReFree(_) => {}
ty::ReEmpty(_) | ty::RePlaceholder(_) | ty::ReVar(_) => {
ty::RePlaceholder(_) | ty::ReVar(_) => {
// 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

@ -347,13 +347,6 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
match outlives_bound {
OutlivesBound::RegionSubRegion(r1, r2) => {
// `where Type:` is lowered to `where Type: 'empty` so that
// we check `Type` is well formed, but there's no use for
// this bound here.
if r1.is_empty() {
return;
}
// The bound says that `r1 <= r2`; we store `r2: r1`.
let r1 = self.universal_regions.to_region_vid(r1);
let r2 = self.universal_regions.to_region_vid(r2);

View file

@ -54,13 +54,6 @@ pub struct UniversalRegions<'tcx> {
/// The total number of universal region variables instantiated.
num_universals: usize,
/// A special region variable created for the `'empty(U0)` region.
/// Note that this is **not** a "universal" region, as it doesn't
/// represent a universally bound placeholder or any such thing.
/// But we do create it here in this type because it's a useful region
/// to have around in a few limited cases.
pub root_empty: RegionVid,
/// The "defining" type for this function, with all universal
/// regions instantiated. For a closure or generator, this is the
/// closure type, but for a top-level function it's the `FnDef`.
@ -323,11 +316,7 @@ impl<'tcx> UniversalRegions<'tcx> {
/// See `UniversalRegionIndices::to_region_vid`.
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
if let ty::ReEmpty(ty::UniverseIndex::ROOT) = *r {
self.root_empty
} else {
self.indices.to_region_vid(r)
}
self.indices.to_region_vid(r)
}
/// As part of the NLL unit tests, you can annotate a function with
@ -501,16 +490,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
_ => None,
};
let root_empty = self
.infcx
.next_nll_region_var(NllRegionVariableOrigin::Existential { from_forall: true })
.to_region_vid();
UniversalRegions {
indices,
fr_static,
fr_fn_body,
root_empty,
first_extern_index,
first_local_index,
num_universals,

View file

@ -27,13 +27,6 @@ impl<'a> DescriptionCtx<'a> {
me.kind = "restatic";
}
ty::ReEmpty(ty::UniverseIndex::ROOT) => me.kind = "reempty",
ty::ReEmpty(ui) => {
me.kind = "reemptyuni";
me.arg = format!("{:?}", ui);
}
ty::RePlaceholder(_) => return None,
// FIXME(#13998) RePlaceholder should probably print like

View file

@ -180,11 +180,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
r: ty::Region<'tcx>,
) -> ty::Region<'tcx> {
match *r {
ty::ReFree(_)
| ty::ReErased
| ty::ReStatic
| ty::ReEmpty(ty::UniverseIndex::ROOT)
| ty::ReEarlyBound(..) => r,
ty::ReFree(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyBound(..) => r,
ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderRegion(placeholder) },
@ -199,10 +195,6 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
)
}
ty::ReEmpty(ui) => {
bug!("canonicalizing 'empty in universe {:?}", ui) // FIXME
}
_ => {
// Other than `'static` or `'empty`, the query
// response should be executing in a fully
@ -381,7 +373,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
ty::ReStatic
| ty::ReEarlyBound(..)
| ty::ReFree(_)
| ty::ReEmpty(_)
| ty::RePlaceholder(..)
| ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r),
}

View file

@ -688,7 +688,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
ty::RePlaceholder(..)
| ty::ReVar(..)
| ty::ReEmpty(_)
| ty::ReStatic
| ty::ReEarlyBound(..)
| ty::ReFree(..) => {
@ -900,7 +899,6 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
ty::RePlaceholder(..)
| ty::ReVar(..)
| ty::ReEmpty(_)
| ty::ReStatic
| ty::ReEarlyBound(..)
| ty::ReFree(..) => {

View file

@ -96,11 +96,6 @@ pub(super) fn note_and_explain_region<'tcx>(
msg_span_from_free_region(tcx, region, alt_span)
}
ty::ReEmpty(ty::UniverseIndex::ROOT) => ("the empty lifetime".to_owned(), alt_span),
// uh oh, hope no user ever sees THIS
ty::ReEmpty(ui) => (format!("the empty lifetime in universe {:?}", ui), alt_span),
ty::RePlaceholder(_) => return,
// FIXME(#13998) RePlaceholder should probably print like
@ -139,8 +134,6 @@ fn msg_span_from_free_region<'tcx>(
(msg, Some(span))
}
ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
ty::ReEmpty(ty::UniverseIndex::ROOT) => ("an empty lifetime".to_owned(), alt_span),
ty::ReEmpty(ui) => (format!("an empty lifetime in universe {:?}", ui), alt_span),
_ => bug!("{:?}", region),
}
}
@ -250,17 +243,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
// Explain the region we are capturing.
match *hidden_region {
ty::ReEmpty(ty::UniverseIndex::ROOT) => {
// All lifetimes shorter than the function body are `empty` in
// lexical region resolution. The default explanation of "an empty
// lifetime" isn't really accurate here.
let message = format!(
"hidden type `{}` captures lifetime smaller than the function body",
hidden_ty
);
err.span_note(span, &message);
}
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) => {
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => {
// Assuming regionck succeeded (*), we ought to always be
// capturing *some* region from the fn header, and hence it
// ought to be free. So under normal circumstances, we will go

View file

@ -126,7 +126,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
| ty::ReFree(_)
| ty::ReVar(_)
| ty::RePlaceholder(..)
| ty::ReEmpty(_)
| ty::ReErased => {
// replace all free regions with 'erased
self.tcx().lifetimes.re_erased

View file

@ -16,7 +16,7 @@ use rustc_data_structures::intern::Interned;
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{ReEarlyBound, ReEmpty, ReErased, ReFree, ReStatic};
use rustc_middle::ty::{ReEarlyBound, ReErased, ReFree, ReStatic};
use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar};
use rustc_middle::ty::{Region, RegionVid};
use rustc_span::Span;
@ -261,13 +261,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
cur_region
}
ReEmpty(b_ui) => {
// Empty regions are ordered according to the universe
// they are associated with.
let ui = a_universe.min(b_ui);
self.tcx().mk_region(ReEmpty(ui))
}
RePlaceholder(placeholder) => {
// If the empty and placeholder regions are in the same universe,
// then the LUB is the Placeholder region (which is the cur_region).
@ -399,13 +392,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
a_region
}
ReEmpty(a_ui) => {
// Empty regions are ordered according to the universe
// they are associated with.
let ui = a_ui.min(empty_ui);
self.tcx().mk_region(ReEmpty(ui))
}
RePlaceholder(placeholder) => {
// If this empty region is from a universe that can
// name the placeholder, then the placeholder is
@ -428,9 +414,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
// check below for a common case, here purely as an
// optimization.
let b_universe = self.var_infos[b_vid].universe;
if let ReEmpty(a_universe) = *a_region && a_universe == b_universe {
return false;
}
let mut lub = self.lub_concrete_regions(a_region, cur_region);
if lub == cur_region {
@ -470,7 +453,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
// they are associated with.
a_ui.min(b_ui) == b_ui
}
(VarValue::Value(a), VarValue::Empty(b_ui)) => {
(VarValue::Value(a), VarValue::Empty(_)) => {
match *a {
ReLateBound(..) | ReErased => {
bug!("cannot relate region: {:?}", a);
@ -493,12 +476,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
false
}
ReEmpty(a_ui) => {
// Empty regions are ordered according to the universe
// they are associated with.
a_ui.min(b_ui) == b_ui
}
RePlaceholder(_) => {
// The LUB is either `a` or `'static`
false
@ -526,12 +503,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
true
}
ReEmpty(b_ui) => {
// Empty regions are ordered according to the universe
// they are associated with.
a_ui.min(b_ui) == b_ui
}
RePlaceholder(placeholder) => {
// If this empty region is from a universe that can
// name the placeholder, then the placeholder is
@ -599,37 +570,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
self.tcx().lifetimes.re_static
}
(ReEmpty(_), ReEarlyBound(_) | ReFree(_)) => {
// All empty regions are less than early-bound, free,
// and scope regions.
b
}
(ReEarlyBound(_) | ReFree(_), ReEmpty(_)) => {
// All empty regions are less than early-bound, free,
// and scope regions.
a
}
(ReEmpty(a_ui), ReEmpty(b_ui)) => {
// Empty regions are ordered according to the universe
// they are associated with.
let ui = a_ui.min(b_ui);
self.tcx().mk_region(ReEmpty(ui))
}
(ReEmpty(empty_ui), RePlaceholder(placeholder))
| (RePlaceholder(placeholder), ReEmpty(empty_ui)) => {
// If this empty region is from a universe that can
// name the placeholder, then the placeholder is
// larger; otherwise, the only ancestor is `'static`.
if empty_ui.can_name(placeholder.universe) {
self.tcx().mk_region(RePlaceholder(placeholder))
} else {
self.tcx().lifetimes.re_static
}
}
(ReEarlyBound(_) | ReFree(_), ReEarlyBound(_) | ReFree(_)) => {
self.region_rels.lub_free_regions(a, b)
}
@ -1088,9 +1028,9 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
ty::ReVar(rid) => match var_values.values[rid] {
VarValue::ErrorValue => false,
VarValue::Empty(_) => true,
VarValue::Value(min) => matches!(*min, ty::ReEmpty(_)),
VarValue::Value(_) => false,
},
_ => matches!(*min, ty::ReEmpty(_)),
_ => false,
},
VerifyBound::AnyBound(bs) => {

View file

@ -699,7 +699,6 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
ty::ReStatic | ty::ReErased | ty::ReFree(..) | ty::ReEarlyBound(..) => {
ty::UniverseIndex::ROOT
}
ty::ReEmpty(ui) => ui,
ty::RePlaceholder(placeholder) => placeholder.universe,
ty::ReVar(vid) => self.var_universe(vid),
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),

View file

@ -1978,7 +1978,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
ty::ReVar(_) | ty::ReErased => false,
ty::ReStatic | ty::ReEmpty(_) => true,
ty::ReStatic => true,
}
}
@ -2062,14 +2062,6 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
p!("'static");
return Ok(self);
}
ty::ReEmpty(ty::UniverseIndex::ROOT) => {
p!("'<empty>");
return Ok(self);
}
ty::ReEmpty(ui) => {
p!(write("'<empty:{:?}>", ui));
return Ok(self);
}
}
p!("'_");

View file

@ -1511,7 +1511,6 @@ impl<'tcx> Region<'tcx> {
ty::ReStatic => true,
ty::ReVar(..) => false,
ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
ty::ReEmpty(_) => false,
ty::ReErased => false,
}
}
@ -1536,11 +1535,6 @@ impl<'tcx> Region<'tcx> {
matches!(*self, ty::RePlaceholder(..))
}
#[inline]
pub fn is_empty(self) -> bool {
matches!(*self, ty::ReEmpty(..))
}
#[inline]
pub fn bound_at_or_above_binder(self, index: ty::DebruijnIndex) -> bool {
match *self {
@ -1572,7 +1566,7 @@ impl<'tcx> Region<'tcx> {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
}
ty::ReEmpty(_) | ty::ReStatic => {
ty::ReStatic => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
}
ty::ReLateBound(..) => {

View file

@ -305,8 +305,7 @@ fn encode_region<'tcx>(
| RegionKind::ReFree(..)
| RegionKind::ReStatic
| RegionKind::ReVar(..)
| RegionKind::RePlaceholder(..)
| RegionKind::ReEmpty(..) => {
| RegionKind::RePlaceholder(..) => {
bug!("encode_region: unexpected `{:?}`", region.kind());
}
}

View file

@ -485,10 +485,6 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
})
.intern(interner)
}
ty::ReEmpty(ui) => {
chalk_ir::LifetimeData::Empty(chalk_ir::UniverseIndex { counter: ui.index() })
.intern(interner)
}
ty::ReErased => chalk_ir::LifetimeData::Erased.intern(interner),
}
}
@ -510,8 +506,8 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
name: ty::BoundRegionKind::BrAnon(p.idx as u32),
}),
chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static,
chalk_ir::LifetimeData::Empty(ui) => {
ty::ReEmpty(ty::UniverseIndex::from_usize(ui.counter))
chalk_ir::LifetimeData::Empty(_) => {
bug!("Chalk should not have been passed an empty lifetime.")
}
chalk_ir::LifetimeData::Erased => return interner.tcx.lifetimes.re_erased,
chalk_ir::LifetimeData::Phantom(void, _) => match *void {},

View file

@ -3,14 +3,14 @@
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
use std::{fmt, hash};
use crate::DebruijnIndex;
use crate::FloatTy;
use crate::HashStableContext;
use crate::IntTy;
use crate::Interner;
use crate::TyDecoder;
use crate::TyEncoder;
use crate::UintTy;
use crate::UniverseIndex;
use crate::{DebruijnIndex, HashStableContext};
use self::RegionKind::*;
use self::TyKind::*;
@ -1023,14 +1023,6 @@ pub enum RegionKind<I: Interner> {
/// Should not exist outside of type inference.
RePlaceholder(I::PlaceholderRegion),
/// Empty lifetime is for data that is never accessed. We tag the
/// empty lifetime with a universe -- the idea is that we don't
/// want `exists<'a> { forall<'b> { 'b: 'a } }` to be satisfiable.
/// Therefore, the `'empty` in a universe `U` is less than all
/// regions visible from `U`, but not less than regions not visible
/// from `U`.
ReEmpty(UniverseIndex),
/// Erased region, used by trait selection, in MIR and during codegen.
ReErased,
}
@ -1046,8 +1038,7 @@ const fn regionkind_discriminant<I: Interner>(value: &RegionKind<I>) -> usize {
ReStatic => 3,
ReVar(_) => 4,
RePlaceholder(_) => 5,
ReEmpty(_) => 6,
ReErased => 7,
ReErased => 6,
}
}
@ -1072,7 +1063,6 @@ impl<I: Interner> Clone for RegionKind<I> {
ReStatic => ReStatic,
ReVar(a) => ReVar(a.clone()),
RePlaceholder(a) => RePlaceholder(a.clone()),
ReEmpty(a) => ReEmpty(a.clone()),
ReErased => ReErased,
}
}
@ -1099,7 +1089,6 @@ impl<I: Interner> PartialEq for RegionKind<I> {
(&RePlaceholder(ref __self_0), &RePlaceholder(ref __arg_1_0)) => {
__self_0 == __arg_1_0
}
(&ReEmpty(ref __self_0), &ReEmpty(ref __arg_1_0)) => __self_0 == __arg_1_0,
(&ReErased, &ReErased) => true,
_ => true,
}
@ -1144,7 +1133,6 @@ impl<I: Interner> Ord for RegionKind<I> {
(&RePlaceholder(ref __self_0), &RePlaceholder(ref __arg_1_0)) => {
Ord::cmp(__self_0, __arg_1_0)
}
(&ReEmpty(ref __self_0), &ReEmpty(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
(&ReErased, &ReErased) => Ordering::Equal,
_ => Ordering::Equal,
}
@ -1182,10 +1170,6 @@ impl<I: Interner> hash::Hash for RegionKind<I> {
hash::Hash::hash(&regionkind_discriminant(self), state);
hash::Hash::hash(__self_0, state)
}
(&ReEmpty(ref __self_0),) => {
hash::Hash::hash(&regionkind_discriminant(self), state);
hash::Hash::hash(__self_0, state)
}
(&ReErased,) => {
hash::Hash::hash(&regionkind_discriminant(self), state);
}
@ -1211,8 +1195,6 @@ impl<I: Interner> fmt::Debug for RegionKind<I> {
RePlaceholder(placeholder) => write!(f, "RePlaceholder({:?})", placeholder),
ReEmpty(ui) => write!(f, "ReEmpty({:?})", ui),
ReErased => write!(f, "ReErased"),
}
}
@ -1247,9 +1229,6 @@ where
RePlaceholder(a) => e.emit_enum_variant(disc, |e| {
a.encode(e);
}),
ReEmpty(a) => e.emit_enum_variant(disc, |e| {
a.encode(e);
}),
ReErased => e.emit_enum_variant(disc, |_| {}),
}
}
@ -1272,8 +1251,7 @@ where
3 => ReStatic,
4 => ReVar(Decodable::decode(d)),
5 => RePlaceholder(Decodable::decode(d)),
6 => ReEmpty(Decodable::decode(d)),
7 => ReErased,
6 => ReErased,
_ => panic!(
"{}",
format!(
@ -1305,9 +1283,6 @@ where
ReErased | ReStatic => {
// No variant fields to hash for these ...
}
ReEmpty(universe) => {
universe.hash_stable(hcx, hasher);
}
ReLateBound(db, br) => {
db.hash_stable(hcx, hasher);
br.hash_stable(hcx, hasher);

View file

@ -161,12 +161,6 @@ fn is_free_region(region: Region<'_>) -> bool {
// ignore it. We can't put it on the struct header anyway.
ty::ReLateBound(..) => false,
// This can appear in `where Self: ` bounds (#64855):
//
// struct Bar<T>(<Self as Foo>::Type) where Self: ;
// struct Baz<'a>(&'a Self) where Self: ;
ty::ReEmpty(_) => false,
// These regions don't appear in types from type declarations:
ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => {
bug!("unexpected region in outlives inference: {:?}", region);

View file

@ -411,11 +411,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
// way early-bound regions do, so we skip them here.
}
ty::ReFree(..)
| ty::ReVar(..)
| ty::RePlaceholder(..)
| ty::ReEmpty(_)
| ty::ReErased => {
ty::ReFree(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => {
// We don't expect to see anything but 'static or bound
// regions when visiting member types or method types.
bug!(