/// return `None` if that is not possible.
query const_to_valtree(
key: ty::ParamEnvAnd<'tcx, ConstAlloc<'tcx>>
- ) -> Option<ty::ValTree> {
+ ) -> Option<ty::ValTree<'tcx>> {
desc { "destructure constant" }
}
}
}
+impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [ty::ValTree<'tcx>] {
+ fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
+ Ok(decoder.tcx().arena.alloc_from_iter(
+ (0..decoder.read_usize()?)
+ .map(|_| Decodable::decode(decoder))
+ .collect::<Result<Vec<_>, _>>()?,
+ ))
+ }
+}
+
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for Allocation {
fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
Ok(decoder.tcx().intern_const_alloc(Decodable::decode(decoder)?))
use super::ScalarInt;
use rustc_macros::HashStable;
-#[derive(Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)]
+#[derive(Copy, Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)]
#[derive(HashStable)]
-pub enum ValTree {
+pub enum ValTree<'tcx> {
Leaf(ScalarInt),
- Branch(Vec<ValTree>),
+ Branch(&'tcx [ValTree<'tcx>]),
}
-impl ValTree {
+impl ValTree<'tcx> {
pub fn zst() -> Self {
- Self::Branch(Vec::new())
+ Self::Branch(&[])
}
}
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
raw: ConstAlloc<'tcx>,
-) -> Option<ty::ValTree> {
+) -> Option<ty::ValTree<'tcx>> {
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
let place = ecx.raw_const_to_mplace(raw).unwrap();
const_to_valtree_inner(&ecx, &place)
fn const_to_valtree_inner<'tcx>(
ecx: &CompileTimeEvalContext<'tcx, 'tcx>,
place: &MPlaceTy<'tcx>,
-) -> Option<ty::ValTree> {
+) -> Option<ty::ValTree<'tcx>> {
let branches = |n, variant| {
let place = match variant {
Some(variant) => ecx.mplace_downcast(&place, variant).unwrap(),
let field = ecx.mplace_field(&place, i).unwrap();
const_to_valtree_inner(ecx, &field)
});
- Some(ty::ValTree::Branch(variant.into_iter().chain(fields).collect::<Option<_>>()?))
+ Some(ty::ValTree::Branch(
+ ecx.tcx
+ .arena
+ .alloc_from_iter(variant.into_iter().chain(fields).collect::<Option<Vec<_>>>()?),
+ ))
};
match place.layout.ty.kind() {
ty::FnDef(..) => Some(ty::ValTree::zst()),