Immediate::ScalarPair(val.into(), Scalar::from_machine_usize(len, cx).into())
}
- pub fn new_dyn_trait(val: Scalar<Tag>, vtable: Pointer<Tag>, cx: &impl HasDataLayout) -> Self {
- Immediate::ScalarPair(val.into(), ScalarMaybeUninit::from_pointer(vtable, cx))
+ pub fn new_dyn_trait(
+ val: Scalar<Tag>,
+ vtable: Pointer<Option<Tag>>,
+ cx: &impl HasDataLayout,
+ ) -> Self {
+ Immediate::ScalarPair(val.into(), ScalarMaybeUninit::from_maybe_pointer(vtable, cx))
}
#[inline]
pub fn to_scalar_or_uninit(self) -> ScalarMaybeUninit<Tag> {
match self {
Immediate::Scalar(val) => val,
- Immediate::ScalarPair(..) => bug!("Got a wide pointer where a scalar was expected"),
+ Immediate::ScalarPair(..) => bug!("Got a scalar pair where a scalar was expected"),
}
}
pub fn to_scalar(self) -> InterpResult<'tcx, Scalar<Tag>> {
self.to_scalar_or_uninit().check_init()
}
+
+ #[inline]
+ pub fn to_scalar_pair(self) -> InterpResult<'tcx, (Scalar<Tag>, Scalar<Tag>)> {
+ match self {
+ Immediate::ScalarPair(val1, val2) => Ok((val1.check_init()?, val2.check_init()?)),
+ Immediate::Scalar(..) => {
+ bug!("Got a scalar where a scalar pair was expected")
+ }
+ }
+ }
}
// ScalarPair needs a type to interpret, so we often have an immediate and a type together
/// we can find the data.
/// Note that for a given layout, this operation will either always fail or always
/// succeed! Whether it succeeds depends on whether the layout can be represented
- /// in a `Immediate`, not on which data is stored there currently.
+ /// in an `Immediate`, not on which data is stored there currently.
pub(crate) fn try_read_immediate(
&self,
src: &OpTy<'tcx, M::PointerTag>,
Err(value) => value,
};
- let field_layout = op.layout.field(self, field)?;
+ let field_layout = op.layout.field(self, field);
if field_layout.is_zst() {
let immediate = Scalar::ZST.into();
return Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout });
match val.val {
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
ty::ConstKind::Error(_) => throw_inval!(AlreadyReported(ErrorReported)),
- ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => {
- let instance = self.resolve(def, substs)?;
- Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into())
+ ty::ConstKind::Unevaluated(uv) => {
+ let instance = self.resolve(uv.def, uv.substs(*self.tcx))?;
+ Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())
}
ty::ConstKind::Infer(..) | ty::ConstKind::Placeholder(..) => {
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", val)
let ptr = self.global_base_pointer(Pointer::new(id, offset))?;
Operand::Indirect(MemPlace::from_ptr(ptr.into(), layout.align.abi))
}
- ConstValue::Scalar(x) => Operand::Immediate(tag_scalar(x.into())?.into()),
+ ConstValue::Scalar(x) => Operand::Immediate(tag_scalar(x)?.into()),
ConstValue::Slice { data, start, end } => {
// We rely on mutability being set correctly in `data` to prevent writes
// where none should happen.