From: Saleem Jaffer Date: Mon, 29 Jul 2019 07:58:55 +0000 (+0530) Subject: use PanicInfo and UnsupportedOpInfo X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=654519d3c5cd0bdece35a3282bdb433bf945ee57;p=rust.git use PanicInfo and UnsupportedOpInfo --- diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index e519a83c026..5a464ddd383 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -237,7 +237,7 @@ fn from(kind: InterpError<'tcx>) -> Self { } #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] -pub enum PanicMessage { +pub enum PanicInfo { Panic { msg: Symbol, line: u32, @@ -257,14 +257,14 @@ pub enum PanicMessage { } /// Type for MIR `Assert` terminator error messages. -pub type AssertMessage<'tcx> = PanicMessage>; +pub type AssertMessage<'tcx> = PanicInfo>; -impl PanicMessage { +impl PanicInfo { /// 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 @@ pub fn description(&self) -> &'static str { GeneratorResumedAfterPanic => "generator resumed after panicking", Panic { .. } | BoundsCheck { .. } => - bug!("Unexpected PanicMessage"), + bug!("Unexpected PanicInfo"), } } } -impl fmt::Debug for PanicMessage { +impl fmt::Debug for PanicInfo { 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 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum InterpError<'tcx> { /// The program panicked. - Panic(PanicMessage), + Panic(PanicInfo), /// The program caused undefined behavior. UndefinedBehaviour(UndefinedBehaviourInfo), /// The program did something the interpreter does not support (some of these *might* be UB diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index c4a3bbfc28b..4b09da87d31 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -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 @@ macro_rules! err_exhaust { 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, }; diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 50f16858c04..1e2ec08301c 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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 @@ fn super_fold_with>(&self, folder: &mut F) -> Self { } } 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 @@ fn super_visit_with>(&self, visitor: &mut V) -> bool { } 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), diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 7562981f94f..ee4ecb6762c 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -514,7 +514,7 @@ fn super_terminator_kind(&mut self, 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); diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 18611c3e167..006ebcbdec6 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -2,7 +2,7 @@ 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 @@ fn codegen_assert_terminator<'b>( // 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 @@ fn codegen_assert_terminator<'b>( // 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(); diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 92774bbb7a6..2be39799b52 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -733,8 +733,8 @@ fn visit_terminator_entry( 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); } diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index aa9e68bd7de..631a8142113 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -207,8 +207,8 @@ fn visit_terminator_kind( 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); } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 50c0640f885..f10d505fe89 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -26,7 +26,7 @@ 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 @@ fn check_terminator( 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) } diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 7a428a2ec9f..7005f274e0e 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -4,7 +4,7 @@ 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}; diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 92daf06e6f8..ec061e74535 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -7,7 +7,7 @@ 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 @@ fn expr_as_rvalue( block, Operand::Move(is_min), false, - PanicMessage::OverflowNeg, + PanicInfo::OverflowNeg, expr_span, ); } @@ -401,7 +401,7 @@ pub fn build_binary_op( 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 @@ pub fn build_binary_op( // 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); diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index f943ff67c08..9605395b84b 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -7,7 +7,7 @@ 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 @@ pub fn hook_fn( 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 @@ pub fn hook_fn( 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); } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index b7dbc838458..14b92f2b3d4 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -136,7 +136,7 @@ pub(super) fn eval_terminator( 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)?) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 9918356d355..ec8a33f7a43 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -13,7 +13,7 @@ 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 @@ fn const_prop( ) } 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 @@ fn visit_terminator( .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"); diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 5461a2e470c..94bb70e10aa 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -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, };