Move to_const_value from MPlaceTy to its only use site
This commit is contained in:
parent
4a5c35bc44
commit
cac6f4c12d
2 changed files with 14 additions and 18 deletions
|
|
@ -117,12 +117,23 @@ pub(super) fn op_to_const<'tcx>(
|
|||
// structs containing such.
|
||||
op.try_as_mplace(ecx)
|
||||
};
|
||||
|
||||
let to_const_value = |mplace: MPlaceTy<'_>| match mplace.ptr {
|
||||
Scalar::Ptr(ptr) => {
|
||||
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
|
||||
ConstValue::ByRef { alloc, offset: ptr.offset }
|
||||
}
|
||||
Scalar::Raw { data, .. } => {
|
||||
assert_eq!(data, mplace.layout.align.abi.bytes().into());
|
||||
ConstValue::Scalar(Scalar::zst())
|
||||
}
|
||||
};
|
||||
let val = match immediate {
|
||||
Ok(mplace) => mplace.to_const_value(ecx.tcx.tcx),
|
||||
Ok(mplace) => to_const_value(mplace),
|
||||
// see comment on `let try_as_immediate` above
|
||||
Err(ImmTy { imm: Immediate::Scalar(x), .. }) => match x {
|
||||
ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s),
|
||||
ScalarMaybeUndef::Undef => op.assert_mem_place(ecx).to_const_value(ecx.tcx.tcx),
|
||||
ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)),
|
||||
},
|
||||
Err(ImmTy { imm: Immediate::ScalarPair(a, b), .. }) => {
|
||||
let (data, start) = match a.not_undef().unwrap() {
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ use std::convert::TryFrom;
|
|||
use std::hash::Hash;
|
||||
|
||||
use rustc::mir;
|
||||
use rustc::mir::interpret::{truncate, ConstValue};
|
||||
use rustc::mir::interpret::truncate;
|
||||
use rustc::ty::layout::{
|
||||
self, Align, HasDataLayout, LayoutOf, PrimitiveExt, Size, TyLayout, VariantIdx,
|
||||
};
|
||||
use rustc::ty::TypeFoldable;
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use rustc_macros::HashStable;
|
||||
|
||||
use super::{
|
||||
|
|
@ -196,20 +195,6 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
|
|||
_ => bug!("vtable not supported on type {:?}", self.layout.ty),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_const_value(self, tcx: TyCtxt<'tcx>) -> ConstValue<'tcx> {
|
||||
match self.mplace.ptr {
|
||||
Scalar::Ptr(ptr) => {
|
||||
let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
|
||||
ConstValue::ByRef { alloc, offset: ptr.offset }
|
||||
}
|
||||
Scalar::Raw { data, .. } => {
|
||||
assert_eq!(data, self.layout.align.abi.bytes().into());
|
||||
ConstValue::Scalar(Scalar::zst())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// These are defined here because they produce a place.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue