use len on mplace instead of reading immediate, remove dead code
This commit is contained in:
parent
8a5273bc99
commit
4b126b805b
3 changed files with 13 additions and 38 deletions
|
@ -12,8 +12,8 @@ use rustc_span::{source_map::DUMMY_SP, symbol::Symbol};
|
||||||
use rustc_target::abi::VariantIdx;
|
use rustc_target::abi::VariantIdx;
|
||||||
|
|
||||||
use crate::interpret::{
|
use crate::interpret::{
|
||||||
intern_const_alloc_recursive, ConstValue, Immediate, InternKind, InterpCx, InterpResult,
|
intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, MPlaceTy,
|
||||||
MPlaceTy, MemPlaceMeta, Scalar,
|
MemPlaceMeta, Scalar,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
|
@ -119,44 +119,19 @@ fn const_to_valtree_inner<'tcx>(
|
||||||
ty::Ref(_, inner_ty, _) => {
|
ty::Ref(_, inner_ty, _) => {
|
||||||
match inner_ty.kind() {
|
match inner_ty.kind() {
|
||||||
ty::Slice(_) | ty::Str => {
|
ty::Slice(_) | ty::Str => {
|
||||||
match ecx.try_read_immediate_from_mplace(&place) {
|
let derefd = ecx.deref_operand(&place.into()).unwrap();
|
||||||
Ok(Some(imm)) => {
|
debug!(?derefd);
|
||||||
let derefd = ecx.deref_operand(&place.into()).expect(&format!("couldnt deref {:?}", imm));
|
let len = derefd.len(&ecx.tcx.tcx).unwrap();
|
||||||
debug!(?derefd);
|
let valtree = slice_branches(ecx, &derefd, len);
|
||||||
|
debug!(?valtree);
|
||||||
|
|
||||||
let len = match *imm {
|
valtree
|
||||||
Immediate::ScalarPair(_, b) => {
|
|
||||||
let len = b.to_machine_usize(&ecx.tcx.tcx).unwrap();
|
|
||||||
len
|
|
||||||
}
|
|
||||||
_ => bug!("expected ScalarPair for &[T] or &str"),
|
|
||||||
};
|
|
||||||
debug!(?len);
|
|
||||||
|
|
||||||
let valtree = slice_branches(ecx, &derefd, len);
|
|
||||||
debug!(?valtree);
|
|
||||||
|
|
||||||
valtree
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let imm = ecx.try_read_immediate_from_mplace(&place).unwrap_or_else(|e| bug!("couldnt read immediate from {:?}, error: {:?}", place, e));
|
let derefd_place = ecx.deref_operand(&place.into()).unwrap_or_else(|e| bug!("couldn't deref {:?}, error: {:?}", place, e));
|
||||||
|
debug!(?derefd_place);
|
||||||
|
|
||||||
match imm {
|
const_to_valtree_inner(ecx, &derefd_place)
|
||||||
Some(imm) => {
|
|
||||||
debug!(?imm);
|
|
||||||
|
|
||||||
let derefd_place = ecx.deref_operand(&place.into()).unwrap_or_else(|e| bug!("couldn't deref {:?}, error: {:?}", place, e));
|
|
||||||
debug!(?derefd_place);
|
|
||||||
|
|
||||||
const_to_valtree_inner(ecx, &derefd_place)
|
|
||||||
}
|
|
||||||
None => bug!("couldn't read immediate from {:?}", place),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ impl<'tcx, Tag: Provenance> ImmTy<'tcx, Tag> {
|
||||||
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
/// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`.
|
/// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`.
|
||||||
/// Returns `None` if the layout does not permit loading this as a value.
|
/// Returns `None` if the layout does not permit loading this as a value.
|
||||||
pub(crate) fn try_read_immediate_from_mplace(
|
fn try_read_immediate_from_mplace(
|
||||||
&self,
|
&self,
|
||||||
mplace: &MPlaceTy<'tcx, M::PointerTag>,
|
mplace: &MPlaceTy<'tcx, M::PointerTag>,
|
||||||
) -> InterpResult<'tcx, Option<ImmTy<'tcx, M::PointerTag>>> {
|
) -> InterpResult<'tcx, Option<ImmTy<'tcx, M::PointerTag>>> {
|
||||||
|
|
|
@ -191,7 +191,7 @@ impl<'tcx, Tag: Provenance> MPlaceTy<'tcx, Tag> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn len(&self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
|
pub(crate) fn len(&self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
|
||||||
if self.layout.is_unsized() {
|
if self.layout.is_unsized() {
|
||||||
// We need to consult `meta` metadata
|
// We need to consult `meta` metadata
|
||||||
match self.layout.ty.kind() {
|
match self.layout.ty.kind() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue