Return ImmTy in discriminant_for_variant.
This commit is contained in:
parent
1d6a32c920
commit
d278ce126c
@ -247,9 +247,9 @@ pub fn discriminant_for_variant(
|
|||||||
&self,
|
&self,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
variant: VariantIdx,
|
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))?;
|
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) => {
|
Some(discr) => {
|
||||||
// This type actually has discriminants.
|
// This type actually has discriminants.
|
||||||
assert_eq!(discr.ty, discr_layout.ty);
|
assert_eq!(discr.ty, discr_layout.ty);
|
||||||
@ -260,6 +260,7 @@ pub fn discriminant_for_variant(
|
|||||||
assert_eq!(variant.as_u32(), 0);
|
assert_eq!(variant.as_u32(), 0);
|
||||||
Scalar::from_uint(variant.as_u32(), discr_layout.size)
|
Scalar::from_uint(variant.as_u32(), discr_layout.size)
|
||||||
}
|
}
|
||||||
})
|
};
|
||||||
|
Ok(ImmTy::from_scalar(discr_value, discr_layout))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ pub fn emulate_intrinsic(
|
|||||||
sym::discriminant_value => {
|
sym::discriminant_value => {
|
||||||
let place = self.deref_pointer(&args[0])?;
|
let place = self.deref_pointer(&args[0])?;
|
||||||
let variant = self.read_discriminant(&place)?;
|
let variant = self.read_discriminant(&place)?;
|
||||||
let discr = self.discriminant_for_variant(place.layout, variant)?;
|
let discr = self.discriminant_for_variant(place.layout, variant)?.to_scalar();
|
||||||
self.write_scalar(discr, dest)?;
|
self.write_scalar(discr, dest)?;
|
||||||
}
|
}
|
||||||
sym::exact_div => {
|
sym::exact_div => {
|
||||||
|
@ -301,7 +301,7 @@ pub fn eval_rvalue_into_place(
|
|||||||
let op = self.eval_place_to_op(place, None)?;
|
let op = self.eval_place_to_op(place, None)?;
|
||||||
let variant = self.read_discriminant(&op)?;
|
let variant = self.read_discriminant(&op)?;
|
||||||
let discr = self.discriminant_for_variant(op.layout, variant)?;
|
let discr = self.discriminant_for_variant(op.layout, variant)?;
|
||||||
self.write_scalar(discr, &dest)?;
|
self.write_immediate(*discr, &dest)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,10 +405,8 @@ fn assign_constant(
|
|||||||
TrackElem::Variant(idx) => self.ecx.project_downcast(op, idx).ok(),
|
TrackElem::Variant(idx) => self.ecx.project_downcast(op, idx).ok(),
|
||||||
TrackElem::Discriminant => {
|
TrackElem::Discriminant => {
|
||||||
let variant = self.ecx.read_discriminant(op).ok()?;
|
let variant = self.ecx.read_discriminant(op).ok()?;
|
||||||
let scalar = self.ecx.discriminant_for_variant(op.layout, variant).ok()?;
|
let discr_value = self.ecx.discriminant_for_variant(op.layout, variant).ok()?;
|
||||||
let discr_ty = op.layout.ty.discriminant_ty(self.tcx);
|
Some(discr_value.into())
|
||||||
let layout = self.tcx.layout_of(self.param_env.and(discr_ty)).ok()?;
|
|
||||||
Some(ImmTy::from_scalar(scalar, layout).into())
|
|
||||||
}
|
}
|
||||||
TrackElem::DerefLen => {
|
TrackElem::DerefLen => {
|
||||||
let op: OpTy<'_> = self.ecx.deref_pointer(op).ok()?.into();
|
let op: OpTy<'_> = self.ecx.deref_pointer(op).ok()?.into();
|
||||||
@ -505,10 +503,9 @@ fn eval_discriminant(&self, enum_ty: Ty<'tcx>, variant_index: VariantIdx) -> Opt
|
|||||||
if !enum_ty.is_enum() {
|
if !enum_ty.is_enum() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let discr = enum_ty.discriminant_for_variant(self.tcx, variant_index)?;
|
let enum_ty_layout = self.tcx.layout_of(self.param_env.and(enum_ty)).ok()?;
|
||||||
let discr_layout = self.tcx.layout_of(self.param_env.and(discr.ty)).ok()?;
|
let discr_value = self.ecx.discriminant_for_variant(enum_ty_layout, variant_index).ok()?;
|
||||||
let discr_value = Scalar::try_from_uint(discr.val, discr_layout.size)?;
|
Some(discr_value.to_scalar())
|
||||||
Some(discr_value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrap_immediate(&self, imm: Immediate) -> FlatSet<Scalar> {
|
fn wrap_immediate(&self, imm: Immediate) -> FlatSet<Scalar> {
|
||||||
|
Loading…
Reference in New Issue
Block a user