Introduce write_aggregate.
This commit is contained in:
parent
83173c68f5
commit
473d0c5510
@ -846,6 +846,34 @@ pub fn write_discriminant(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Writes the discriminant of the given variant.
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn write_aggregate(
|
||||
&mut self,
|
||||
kind: &mir::AggregateKind<'tcx>,
|
||||
operands: &[mir::Operand<'tcx>],
|
||||
dest: &PlaceTy<'tcx, M::Provenance>,
|
||||
) -> InterpResult<'tcx> {
|
||||
self.write_uninit(&dest)?;
|
||||
let (variant_index, variant_dest, active_field_index) = match *kind {
|
||||
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
|
||||
let variant_dest = self.place_downcast(&dest, variant_index)?;
|
||||
(variant_index, variant_dest, active_field_index)
|
||||
}
|
||||
_ => (VariantIdx::from_u32(0), dest.clone(), None),
|
||||
};
|
||||
if active_field_index.is_some() {
|
||||
assert_eq!(operands.len(), 1);
|
||||
}
|
||||
for (field_index, operand) in operands.iter().enumerate() {
|
||||
let field_index = active_field_index.unwrap_or(field_index);
|
||||
let field_dest = self.place_field(&variant_dest, field_index)?;
|
||||
let op = self.eval_operand(operand, Some(field_dest.layout))?;
|
||||
self.copy_op(&op, &field_dest, /*allow_transmute*/ false)?;
|
||||
}
|
||||
self.write_discriminant(variant_index, &dest)
|
||||
}
|
||||
|
||||
pub fn raw_const_to_mplace(
|
||||
&self,
|
||||
raw: ConstAlloc<'tcx>,
|
||||
|
@ -7,7 +7,6 @@
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::{InterpResult, Scalar};
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
||||
use super::{ImmTy, InterpCx, Machine};
|
||||
|
||||
@ -200,24 +199,7 @@ pub fn eval_rvalue_into_place(
|
||||
}
|
||||
|
||||
Aggregate(box ref kind, ref operands) => {
|
||||
self.write_uninit(&dest)?;
|
||||
let (variant_index, variant_dest, active_field_index) = match *kind {
|
||||
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
|
||||
let variant_dest = self.place_downcast(&dest, variant_index)?;
|
||||
(variant_index, variant_dest, active_field_index)
|
||||
}
|
||||
_ => (VariantIdx::from_u32(0), dest.clone(), None),
|
||||
};
|
||||
if active_field_index.is_some() {
|
||||
assert_eq!(operands.len(), 1);
|
||||
}
|
||||
for (field_index, operand) in operands.iter().enumerate() {
|
||||
let field_index = active_field_index.unwrap_or(field_index);
|
||||
let field_dest = self.place_field(&variant_dest, field_index)?;
|
||||
let op = self.eval_operand(operand, Some(field_dest.layout))?;
|
||||
self.copy_op(&op, &field_dest, /*allow_transmute*/ false)?;
|
||||
}
|
||||
self.write_discriminant(variant_index, &dest)?;
|
||||
self.write_aggregate(kind, operands, &dest)?;
|
||||
}
|
||||
|
||||
Repeat(ref operand, _) => {
|
||||
|
Loading…
Reference in New Issue
Block a user