From fd352b02e17d78f03345ebc3ffabe02b0cb04fd1 Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Sat, 20 Jul 2019 11:48:16 +0530 Subject: [PATCH] alters the panic variant of InterpError --- src/librustc/mir/interpret/error.rs | 59 +++++++++--------------- src/librustc/mir/interpret/mod.rs | 2 +- src/librustc_mir/interpret/intrinsics.rs | 6 +-- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index d5caa3c8ce4..9e216a14874 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -228,6 +228,24 @@ impl<'tcx> From> for InterpErrorInfo<'tcx> { pub type AssertMessage<'tcx> = InterpError<'tcx, mir::Operand<'tcx>>; +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] +pub enum EvalErrorPanic { + Panic { + msg: Symbol, + line: u32, + col: u32, + file: Symbol, + }, + BoundsCheck { + len: O, + index: O, + }, + Overflow(mir::BinOp), + OverflowNeg, + DivisionByZero, + RemainderByZero, +} + #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum InterpError<'tcx, O> { /// This variant is used by machines to signal their own errors that do not @@ -247,7 +265,6 @@ pub enum InterpError<'tcx, O> { DanglingPointerDeref, DoubleFree, InvalidMemoryAccess, - FunctionPointerTyMismatch(FnSig<'tcx>, FnSig<'tcx>), InvalidFunctionPointer, InvalidBool, InvalidDiscriminant(ScalarMaybeUndef), @@ -267,13 +284,11 @@ pub enum InterpError<'tcx, O> { Unimplemented(String), DerefFunctionPointer, ExecuteMemory, - // asd BoundsCheck { len: O, index: O }, Overflow(mir::BinOp), OverflowNeg, DivisionByZero, RemainderByZero, - // asd Intrinsic(String), InvalidChar(u128), StackFrameLimitReached, @@ -284,29 +299,6 @@ pub enum InterpError<'tcx, O> { required: Align, has: Align, }, - MemoryLockViolation { - ptr: Pointer, - len: u64, - frame: usize, - access: AccessKind, - lock: Lock, - }, - MemoryAcquireConflict { - ptr: Pointer, - len: u64, - kind: AccessKind, - lock: Lock, - }, - InvalidMemoryLockRelease { - ptr: Pointer, - len: u64, - frame: usize, - lock: Lock, - }, - DeallocatedLockedMemory { - ptr: Pointer, - lock: Lock, - }, ValidationFailure(String), CalledClosureAsFunction, VtableForArgumentlessMethod, @@ -324,7 +316,7 @@ pub enum InterpError<'tcx, O> { HeapAllocZeroBytes, HeapAllocNonPowerOfTwoAlignment(u64), Unreachable, - Panic(EvalErrorPanic<'tcx, O>), + Panic(EvalErrorPanic), ReadFromReturnPointer, PathNotFound(Vec), UnimplementedTraitSelection, @@ -340,15 +332,6 @@ pub enum InterpError<'tcx, O> { InfiniteLoop, } -#[derive(Clone, RustcEncodable, RustcDecodable)] -pub enum EvalErrorPanic<'tcx, O> { - Panic, - BoundsCheck { len: O, index: O }, - Overflow(mir::BinOp), - OverflowNeg, - DivisionByZero, - RemainderByZero, -} pub type InterpResult<'tcx, T = ()> = Result>; @@ -549,8 +532,8 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> { write!(f, "incorrect alloc info: expected size {} and align {}, \ got size {} and align {}", size.bytes(), align.bytes(), size2.bytes(), align2.bytes()), - Panic { ref msg, line, col, ref file } => - write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col), + Panic { .. } => + write!(f, "the evaluated program panicked"), InvalidDiscriminant(val) => write!(f, "encountered invalid enum discriminant {}", val), Exit(code) => diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 1b294250aa3..01bc27d55e5 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -12,7 +12,7 @@ mod pointer; pub use self::error::{ InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error, - FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, + FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, EvalErrorPanic }; pub use self::value::{Scalar, ScalarMaybeUndef, RawConst, ConstValue}; diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index cf36c10a614..5b80d0e251e 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -7,7 +7,7 @@ use rustc::ty; use rustc::ty::layout::{LayoutOf, Primitive, Size}; use rustc::mir::BinOp; use rustc::mir::interpret::{ - InterpResult, InterpError, Scalar, + InterpResult, InterpError, Scalar, EvalErrorPanic, }; use super::{ @@ -261,7 +261,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let file = Symbol::intern(self.read_str(file_place)?); let line = self.read_scalar(line.into())?.to_u32()?; let col = self.read_scalar(col.into())?.to_u32()?; - return Err(InterpError::Panic { msg, file, line, col }.into()); + return Err(InterpError::Panic(EvalErrorPanic::Panic { msg, file, line, col }).into()); } else if Some(def_id) == self.tcx.lang_items().begin_panic_fn() { assert!(args.len() == 2); // &'static str, &(&'static str, u32, u32) @@ -279,7 +279,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let file = Symbol::intern(self.read_str(file_place)?); let line = self.read_scalar(line.into())?.to_u32()?; let col = self.read_scalar(col.into())?.to_u32()?; - return Err(InterpError::Panic { msg, file, line, col }.into()); + return Err(InterpError::Panic(EvalErrorPanic::Panic { msg, file, line, col }).into()); } else { return Ok(false); }