Skip to content

Commit 0b7a793

Browse files
Rollup merge of #78463 - varkor:placeholder-const, r=nikomatsakis
Add type to `ConstKind::Placeholder` I simply threaded `<'tcx>` through everything that required it. I'm not sure whether this is the correct thing to do, but it seems to work. r? `@nikomatsakis`
2 parents ef32ef7 + e24a4b4 commit 0b7a793

File tree

8 files changed

+41
-31
lines changed

8 files changed

+41
-31
lines changed

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl CanonicalizeRegionMode for CanonicalizeFreeRegionsOtherThanStatic {
277277
struct Canonicalizer<'cx, 'tcx> {
278278
infcx: Option<&'cx InferCtxt<'cx, 'tcx>>,
279279
tcx: TyCtxt<'tcx>,
280-
variables: SmallVec<[CanonicalVarInfo; 8]>,
280+
variables: SmallVec<[CanonicalVarInfo<'tcx>; 8]>,
281281
query_state: &'cx mut OriginalQueryValues<'tcx>,
282282
// Note that indices is only used once `var_values` is big enough to be
283283
// heap-allocated.
@@ -542,7 +542,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
542542
/// or returns an existing variable if `kind` has already been
543543
/// seen. `kind` is expected to be an unbound variable (or
544544
/// potentially a free region).
545-
fn canonical_var(&mut self, info: CanonicalVarInfo, kind: GenericArg<'tcx>) -> BoundVar {
545+
fn canonical_var(&mut self, info: CanonicalVarInfo<'tcx>, kind: GenericArg<'tcx>) -> BoundVar {
546546
let Canonicalizer { variables, query_state, indices, .. } = self;
547547

548548
let var_values = &mut query_state.var_values;
@@ -621,7 +621,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
621621
/// representing the region `r`; return a region referencing it.
622622
fn canonical_var_for_region(
623623
&mut self,
624-
info: CanonicalVarInfo,
624+
info: CanonicalVarInfo<'tcx>,
625625
r: ty::Region<'tcx>,
626626
) -> ty::Region<'tcx> {
627627
let var = self.canonical_var(info, r.into());
@@ -633,7 +633,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
633633
/// if `ty_var` is bound to anything; if so, canonicalize
634634
/// *that*. Otherwise, create a new canonical variable for
635635
/// `ty_var`.
636-
fn canonicalize_ty_var(&mut self, info: CanonicalVarInfo, ty_var: Ty<'tcx>) -> Ty<'tcx> {
636+
fn canonicalize_ty_var(&mut self, info: CanonicalVarInfo<'tcx>, ty_var: Ty<'tcx>) -> Ty<'tcx> {
637637
let infcx = self.infcx.expect("encountered ty-var without infcx");
638638
let bound_to = infcx.shallow_resolve(ty_var);
639639
if bound_to != ty_var {
@@ -650,7 +650,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
650650
/// `const_var`.
651651
fn canonicalize_const_var(
652652
&mut self,
653-
info: CanonicalVarInfo,
653+
info: CanonicalVarInfo<'tcx>,
654654
const_var: &'tcx ty::Const<'tcx>,
655655
) -> &'tcx ty::Const<'tcx> {
656656
let infcx = self.infcx.expect("encountered const-var without infcx");

compiler/rustc_infer/src/infer/canonical/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
8282
fn instantiate_canonical_vars(
8383
&self,
8484
span: Span,
85-
variables: &List<CanonicalVarInfo>,
85+
variables: &List<CanonicalVarInfo<'tcx>>,
8686
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
8787
) -> CanonicalVarValues<'tcx> {
8888
let var_values: IndexVec<BoundVar, GenericArg<'tcx>> = variables
@@ -100,7 +100,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
100100
fn instantiate_canonical_var(
101101
&self,
102102
span: Span,
103-
cv_info: CanonicalVarInfo,
103+
cv_info: CanonicalVarInfo<'tcx>,
104104
universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
105105
) -> GenericArg<'tcx> {
106106
match cv_info.kind {
@@ -154,7 +154,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
154154
self.tcx
155155
.mk_const(ty::Const {
156156
val: ty::ConstKind::Placeholder(placeholder_mapped),
157-
ty: self.tcx.ty_error(), // FIXME(const_generics)
157+
ty: name.ty,
158158
})
159159
.into()
160160
}

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
9595
self.tcx.mk_const(ty::Const {
9696
val: ty::ConstKind::Placeholder(ty::PlaceholderConst {
9797
universe: next_universe,
98-
name: bound_var,
98+
name: ty::BoundConst { var: bound_var, ty },
9999
}),
100100
ty,
101101
})

compiler/rustc_middle/src/infer/canonical.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct Canonical<'tcx, V> {
4040
pub value: V,
4141
}
4242

43-
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo>;
43+
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
4444

4545
/// A set of values corresponding to the canonical variables from some
4646
/// `Canonical`. You can give these values to
@@ -88,11 +88,11 @@ impl Default for OriginalQueryValues<'tcx> {
8888
/// a copy of the canonical value in some other inference context,
8989
/// with fresh inference variables replacing the canonical values.
9090
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
91-
pub struct CanonicalVarInfo {
92-
pub kind: CanonicalVarKind,
91+
pub struct CanonicalVarInfo<'tcx> {
92+
pub kind: CanonicalVarKind<'tcx>,
9393
}
9494

95-
impl CanonicalVarInfo {
95+
impl<'tcx> CanonicalVarInfo<'tcx> {
9696
pub fn universe(&self) -> ty::UniverseIndex {
9797
self.kind.universe()
9898
}
@@ -113,7 +113,7 @@ impl CanonicalVarInfo {
113113
/// in the type-theory sense of the term -- i.e., a "meta" type system
114114
/// that analyzes type-like values.
115115
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyDecodable, TyEncodable, HashStable)]
116-
pub enum CanonicalVarKind {
116+
pub enum CanonicalVarKind<'tcx> {
117117
/// Some kind of type inference variable.
118118
Ty(CanonicalTyVarKind),
119119

@@ -132,10 +132,10 @@ pub enum CanonicalVarKind {
132132
Const(ty::UniverseIndex),
133133

134134
/// A "placeholder" that represents "any const".
135-
PlaceholderConst(ty::PlaceholderConst),
135+
PlaceholderConst(ty::PlaceholderConst<'tcx>),
136136
}
137137

138-
impl CanonicalVarKind {
138+
impl<'tcx> CanonicalVarKind<'tcx> {
139139
pub fn universe(self) -> ty::UniverseIndex {
140140
match self {
141141
CanonicalVarKind::Ty(kind) => match kind {
@@ -287,9 +287,11 @@ pub type QueryOutlivesConstraint<'tcx> =
287287
ty::Binder<ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;
288288

289289
CloneTypeFoldableAndLiftImpls! {
290-
crate::infer::canonical::Certainty,
291-
crate::infer::canonical::CanonicalVarInfo,
292-
crate::infer::canonical::CanonicalVarKind,
290+
for <'tcx> {
291+
crate::infer::canonical::Certainty,
292+
crate::infer::canonical::CanonicalVarInfo<'tcx>,
293+
crate::infer::canonical::CanonicalVarKind<'tcx>,
294+
}
293295
}
294296

295297
CloneTypeFoldableImpls! {

compiler/rustc_middle/src/ty/codec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Region<'tcx> {
278278
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for CanonicalVarInfos<'tcx> {
279279
fn decode(decoder: &mut D) -> Result<Self, D::Error> {
280280
let len = decoder.read_usize()?;
281-
let interned: Result<Vec<CanonicalVarInfo>, _> =
281+
let interned: Result<Vec<CanonicalVarInfo<'tcx>>, _> =
282282
(0..len).map(|_| Decodable::decode(decoder)).collect();
283283
Ok(decoder.tcx().intern_canonical_var_infos(interned?.as_slice()))
284284
}

compiler/rustc_middle/src/ty/consts/kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum ConstKind<'tcx> {
2323
Bound(ty::DebruijnIndex, ty::BoundVar),
2424

2525
/// A placeholder const - universally quantified higher-ranked const.
26-
Placeholder(ty::PlaceholderConst),
26+
Placeholder(ty::PlaceholderConst<'tcx>),
2727

2828
/// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other
2929
/// variants when the code is monomorphic enough for that.

compiler/rustc_middle/src/ty/context.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub struct CtxtInterners<'tcx> {
8383
type_: InternedSet<'tcx, TyS<'tcx>>,
8484
type_list: InternedSet<'tcx, List<Ty<'tcx>>>,
8585
substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
86-
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo>>,
86+
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
8787
region: InternedSet<'tcx, RegionKind>,
8888
existential_predicates: InternedSet<'tcx, List<ExistentialPredicate<'tcx>>>,
8989
predicate: InternedSet<'tcx, PredicateInner<'tcx>>,
@@ -1613,7 +1613,7 @@ nop_lift! {predicate; &'a PredicateInner<'a> => &'tcx PredicateInner<'tcx>}
16131613
nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
16141614
nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
16151615
nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>}
1616-
nop_list_lift! {canonical_var_infos; CanonicalVarInfo => CanonicalVarInfo}
1616+
nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>}
16171617
nop_list_lift! {projs; ProjectionKind => ProjectionKind}
16181618

16191619
// This is the impl for `&'a InternalSubsts<'a>`.
@@ -2049,7 +2049,7 @@ macro_rules! slice_interners {
20492049
slice_interners!(
20502050
type_list: _intern_type_list(Ty<'tcx>),
20512051
substs: _intern_substs(GenericArg<'tcx>),
2052-
canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo),
2052+
canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo<'tcx>),
20532053
existential_predicates: _intern_existential_predicates(ExistentialPredicate<'tcx>),
20542054
predicates: _intern_predicates(Predicate<'tcx>),
20552055
projs: _intern_projs(ProjectionKind),
@@ -2448,7 +2448,10 @@ impl<'tcx> TyCtxt<'tcx> {
24482448
if ts.is_empty() { List::empty() } else { self._intern_place_elems(ts) }
24492449
}
24502450

2451-
pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVarInfos<'tcx> {
2451+
pub fn intern_canonical_var_infos(
2452+
self,
2453+
ts: &[CanonicalVarInfo<'tcx>],
2454+
) -> CanonicalVarInfos<'tcx> {
24522455
if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) }
24532456
}
24542457

compiler/rustc_middle/src/ty/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1580,11 +1580,9 @@ impl UniverseIndex {
15801580
}
15811581
}
15821582

1583-
/// The "placeholder index" fully defines a placeholder region.
1584-
/// Placeholder regions are identified by both a **universe** as well
1585-
/// as a "bound-region" within that universe. The `bound_region` is
1586-
/// basically a name -- distinct bound regions within the same
1587-
/// universe are just two regions with an unknown relationship to one
1583+
/// The "placeholder index" fully defines a placeholder region, type, or const. Placeholders are
1584+
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
1585+
/// regions/types/consts within the same universe simply have an unknown relationship to one
15881586
/// another.
15891587
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
15901588
pub struct Placeholder<T> {
@@ -1606,7 +1604,14 @@ pub type PlaceholderRegion = Placeholder<BoundRegion>;
16061604

16071605
pub type PlaceholderType = Placeholder<BoundVar>;
16081606

1609-
pub type PlaceholderConst = Placeholder<BoundVar>;
1607+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
1608+
#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)]
1609+
pub struct BoundConst<'tcx> {
1610+
pub var: BoundVar,
1611+
pub ty: Ty<'tcx>,
1612+
}
1613+
1614+
pub type PlaceholderConst<'tcx> = Placeholder<BoundConst<'tcx>>;
16101615

16111616
/// A `DefId` which is potentially bundled with its corresponding generic parameter
16121617
/// in case `did` is a const argument.

0 commit comments

Comments
 (0)