addding an interp_error module

This commit is contained in:
Saleem Jaffer 2019-07-30 13:18:36 +05:30
parent 96205212e5
commit 2a33fbff22
7 changed files with 30 additions and 11 deletions

View file

@ -0,0 +1,20 @@
//! macros to do something like `.ok_or_else(|| inval!(TooGeneric).into())` rather than
//! `.ok_or_else(|| InterpError::InvalidProgram(TooGeneric).into())`
#[macro_export]
macro_rules! inval {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::InvalidProgram(
$crate::mir::interpret::InvalidProgramInfo::$($tt)*
)
};
}
#[macro_export]
macro_rules! unsup {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::Unsupported(
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
)
};
}

View file

@ -49,6 +49,7 @@ mod error;
mod value;
mod allocation;
mod pointer;
mod interp_error;
pub use self::error::{
InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error,

View file

@ -7,7 +7,7 @@ use syntax::symbol::sym;
use rustc_apfloat::ieee::{Single, Double};
use rustc_apfloat::{Float, FloatConvert};
use rustc::mir::interpret::{
Scalar, InterpResult, Pointer, PointerArithmetic, InterpError,
Scalar, InterpResult, Pointer, PointerArithmetic,
};
use rustc::mir::CastKind;
@ -74,7 +74,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
Pointer(PointerCast::ReifyFnPointer) => {
use rustc::mir::interpret::InvalidProgramInfo::TooGeneric;
// The src operand does not matter, just its type
match src.layout.ty.sty {
ty::FnDef(def_id, substs) => {
@ -86,7 +85,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.param_env,
def_id,
substs,
).ok_or_else(|| InterpError::InvalidProgram(TooGeneric).into());
).ok_or_else(|| inval!(TooGeneric).into());
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance?));
self.write_scalar(Scalar::Ptr(fn_ptr.into()), dest)?;
}

View file

@ -326,7 +326,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.param_env,
def_id,
substs,
).ok_or_else(|| InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric).into())
).ok_or_else(|| inval!(TooGeneric).into())
}
pub fn load_mir(

View file

@ -637,7 +637,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
.find(|(_, var)| var.val == real_discr),
_ => bug!("tagged layout for non-adt non-generator"),
}.ok_or_else(
|| InterpError::Unsupported(InvalidDiscriminant(raw_discr.erase_tag()))
|| unsup!(InvalidDiscriminant(raw_discr.erase_tag()))
)?;
(real_discr, index.0)
},

View file

@ -7,9 +7,8 @@ use syntax::source_map::Span;
use rustc_target::spec::abi::Abi;
use super::{
InterpResult, PointerArithmetic, InterpError, Scalar,
InterpResult, PointerArithmetic, Scalar,
InterpCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal,
UnsupportedOpInfo,
};
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
@ -221,7 +220,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
return Ok(());
}
let caller_arg = caller_arg.next()
.ok_or_else(|| InterpError::Unsupported(UnsupportedOpInfo::FunctionArgCountMismatch))?;
.ok_or_else(|| unsup!(FunctionArgCountMismatch)) ?;
if rust_abi {
debug_assert!(!caller_arg.layout.is_zst(), "ZSTs must have been already filtered out");
}

View file

@ -1,8 +1,8 @@
use rustc::ty::{self, Ty, Instance};
use rustc::ty::layout::{Size, Align, LayoutOf};
use rustc::mir::interpret::{Scalar, Pointer, InterpResult, PointerArithmetic, InvalidProgramInfo};
use rustc::mir::interpret::{Scalar, Pointer, InterpResult, PointerArithmetic,};
use super::{InterpCx, InterpError, Machine, MemoryKind, FnVal};
use super::{InterpCx, Machine, MemoryKind, FnVal};
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// Creates a dynamic vtable for the given type and vtable origin. This is used only for
@ -83,7 +83,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.param_env,
def_id,
substs,
).ok_or_else(|| InterpError::InvalidProgram(InvalidProgramInfo::TooGeneric))?;
).ok_or_else(|| inval!(TooGeneric))?;
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));
let method_ptr = vtable.offset(ptr_size * (3 + i as u64), self)?;
self.memory