Auto merge of #115705 - cjgillot:const-prop-aggregate, r=oli-obk
Read from non-scalar constants and statics in dataflow const-prop DataflowConstProp is designed to handle scalar values. When MIR features an assignment from a non-scalar constant, we need to manually decompose it into the custom state space. This PR tweaks interpreter callbacks to allow reusing `eval_mir_constant` without having a stack frame to get a span from. r? `@oli-obk` cc `@jachris`
This commit is contained in:
commit
cc7a9d6972
26 changed files with 1072 additions and 144 deletions
|
@ -247,9 +247,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
&self,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
variant: VariantIdx,
|
||||
) -> InterpResult<'tcx, Scalar<M::Provenance>> {
|
||||
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
|
||||
let discr_layout = self.layout_of(layout.ty.discriminant_ty(*self.tcx))?;
|
||||
Ok(match layout.ty.discriminant_for_variant(*self.tcx, variant) {
|
||||
let discr_value = match layout.ty.discriminant_for_variant(*self.tcx, variant) {
|
||||
Some(discr) => {
|
||||
// This type actually has discriminants.
|
||||
assert_eq!(discr.ty, discr_layout.ty);
|
||||
|
@ -260,6 +260,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
assert_eq!(variant.as_u32(), 0);
|
||||
Scalar::from_uint(variant.as_u32(), discr_layout.size)
|
||||
}
|
||||
})
|
||||
};
|
||||
Ok(ImmTy::from_scalar(discr_value, discr_layout))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let place = self.deref_pointer(&args[0])?;
|
||||
let variant = self.read_discriminant(&place)?;
|
||||
let discr = self.discriminant_for_variant(place.layout, variant)?;
|
||||
self.write_scalar(discr, dest)?;
|
||||
self.write_immediate(*discr, dest)?;
|
||||
}
|
||||
sym::exact_div => {
|
||||
let l = self.read_immediate(&args[0])?;
|
||||
|
|
|
@ -301,7 +301,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let op = self.eval_place_to_op(place, None)?;
|
||||
let variant = self.read_discriminant(&op)?;
|
||||
let discr = self.discriminant_for_variant(op.layout, variant)?;
|
||||
self.write_scalar(discr, &dest)?;
|
||||
self.write_immediate(*discr, &dest)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue