use rustc::mir::interpret::{
GlobalId, AllocId, CheckInAllocMsg,
ConstValue, Pointer, Scalar,
- EvalResult, InterpError, InboundsCheck,
+ InterpResult, InterpError, InboundsCheck,
sign_extend, truncate,
};
use super::{
}
#[inline]
- pub fn to_scalar(self) -> EvalResult<'tcx, Scalar<Tag>> {
+ pub fn to_scalar(self) -> InterpResult<'tcx, Scalar<Tag>> {
self.to_scalar_or_undef().not_undef()
}
#[inline]
- pub fn to_scalar_pair(self) -> EvalResult<'tcx, (Scalar<Tag>, Scalar<Tag>)> {
+ pub fn to_scalar_pair(self) -> InterpResult<'tcx, (Scalar<Tag>, Scalar<Tag>)> {
match self {
Immediate::Scalar(..) => bug!("Got a thin pointer where a scalar pair was expected"),
Immediate::ScalarPair(a, b) => Ok((a.not_undef()?, b.not_undef()?))
/// Converts the immediate into a pointer (or a pointer-sized integer).
/// Throws away the second half of a ScalarPair!
#[inline]
- pub fn to_scalar_ptr(self) -> EvalResult<'tcx, Scalar<Tag>> {
+ pub fn to_scalar_ptr(self) -> InterpResult<'tcx, Scalar<Tag>> {
match self {
Immediate::Scalar(ptr) |
Immediate::ScalarPair(ptr, _) => ptr.not_undef(),
/// Converts the value into its metadata.
/// Throws away the first half of a ScalarPair!
#[inline]
- pub fn to_meta(self) -> EvalResult<'tcx, Option<Scalar<Tag>>> {
+ pub fn to_meta(self) -> InterpResult<'tcx, Option<Scalar<Tag>>> {
Ok(match self {
Immediate::Scalar(_) => None,
Immediate::ScalarPair(_, meta) => Some(meta.not_undef()?),
}
#[inline]
- pub fn to_bits(self) -> EvalResult<'tcx, u128> {
+ pub fn to_bits(self) -> InterpResult<'tcx, u128> {
self.to_scalar()?.to_bits(self.layout.size)
}
}
#[inline(always)]
pub(super) fn from_known_layout<'tcx>(
layout: Option<TyLayout<'tcx>>,
- compute: impl FnOnce() -> EvalResult<'tcx, TyLayout<'tcx>>
-) -> EvalResult<'tcx, TyLayout<'tcx>> {
+ compute: impl FnOnce() -> InterpResult<'tcx, TyLayout<'tcx>>
+) -> InterpResult<'tcx, TyLayout<'tcx>> {
match layout {
None => compute(),
Some(layout) => {
fn try_read_immediate_from_mplace(
&self,
mplace: MPlaceTy<'tcx, M::PointerTag>,
- ) -> EvalResult<'tcx, Option<Immediate<M::PointerTag>>> {
+ ) -> InterpResult<'tcx, Option<Immediate<M::PointerTag>>> {
if mplace.layout.is_unsized() {
// Don't touch unsized
return Ok(None);
/// 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.
- pub(super) fn try_read_immediate(
+ pub(crate) fn try_read_immediate(
&self,
src: OpTy<'tcx, M::PointerTag>,
- ) -> EvalResult<'tcx, Result<Immediate<M::PointerTag>, MemPlace<M::PointerTag>>> {
+ ) -> InterpResult<'tcx, Result<Immediate<M::PointerTag>, MemPlace<M::PointerTag>>> {
Ok(match src.try_as_mplace() {
Ok(mplace) => {
if let Some(val) = self.try_read_immediate_from_mplace(mplace)? {
pub fn read_immediate(
&self,
op: OpTy<'tcx, M::PointerTag>
- ) -> EvalResult<'tcx, ImmTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, ImmTy<'tcx, M::PointerTag>> {
if let Ok(imm) = self.try_read_immediate(op)? {
Ok(ImmTy { imm, layout: op.layout })
} else {
pub fn read_scalar(
&self,
op: OpTy<'tcx, M::PointerTag>
- ) -> EvalResult<'tcx, ScalarMaybeUndef<M::PointerTag>> {
+ ) -> InterpResult<'tcx, ScalarMaybeUndef<M::PointerTag>> {
Ok(self.read_immediate(op)?.to_scalar_or_undef())
}
pub fn read_str(
&self,
mplace: MPlaceTy<'tcx, M::PointerTag>,
- ) -> EvalResult<'tcx, &str> {
+ ) -> InterpResult<'tcx, &str> {
let len = mplace.len(self)?;
let bytes = self.memory.read_bytes(mplace.ptr, Size::from_bytes(len as u64))?;
let str = ::std::str::from_utf8(bytes)
&self,
op: OpTy<'tcx, M::PointerTag>,
field: u64,
- ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
let base = match op.try_as_mplace() {
Ok(mplace) => {
// The easy case
&self,
op: OpTy<'tcx, M::PointerTag>,
variant: VariantIdx,
- ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
// Downcasts only change the layout
Ok(match op.try_as_mplace() {
Ok(mplace) => {
&self,
base: OpTy<'tcx, M::PointerTag>,
proj_elem: &mir::PlaceElem<'tcx>,
- ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
use rustc::mir::ProjectionElem::*;
Ok(match *proj_elem {
Field(field, _) => self.operand_field(base, field.index() as u64)?,
frame: &super::Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
local: mir::Local,
layout: Option<TyLayout<'tcx>>,
- ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
assert_ne!(local, mir::RETURN_PLACE);
let layout = self.layout_of_local(frame, local, layout)?;
let op = if layout.is_zst() {
pub fn place_to_op(
&self,
place: PlaceTy<'tcx, M::PointerTag>
- ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
let op = match *place {
Place::Ptr(mplace) => {
Operand::Indirect(mplace)
&self,
mir_place: &mir::Place<'tcx>,
layout: Option<TyLayout<'tcx>>,
- ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
use rustc::mir::Place;
use rustc::mir::PlaceBase;
&self,
mir_op: &mir::Operand<'tcx>,
layout: Option<TyLayout<'tcx>>,
- ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
use rustc::mir::Operand::*;
let op = match *mir_op {
// FIXME: do some more logic on `move` to invalidate the old location
pub(super) fn eval_operands(
&self,
ops: &[mir::Operand<'tcx>],
- ) -> EvalResult<'tcx, Vec<OpTy<'tcx, M::PointerTag>>> {
+ ) -> InterpResult<'tcx, Vec<OpTy<'tcx, M::PointerTag>>> {
ops.into_iter()
.map(|op| self.eval_operand(op, None))
.collect()
&self,
val: &'tcx ty::Const<'tcx>,
layout: Option<TyLayout<'tcx>>,
- ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
+ ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
let tag_scalar = |scalar| match scalar {
Scalar::Ptr(ptr) => Scalar::Ptr(self.tag_static_base_pointer(ptr)),
Scalar::Raw { data, size } => Scalar::Raw { data, size },
};
// Early-return cases.
match val.val {
- ConstValue::Param(_) => return err!(TooGeneric),
+ ConstValue::Param(_) => return err!(TooGeneric), // FIXME(oli-obk): try to monomorphize
ConstValue::Unevaluated(def_id, substs) => {
let instance = self.resolve(def_id, substs)?;
return Ok(OpTy::from(self.const_eval_raw(GlobalId {
let op = match val.val {
ConstValue::ByRef(ptr, _alloc) => {
// We rely on mutability being set correctly in that allocation to prevent writes
- // where none should happen -- and for `static mut`, we copy on demand anyway.
+ // where none should happen.
let ptr = self.tag_static_base_pointer(ptr);
Operand::Indirect(MemPlace::from_ptr(ptr, layout.align.abi))
},
ConstValue::Scalar(x) =>
Operand::Immediate(Immediate::Scalar(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.
let ptr = Pointer::new(
self.tcx.alloc_map.lock().create_memory_alloc(data),
Size::from_bytes(start as u64), // offset: `start`
pub fn read_discriminant(
&self,
rval: OpTy<'tcx, M::PointerTag>,
- ) -> EvalResult<'tcx, (u128, VariantIdx)> {
+ ) -> InterpResult<'tcx, (u128, VariantIdx)> {
trace!("read_discriminant_value {:#?}", rval.layout);
let (discr_kind, discr_index) = match rval.layout.variants {