simplify valtree branches construction
This commit is contained in:
parent
885e0f1b96
commit
b722d5da1d
1 changed files with 12 additions and 15 deletions
|
@ -21,7 +21,7 @@ use crate::interpret::{
|
||||||
fn branches<'tcx>(
|
fn branches<'tcx>(
|
||||||
ecx: &CompileTimeInterpCx<'tcx>,
|
ecx: &CompileTimeInterpCx<'tcx>,
|
||||||
place: &MPlaceTy<'tcx>,
|
place: &MPlaceTy<'tcx>,
|
||||||
n: usize,
|
field_count: usize,
|
||||||
variant: Option<VariantIdx>,
|
variant: Option<VariantIdx>,
|
||||||
num_nodes: &mut usize,
|
num_nodes: &mut usize,
|
||||||
) -> ValTreeCreationResult<'tcx> {
|
) -> ValTreeCreationResult<'tcx> {
|
||||||
|
@ -29,24 +29,21 @@ fn branches<'tcx>(
|
||||||
Some(variant) => ecx.project_downcast(place, variant).unwrap(),
|
Some(variant) => ecx.project_downcast(place, variant).unwrap(),
|
||||||
None => place.clone(),
|
None => place.clone(),
|
||||||
};
|
};
|
||||||
let variant = variant
|
debug!(?place);
|
||||||
.map(|variant| Some(ty::ValTree::from_scalar_int(*ecx.tcx, variant.as_u32().into())));
|
|
||||||
debug!(?place, ?variant);
|
|
||||||
|
|
||||||
let mut fields = Vec::with_capacity(n);
|
let mut branches = Vec::with_capacity(field_count + variant.is_some() as usize);
|
||||||
for i in 0..n {
|
|
||||||
let field = ecx.project_field(&place, i).unwrap();
|
|
||||||
let valtree = const_to_valtree_inner(ecx, &field, num_nodes)?;
|
|
||||||
fields.push(Some(valtree));
|
|
||||||
}
|
|
||||||
|
|
||||||
// For enums, we prepend their variant index before the variant's fields so we can figure out
|
// For enums, we prepend their variant index before the variant's fields so we can figure out
|
||||||
// the variant again when just seeing a valtree.
|
// the variant again when just seeing a valtree.
|
||||||
let branches = variant
|
if let Some(variant) = variant {
|
||||||
.into_iter()
|
branches.push(ty::ValTree::from_scalar_int(*ecx.tcx, variant.as_u32().into()));
|
||||||
.chain(fields.into_iter())
|
}
|
||||||
.collect::<Option<Vec<_>>>()
|
|
||||||
.expect("should have already checked for errors in ValTree creation");
|
for i in 0..field_count {
|
||||||
|
let field = ecx.project_field(&place, i).unwrap();
|
||||||
|
let valtree = const_to_valtree_inner(ecx, &field, num_nodes)?;
|
||||||
|
branches.push(valtree);
|
||||||
|
}
|
||||||
|
|
||||||
// Have to account for ZSTs here
|
// Have to account for ZSTs here
|
||||||
if branches.len() == 0 {
|
if branches.len() == 0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue