Distinguish between placeholder kinds

This commit is contained in:
scalexm 2018-11-02 15:08:51 +01:00
parent 1f57e48411
commit 7401e3def5
12 changed files with 44 additions and 26 deletions

View File

@ -142,7 +142,7 @@ pub enum CanonicalVarKind {
/// A "placeholder" that represents "any region". Created when you
/// are solving a goal like `for<'a> T: Foo<'a>` to represent the
/// bound region `'a`.
PlaceholderRegion(ty::Placeholder),
PlaceholderRegion(ty::PlaceholderRegion),
}
impl CanonicalVarKind {
@ -374,9 +374,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
universe_map(ui),
).into(),
CanonicalVarKind::PlaceholderRegion(ty::Placeholder { universe, name }) => {
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, name }) => {
let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::Placeholder {
let placeholder_mapped = ty::PlaceholderRegion {
universe: universe_mapped,
name,
};

View File

@ -340,7 +340,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let next_universe = self.create_next_universe();
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
self.tcx.mk_region(ty::RePlaceholder(ty::Placeholder {
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
universe: next_universe,
name: br,
}))

View File

@ -411,7 +411,7 @@ pub enum NLLRegionVariableOrigin {
/// "Universal" instantiation of a higher-ranked region (e.g.,
/// from a `for<'a> T` binder). Meant to represent "any region".
Placeholder(ty::Placeholder),
Placeholder(ty::PlaceholderRegion),
Existential,
}

View File

@ -95,7 +95,7 @@ pub trait TypeRelatingDelegate<'tcx> {
/// So e.g. if you have `for<'a> fn(..) <: for<'b> fn(..)`, then
/// we will invoke this method to instantiate `'b` with a
/// placeholder region.
fn next_placeholder_region(&mut self, placeholder: ty::Placeholder) -> ty::Region<'tcx>;
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx>;
/// Creates a new existential region in the given universe. This
/// is used when handling subtyping and type variables -- if we
@ -176,7 +176,7 @@ where
universe
});
let placeholder = ty::Placeholder { universe, name: br };
let placeholder = ty::PlaceholderRegion { universe, name: br };
delegate.next_placeholder_region(placeholder)
} else {
delegate.next_existential_region_var()

View File

@ -1587,12 +1587,27 @@ impl UniverseIndex {
/// universe are just two regions with an unknown relationship to one
/// another.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
pub struct Placeholder {
pub struct Placeholder<T> {
pub universe: UniverseIndex,
pub name: BoundRegion,
pub name: T,
}
impl_stable_hash_for!(struct Placeholder { universe, name });
impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for Placeholder<T>
where T: HashStable<StableHashingContext<'a>>
{
fn hash_stable<W: StableHasherResult>(
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>
) {
self.universe.hash_stable(hcx, hasher);
self.name.hash_stable(hcx, hasher);
}
}
pub type PlaceholderRegion = Placeholder<BoundRegion>;
pub type PlaceholderType = Placeholder<BoundVar>;
/// When type checking, we use the `ParamEnv` to track
/// details about the set of where-clauses that are in scope at this

View File

@ -1165,7 +1165,7 @@ pub enum RegionKind {
/// A placeholder region - basically the higher-ranked version of ReFree.
/// Should not exist after typeck.
RePlaceholder(ty::Placeholder),
RePlaceholder(ty::PlaceholderRegion),
/// Empty lifetime is for data that is never accessed.
/// Bottom in the region lattice. We treat ReEmpty somewhat

View File

@ -792,7 +792,7 @@ define_print! {
}
ty::ReLateBound(_, br) |
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
ty::RePlaceholder(ty::PlaceholderRegion { name: br, .. }) => {
write!(f, "{}", br)
}
ty::ReScope(scope) if cx.identify_regions => {

View File

@ -2193,7 +2193,7 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
match ty.sty {
ty::TyKind::Ref(ty::RegionKind::ReLateBound(_, br), _, _)
| ty::TyKind::Ref(
ty::RegionKind::RePlaceholder(ty::Placeholder { name: br, .. }),
ty::RegionKind::RePlaceholder(ty::PlaceholderRegion { name: br, .. }),
_,
_,
) => with_highlight_region_for_bound_region(*br, counter, || ty.to_string()),
@ -2207,7 +2207,7 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
match ty.sty {
ty::TyKind::Ref(region, _, _) => match region {
ty::RegionKind::ReLateBound(_, br)
| ty::RegionKind::RePlaceholder(ty::Placeholder { name: br, .. }) => {
| ty::RegionKind::RePlaceholder(ty::PlaceholderRegion { name: br, .. }) => {
with_highlight_region_for_bound_region(*br, counter, || region.to_string())
}
_ => region.to_string(),

View File

@ -1230,7 +1230,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
mir: &Mir<'tcx>,
_mir_def_id: DefId,
longer_fr: RegionVid,
placeholder: ty::Placeholder,
placeholder: ty::PlaceholderRegion,
) {
debug!(
"check_bound_universal_region(fr={:?}, placeholder={:?})",

View File

@ -150,7 +150,7 @@ crate enum RegionElement {
/// A placeholder (e.g., instantiated from a `for<'a> fn(&'a u32)`
/// type).
PlaceholderRegion(ty::Placeholder),
PlaceholderRegion(ty::PlaceholderRegion),
}
/// When we initially compute liveness, we use a bit matrix storing
@ -219,17 +219,17 @@ impl<N: Idx> LivenessValues<N> {
}
}
/// Maps from `ty::Placeholder` values that are used in the rest of
/// Maps from `ty::PlaceholderRegion` values that are used in the rest of
/// rustc to the internal `PlaceholderIndex` values that are used in
/// NLL.
#[derive(Default)]
crate struct PlaceholderIndices {
to_index: FxHashMap<ty::Placeholder, PlaceholderIndex>,
from_index: IndexVec<PlaceholderIndex, ty::Placeholder>,
to_index: FxHashMap<ty::PlaceholderRegion, PlaceholderIndex>,
from_index: IndexVec<PlaceholderIndex, ty::PlaceholderRegion>,
}
impl PlaceholderIndices {
crate fn insert(&mut self, placeholder: ty::Placeholder) -> PlaceholderIndex {
crate fn insert(&mut self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
let PlaceholderIndices {
to_index,
from_index,
@ -239,11 +239,11 @@ impl PlaceholderIndices {
.or_insert_with(|| from_index.push(placeholder))
}
crate fn lookup_index(&self, placeholder: ty::Placeholder) -> PlaceholderIndex {
crate fn lookup_index(&self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
self.to_index[&placeholder]
}
crate fn lookup_placeholder(&self, placeholder: PlaceholderIndex) -> ty::Placeholder {
crate fn lookup_placeholder(&self, placeholder: PlaceholderIndex) -> ty::PlaceholderRegion {
self.from_index[placeholder]
}
@ -375,7 +375,7 @@ impl<N: Idx> RegionValues<N> {
crate fn placeholders_contained_in<'a>(
&'a self,
r: N,
) -> impl Iterator<Item = ty::Placeholder> + 'a {
) -> impl Iterator<Item = ty::PlaceholderRegion> + 'a {
self.placeholders
.row(r)
.into_iter()
@ -432,7 +432,7 @@ impl ToElementIndex for RegionVid {
}
}
impl ToElementIndex for ty::Placeholder {
impl ToElementIndex for ty::PlaceholderRegion {
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
let index = values.placeholder_indices.lookup_index(self);
values.placeholders.insert(row, index)

View File

@ -777,7 +777,7 @@ impl MirTypeckRegionConstraints<'tcx> {
fn placeholder_region(
&mut self,
infcx: &InferCtxt<'_, '_, 'tcx>,
placeholder: ty::Placeholder,
placeholder: ty::PlaceholderRegion,
) -> ty::Region<'tcx> {
let placeholder_index = self.placeholder_indices.insert(placeholder);
match self.placeholder_index_to_region.get(placeholder_index) {

View File

@ -84,7 +84,10 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, '_, 'tcx> {
}
}
fn next_placeholder_region(&mut self, placeholder: ty::Placeholder) -> ty::Region<'tcx> {
fn next_placeholder_region(
&mut self,
placeholder: ty::PlaceholderRegion
) -> ty::Region<'tcx> {
if let Some(borrowck_context) = &mut self.borrowck_context {
borrowck_context.constraints.placeholder_region(self.infcx, placeholder)
} else {