Skip to content

Commit 06f4950

Browse files
committed
Auto merge of #100032 - BoxyUwU:no_ty_in_placeholder_const, r=compiler-errors
make `PlaceholderConst` not store the type of the const Currently the `Placeholder` variant on `ConstKind` is 28 bytes when with this PR its 8 bytes, i am not sure this is really useful at all rn since `Unevaluated` and `Value` variants are huge still but eventually it should be possible to get both down to 16 bytes 🤔. Mostly opening this to see if this change has any perf impact when done before it can make `ConstKind`/`ConstS` smaller
2 parents 792bc5a + 49d001c commit 06f4950

File tree

8 files changed

+21
-19
lines changed

8 files changed

+21
-19
lines changed

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
511511
}
512512
ty::ConstKind::Placeholder(placeholder) => {
513513
return self.canonicalize_const_var(
514-
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderConst(placeholder) },
514+
CanonicalVarInfo {
515+
kind: CanonicalVarKind::PlaceholderConst(placeholder, ct.ty()),
516+
},
515517
ct,
516518
);
517519
}
@@ -695,11 +697,14 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
695697
..placeholder
696698
})
697699
}
698-
CanonicalVarKind::PlaceholderConst(placeholder) => {
699-
CanonicalVarKind::PlaceholderConst(ty::Placeholder {
700-
universe: reverse_universe_map[&placeholder.universe],
701-
..placeholder
702-
})
700+
CanonicalVarKind::PlaceholderConst(placeholder, t) => {
701+
CanonicalVarKind::PlaceholderConst(
702+
ty::Placeholder {
703+
universe: reverse_universe_map[&placeholder.universe],
704+
..placeholder
705+
},
706+
t,
707+
)
703708
}
704709
},
705710
})

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
144144
)
145145
.into(),
146146

147-
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }) => {
147+
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => {
148148
let universe_mapped = universe_map(universe);
149149
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
150150
self.tcx
151151
.mk_const(ty::ConstS {
152152
kind: ty::ConstKind::Placeholder(placeholder_mapped),
153-
ty: name.ty,
153+
ty,
154154
})
155155
.into()
156156
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
9797
self.tcx.mk_const(ty::ConstS {
9898
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
9999
universe: next_universe,
100-
name: ty::BoundConst { var: bound_var, ty },
100+
name: bound_var,
101101
}),
102102
ty,
103103
})

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
20672067
ty,
20682068
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
20692069
universe: ty::UniverseIndex::ROOT,
2070-
name: ty::BoundConst { ty, var: ty::BoundVar::from_usize(idx) },
2070+
name: ty::BoundVar::from_usize(idx),
20712071
}),
20722072
})
20732073
.into()

compiler/rustc_middle/src/infer/canonical.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'tcx> CanonicalVarInfo<'tcx> {
105105
CanonicalVarKind::Region(_) => true,
106106
CanonicalVarKind::PlaceholderRegion(..) => false,
107107
CanonicalVarKind::Const(..) => true,
108-
CanonicalVarKind::PlaceholderConst(_) => false,
108+
CanonicalVarKind::PlaceholderConst(_, _) => false,
109109
}
110110
}
111111
}
@@ -133,7 +133,7 @@ pub enum CanonicalVarKind<'tcx> {
133133
Const(ty::UniverseIndex, Ty<'tcx>),
134134

135135
/// A "placeholder" that represents "any const".
136-
PlaceholderConst(ty::PlaceholderConst<'tcx>),
136+
PlaceholderConst(ty::PlaceholderConst<'tcx>, Ty<'tcx>),
137137
}
138138

139139
impl<'tcx> CanonicalVarKind<'tcx> {
@@ -148,7 +148,7 @@ impl<'tcx> CanonicalVarKind<'tcx> {
148148
CanonicalVarKind::Region(ui) => ui,
149149
CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.universe,
150150
CanonicalVarKind::Const(ui, _) => ui,
151-
CanonicalVarKind::PlaceholderConst(placeholder) => placeholder.universe,
151+
CanonicalVarKind::PlaceholderConst(placeholder, _) => placeholder.universe,
152152
}
153153
}
154154
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ pub struct BoundConst<'tcx> {
12001200
pub ty: Ty<'tcx>,
12011201
}
12021202

1203-
pub type PlaceholderConst<'tcx> = Placeholder<BoundConst<'tcx>>;
1203+
pub type PlaceholderConst<'tcx> = Placeholder<BoundVar>;
12041204

12051205
/// A `DefId` which, in case it is a const argument, is potentially bundled with
12061206
/// the `DefId` of the generic parameter it instantiates.

compiler/rustc_trait_selection/src/traits/project.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,7 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
744744
}
745745
ty::ConstKind::Bound(debruijn, bound_const) if debruijn >= self.current_index => {
746746
let universe = self.universe_for(debruijn);
747-
let p = ty::PlaceholderConst {
748-
universe,
749-
name: ty::BoundConst { var: bound_const, ty: ct.ty() },
750-
};
747+
let p = ty::PlaceholderConst { universe, name: bound_const };
751748
self.mapped_consts.insert(p, bound_const);
752749
self.infcx
753750
.tcx

compiler/rustc_traits/src/chalk/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(crate) fn evaluate_goal<'tcx>(
7676
chalk_ir::UniverseIndex { counter: ui.index() },
7777
),
7878
CanonicalVarKind::Const(_ui, _ty) => unimplemented!(),
79-
CanonicalVarKind::PlaceholderConst(_pc) => unimplemented!(),
79+
CanonicalVarKind::PlaceholderConst(_pc, _ty) => unimplemented!(),
8080
}),
8181
),
8282
value: obligation.value.lower_into(interner),

0 commit comments

Comments
 (0)