use PanicInfo and UnsupportedOpInfo
This commit is contained in:
parent
8e9d0faff2
commit
654519d3c5
14 changed files with 42 additions and 42 deletions
|
|
@ -237,7 +237,7 @@ impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
|
|||
}
|
||||
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
|
||||
pub enum PanicMessage<O> {
|
||||
pub enum PanicInfo<O> {
|
||||
Panic {
|
||||
msg: Symbol,
|
||||
line: u32,
|
||||
|
|
@ -257,14 +257,14 @@ pub enum PanicMessage<O> {
|
|||
}
|
||||
|
||||
/// Type for MIR `Assert` terminator error messages.
|
||||
pub type AssertMessage<'tcx> = PanicMessage<mir::Operand<'tcx>>;
|
||||
pub type AssertMessage<'tcx> = PanicInfo<mir::Operand<'tcx>>;
|
||||
|
||||
impl<O> PanicMessage<O> {
|
||||
impl<O> PanicInfo<O> {
|
||||
/// Getting a description does not require `O` to be printable, and does not
|
||||
/// require allocation.
|
||||
/// The caller is expected to handle `Panic` and `BoundsCheck` separately.
|
||||
pub fn description(&self) -> &'static str {
|
||||
use PanicMessage::*;
|
||||
use PanicInfo::*;
|
||||
match self {
|
||||
Overflow(mir::BinOp::Add) =>
|
||||
"attempt to add with overflow",
|
||||
|
|
@ -293,14 +293,14 @@ impl<O> PanicMessage<O> {
|
|||
GeneratorResumedAfterPanic =>
|
||||
"generator resumed after panicking",
|
||||
Panic { .. } | BoundsCheck { .. } =>
|
||||
bug!("Unexpected PanicMessage"),
|
||||
bug!("Unexpected PanicInfo"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<O: fmt::Debug> fmt::Debug for PanicMessage<O> {
|
||||
impl<O: fmt::Debug> fmt::Debug for PanicInfo<O> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use PanicMessage::*;
|
||||
use PanicInfo::*;
|
||||
match self {
|
||||
Panic { ref msg, line, col, ref file } =>
|
||||
write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col),
|
||||
|
|
@ -568,7 +568,7 @@ impl fmt::Debug for ResourceExhaustionInfo {
|
|||
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
|
||||
pub enum InterpError<'tcx> {
|
||||
/// The program panicked.
|
||||
Panic(PanicMessage<u64>),
|
||||
Panic(PanicInfo<u64>),
|
||||
/// The program caused undefined behavior.
|
||||
UndefinedBehaviour(UndefinedBehaviourInfo),
|
||||
/// The program did something the interpreter does not support (some of these *might* be UB
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ macro_rules! err_ub {
|
|||
macro_rules! err_panic {
|
||||
($($tt:tt)*) => {
|
||||
Err($crate::mir::interpret::InterpError::Panic(
|
||||
$crate::mir::interpret::PanicMessage::$($tt)*
|
||||
$crate::mir::interpret::PanicInfo::$($tt)*
|
||||
).into())
|
||||
};
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ mod pointer;
|
|||
|
||||
pub use self::error::{
|
||||
InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error,
|
||||
FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicMessage, UnsupportedInfo,
|
||||
FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicInfo, UnsupportedInfo,
|
||||
InvalidProgramInfo, ResourceExhaustionInfo, UndefinedBehaviourInfo,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
use crate::hir::def::{CtorKind, Namespace};
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::hir::{self, InlineAsm as HirInlineAsm};
|
||||
use crate::mir::interpret::{ConstValue, PanicMessage, Scalar};
|
||||
use crate::mir::interpret::{ConstValue, PanicInfo, Scalar};
|
||||
use crate::mir::visit::MirVisitable;
|
||||
use crate::ty::adjustment::PointerCast;
|
||||
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
|
|
@ -3152,7 +3152,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
|||
}
|
||||
}
|
||||
Assert { ref cond, expected, ref msg, target, cleanup } => {
|
||||
use PanicMessage::*;
|
||||
use PanicInfo::*;
|
||||
let msg = match msg {
|
||||
BoundsCheck { ref len, ref index } =>
|
||||
BoundsCheck {
|
||||
|
|
@ -3200,7 +3200,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
|||
}
|
||||
Assert { ref cond, ref msg, .. } => {
|
||||
if cond.visit_with(visitor) {
|
||||
use PanicMessage::*;
|
||||
use PanicInfo::*;
|
||||
match msg {
|
||||
BoundsCheck { ref len, ref index } =>
|
||||
len.visit_with(visitor) || index.visit_with(visitor),
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@ macro_rules! make_mir_visitor {
|
|||
fn super_assert_message(&mut self,
|
||||
msg: & $($mutability)? AssertMessage<'tcx>,
|
||||
location: Location) {
|
||||
use crate::mir::interpret::PanicMessage::*;
|
||||
use crate::mir::interpret::PanicInfo::*;
|
||||
match msg {
|
||||
BoundsCheck { len, index } => {
|
||||
self.visit_operand(len, location);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use rustc::middle::lang_items;
|
|||
use rustc::ty::{self, Ty, TypeFoldable, Instance};
|
||||
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt};
|
||||
use rustc::mir::{self, Place, PlaceBase, Static, StaticKind};
|
||||
use rustc::mir::interpret::PanicMessage;
|
||||
use rustc::mir::interpret::PanicInfo;
|
||||
use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use crate::base;
|
||||
|
|
@ -368,7 +368,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
// checked operation, just a comparison with the minimum
|
||||
// value, so we have to check for the assert message.
|
||||
if !bx.check_overflow() {
|
||||
if let PanicMessage::OverflowNeg = *msg {
|
||||
if let PanicInfo::OverflowNeg = *msg {
|
||||
const_cond = Some(expected);
|
||||
}
|
||||
}
|
||||
|
|
@ -403,7 +403,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
|
||||
// Put together the arguments to the panic entry point.
|
||||
let (lang_item, args) = match msg {
|
||||
PanicMessage::BoundsCheck { ref len, ref index } => {
|
||||
PanicInfo::BoundsCheck { ref len, ref index } => {
|
||||
let len = self.codegen_operand(&mut bx, len).immediate();
|
||||
let index = self.codegen_operand(&mut bx, index).immediate();
|
||||
|
||||
|
|
|
|||
|
|
@ -733,8 +733,8 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
|
|||
cleanup: _,
|
||||
} => {
|
||||
self.consume_operand(loc, (cond, span), flow_state);
|
||||
use rustc::mir::interpret::PanicMessage;
|
||||
if let PanicMessage::BoundsCheck { ref len, ref index } = *msg {
|
||||
use rustc::mir::interpret::PanicInfo;
|
||||
if let PanicInfo::BoundsCheck { ref len, ref index } = *msg {
|
||||
self.consume_operand(loc, (len, span), flow_state);
|
||||
self.consume_operand(loc, (index, span), flow_state);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,8 +207,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
|
|||
cleanup: _,
|
||||
} => {
|
||||
self.consume_operand(location, cond);
|
||||
use rustc::mir::interpret::PanicMessage;
|
||||
if let PanicMessage::BoundsCheck { ref len, ref index } = *msg {
|
||||
use rustc::mir::interpret::PanicInfo;
|
||||
if let PanicInfo::BoundsCheck { ref len, ref index } = *msg {
|
||||
self.consume_operand(location, len);
|
||||
self.consume_operand(location, index);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use rustc::infer::canonical::QueryRegionConstraints;
|
|||
use rustc::infer::outlives::env::RegionBoundPairs;
|
||||
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
|
||||
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc::mir::interpret::{ConstValue, PanicMessage};
|
||||
use rustc::mir::interpret::{ConstValue, PanicInfo};
|
||||
use rustc::mir::tcx::PlaceTy;
|
||||
use rustc::mir::visit::{PlaceContext, Visitor, NonMutatingUseContext};
|
||||
use rustc::mir::*;
|
||||
|
|
@ -1632,7 +1632,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty);
|
||||
}
|
||||
|
||||
if let PanicMessage::BoundsCheck { ref len, ref index } = *msg {
|
||||
if let PanicInfo::BoundsCheck { ref len, ref index } = *msg {
|
||||
if len.ty(body, tcx) != tcx.types.usize {
|
||||
span_mirbug!(self, len, "bounds-check length non-usize {:?}", len)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::build::expr::category::Category;
|
|||
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
|
||||
use crate::build::{BlockAnd, BlockAndExtension, Builder};
|
||||
use crate::hair::*;
|
||||
use rustc::mir::interpret::{PanicMessage::BoundsCheck};
|
||||
use rustc::mir::interpret::{PanicInfo::BoundsCheck};
|
||||
use rustc::mir::*;
|
||||
use rustc::ty::{CanonicalUserTypeAnnotation, Variance};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::build::expr::category::{Category, RvalueFunc};
|
|||
use crate::build::{BlockAnd, BlockAndExtension, Builder};
|
||||
use crate::hair::*;
|
||||
use rustc::middle::region;
|
||||
use rustc::mir::interpret::PanicMessage;
|
||||
use rustc::mir::interpret::PanicInfo;
|
||||
use rustc::mir::*;
|
||||
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts};
|
||||
use syntax_pos::Span;
|
||||
|
|
@ -101,7 +101,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
Operand::Move(is_min),
|
||||
false,
|
||||
PanicMessage::OverflowNeg,
|
||||
PanicInfo::OverflowNeg,
|
||||
expr_span,
|
||||
);
|
||||
}
|
||||
|
|
@ -401,7 +401,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let val = result_value.clone().field(val_fld, ty);
|
||||
let of = result_value.field(of_fld, bool_ty);
|
||||
|
||||
let err = PanicMessage::Overflow(op);
|
||||
let err = PanicInfo::Overflow(op);
|
||||
|
||||
block = self.assert(block, Operand::Move(of), false, err, span);
|
||||
|
||||
|
|
@ -412,11 +412,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// and 2. there are two possible failure cases, divide-by-zero and overflow.
|
||||
|
||||
let zero_err = if op == BinOp::Div {
|
||||
PanicMessage::DivisionByZero
|
||||
PanicInfo::DivisionByZero
|
||||
} else {
|
||||
PanicMessage::RemainderByZero
|
||||
PanicInfo::RemainderByZero
|
||||
};
|
||||
let overflow_err = PanicMessage::Overflow(op);
|
||||
let overflow_err = PanicInfo::Overflow(op);
|
||||
|
||||
// Check for / 0
|
||||
let is_zero = self.temp(bool_ty, span);
|
||||
|
|
|
|||
|
|
@ -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, PanicMessage, UnsupportedInfo::*,
|
||||
InterpResult, InterpError, Scalar, PanicInfo, UnsupportedInfo::*,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
@ -250,7 +250,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(PanicMessage::Panic { msg, file, line, col }).into());
|
||||
return Err(InterpError::Panic(PanicInfo::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)
|
||||
|
|
@ -268,7 +268,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(PanicMessage::Panic { msg, file, line, col }).into());
|
||||
return Err(InterpError::Panic(PanicInfo::Panic { msg, file, line, col }).into());
|
||||
} else {
|
||||
return Ok(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
self.goto_block(Some(target))?;
|
||||
} else {
|
||||
// Compute error message
|
||||
use rustc::mir::interpret::PanicMessage::*;
|
||||
use rustc::mir::interpret::PanicInfo::*;
|
||||
return match msg {
|
||||
BoundsCheck { ref len, ref index } => {
|
||||
let len = self.read_immediate(self.eval_operand(len, None)?)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use rustc::mir::{
|
|||
use rustc::mir::visit::{
|
||||
Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext,
|
||||
};
|
||||
use rustc::mir::interpret::{Scalar, GlobalId, InterpResult, InterpError, PanicMessage};
|
||||
use rustc::mir::interpret::{Scalar, GlobalId, InterpResult, InterpError, PanicInfo};
|
||||
use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt};
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use rustc::ty::subst::InternalSubsts;
|
||||
|
|
@ -526,7 +526,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
)
|
||||
} else {
|
||||
if overflow {
|
||||
let err = InterpError::Panic(PanicMessage::Overflow(op)).into();
|
||||
let err = InterpError::Panic(PanicInfo::Overflow(op)).into();
|
||||
let _: Option<()> = self.use_ecx(source_info, |_| Err(err));
|
||||
return None;
|
||||
}
|
||||
|
|
@ -763,12 +763,12 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
|
|||
.as_local_hir_id(self.source.def_id())
|
||||
.expect("some part of a failing const eval must be local");
|
||||
let msg = match msg {
|
||||
PanicMessage::Overflow(_) |
|
||||
PanicMessage::OverflowNeg |
|
||||
PanicMessage::DivisionByZero |
|
||||
PanicMessage::RemainderByZero =>
|
||||
PanicInfo::Overflow(_) |
|
||||
PanicInfo::OverflowNeg |
|
||||
PanicInfo::DivisionByZero |
|
||||
PanicInfo::RemainderByZero =>
|
||||
msg.description().to_owned(),
|
||||
PanicMessage::BoundsCheck { ref len, ref index } => {
|
||||
PanicInfo::BoundsCheck { ref len, ref index } => {
|
||||
let len = self
|
||||
.eval_operand(len, source_info)
|
||||
.expect("len must be const");
|
||||
|
|
|
|||
|
|
@ -1016,7 +1016,7 @@ fn create_generator_resume_function<'tcx>(
|
|||
|
||||
let mut cases = create_cases(body, &transform, |point| Some(point.resume));
|
||||
|
||||
use rustc::mir::interpret::PanicMessage::{
|
||||
use rustc::mir::interpret::PanicInfo::{
|
||||
GeneratorResumedAfterPanic,
|
||||
GeneratorResumedAfterReturn,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue