use From to convert scalars to immediates
This commit is contained in:
parent
b318bcfa78
commit
780e1fc5df
2 changed files with 10 additions and 15 deletions
|
|
@ -47,11 +47,6 @@ impl<Tag> From<Scalar<Tag>> for Immediate<Tag> {
|
|||
}
|
||||
|
||||
impl<'tcx, Tag> Immediate<Tag> {
|
||||
#[inline]
|
||||
pub fn from_scalar(val: Scalar<Tag>) -> Self {
|
||||
Immediate::Scalar(ScalarMaybeUndef::Scalar(val))
|
||||
}
|
||||
|
||||
pub fn new_slice(
|
||||
val: Scalar<Tag>,
|
||||
len: u64,
|
||||
|
|
@ -196,7 +191,7 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag>
|
|||
{
|
||||
#[inline]
|
||||
pub fn from_scalar(val: Scalar<Tag>, layout: TyLayout<'tcx>) -> Self {
|
||||
ImmTy { imm: Immediate::from_scalar(val), layout }
|
||||
ImmTy { imm: val.into(), layout }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -254,7 +249,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let ptr = match self.check_mplace_access(mplace, None)? {
|
||||
Some(ptr) => ptr,
|
||||
None => return Ok(Some(ImmTy { // zero-sized type
|
||||
imm: Immediate::Scalar(Scalar::zst().into()),
|
||||
imm: Scalar::zst().into(),
|
||||
layout: mplace.layout,
|
||||
})),
|
||||
};
|
||||
|
|
@ -265,7 +260,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
.get(ptr.alloc_id)?
|
||||
.read_scalar(self, ptr, mplace.layout.size)?;
|
||||
Ok(Some(ImmTy {
|
||||
imm: Immediate::Scalar(scalar),
|
||||
imm: scalar.into(),
|
||||
layout: mplace.layout,
|
||||
}))
|
||||
}
|
||||
|
|
@ -368,7 +363,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let field = field.try_into().unwrap();
|
||||
let field_layout = op.layout.field(self, field)?;
|
||||
if field_layout.is_zst() {
|
||||
let immediate = Immediate::Scalar(Scalar::zst().into());
|
||||
let immediate = Scalar::zst().into();
|
||||
return Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout });
|
||||
}
|
||||
let offset = op.layout.fields.offset(field);
|
||||
|
|
@ -378,7 +373,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// extract fields from types with `ScalarPair` ABI
|
||||
Immediate::ScalarPair(a, b) => {
|
||||
let val = if offset.bytes() == 0 { a } else { b };
|
||||
Immediate::Scalar(val)
|
||||
Immediate::from(val)
|
||||
},
|
||||
Immediate::Scalar(val) =>
|
||||
bug!("field access on non aggregate {:#?}, {:#?}", val, op.layout),
|
||||
|
|
@ -415,7 +410,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
Deref => self.deref_operand(base)?.into(),
|
||||
Subslice { .. } | ConstantIndex { .. } | Index(_) => if base.layout.is_zst() {
|
||||
OpTy {
|
||||
op: Operand::Immediate(Immediate::Scalar(Scalar::zst().into())),
|
||||
op: Operand::Immediate(Scalar::zst().into()),
|
||||
// the actual index doesn't matter, so we just pick a convenient one like 0
|
||||
layout: base.layout.field(self, 0)?,
|
||||
}
|
||||
|
|
@ -439,7 +434,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let layout = self.layout_of_local(frame, local, layout)?;
|
||||
let op = if layout.is_zst() {
|
||||
// Do not read from ZST, they might not be initialized
|
||||
Operand::Immediate(Immediate::Scalar(Scalar::zst().into()))
|
||||
Operand::Immediate(Scalar::zst().into())
|
||||
} else {
|
||||
frame.locals[local].access()?
|
||||
};
|
||||
|
|
@ -570,7 +565,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
Operand::Indirect(MemPlace::from_ptr(ptr, align))
|
||||
},
|
||||
ConstValue::Scalar(x) =>
|
||||
Operand::Immediate(Immediate::Scalar(tag_scalar(x).into())),
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use rustc_target::spec::abi::Abi;
|
|||
|
||||
use super::{
|
||||
InterpResult, PointerArithmetic, Scalar,
|
||||
InterpCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal,
|
||||
InterpCx, Machine, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal,
|
||||
};
|
||||
|
||||
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
|
|
@ -460,7 +460,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// Adjust receiver argument.
|
||||
args[0] = OpTy::from(ImmTy {
|
||||
layout: this_receiver_ptr,
|
||||
imm: Immediate::Scalar(receiver_place.ptr.into())
|
||||
imm: receiver_place.ptr.into()
|
||||
});
|
||||
trace!("Patched self operand to {:#?}", args[0]);
|
||||
// recurse with concrete function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue