create leafs for slices

This commit is contained in:
b-naber
2022-04-08 13:09:24 +02:00
parent fcc4d8ce98
commit 82217a6587
6 changed files with 63 additions and 144 deletions

View File

@@ -14,9 +14,9 @@ use rustc_target::abi::{Abi, HasDataLayout, Size, TagEncoding};
use rustc_target::abi::{VariantIdx, Variants};
use super::{
alloc_range, from_known_layout, mir_assign_valid_types, AllocId, AllocRange, Allocation,
ConstValue, GlobalId, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, Place, PlaceTy,
Pointer, Provenance, Scalar, ScalarMaybeUninit,
alloc_range, from_known_layout, mir_assign_valid_types, AllocId, ConstValue, GlobalId,
InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Provenance,
Scalar, ScalarMaybeUninit,
};
/// An `Immediate` represents a single immediate self-contained Rust value.
@@ -98,7 +98,7 @@ impl<'tcx, Tag: Provenance> Immediate<Tag> {
// as input for binary and cast operations.
#[derive(Copy, Clone, Debug)]
pub struct ImmTy<'tcx, Tag: Provenance = AllocId> {
imm: Immediate<Tag>,
pub(crate) imm: Immediate<Tag>,
pub layout: TyAndLayout<'tcx>,
}
@@ -777,32 +777,3 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
})
}
}
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx, PointerTag = AllocId>> InterpCx<'mir, 'tcx, M> {
pub fn get_alloc_from_imm_scalar_pair(
&self,
imm: ImmTy<'tcx, M::PointerTag>,
) -> (&Allocation, AllocRange) {
match imm.imm {
Immediate::ScalarPair(a, b) => {
// We know `offset` is relative to the allocation, so we can use `into_parts`.
let (data, start) = match self.scalar_to_ptr(a.check_init().unwrap()).into_parts() {
(Some(alloc_id), offset) => {
(self.tcx.global_alloc(alloc_id).unwrap_memory(), offset.bytes())
}
(None, _offset) => (
self.tcx.intern_const_alloc(Allocation::from_bytes_byte_aligned_immutable(
b"" as &[u8],
)),
0,
),
};
let len = b.to_machine_usize(self).unwrap();
let size = Size::from_bytes(len);
let start = Size::from_bytes(start);
(data.inner(), AllocRange { start, size })
}
_ => bug!("{:?} not a ScalarPair", imm),
}
}
}

View File

@@ -305,18 +305,6 @@ where
Ok(mplace)
}
#[instrument(skip(self), level = "debug")]
pub fn deref_mplace(
&self,
src: &MPlaceTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
let val = self.try_read_immediate_from_mplace(src)?;
let mplace = self.ref_to_mplace(&val.unwrap())?;
self.check_mplace_access(mplace, CheckInAllocMsg::DerefTest)?;
Ok(mplace)
}
#[inline]
pub(super) fn get_alloc(
&self,