Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
saleemjaffer committed Aug 1, 2019
1 parent c17d11f commit 0c4513e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 40 deletions.
71 changes: 40 additions & 31 deletions src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
//! An interpreter for MIR used in CTFE and by miri

#[macro_export]
macro_rules! throw_unsup {
($($tt:tt)*) => { return Err(err_unsup!($($tt)*).into()) };
}

#[macro_export]
macro_rules! throw_inval {
($($tt:tt)*) => { return Err(err_inval!($($tt)*).into()) };
}

#[macro_export]
macro_rules! throw_ub {
macro_rules! err_unsup {
($($tt:tt)*) => {
return Err($crate::mir::interpret::InterpError::UndefinedBehaviour(
$crate::mir::interpret::UndefinedBehaviourInfo::$($tt)*
).into())
$crate::mir::interpret::InterpError::Unsupported(
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
)
};
}

#[macro_export]
macro_rules! throw_panic {
($($tt:tt)*) => { return Err(err_panic!($($tt)*).into()) };
}

#[macro_export]
macro_rules! throw_exhaust {
($($tt:tt)*) => { return Err(err_exhaust!($($tt)*).into()) };
}

#[macro_export]
macro_rules! err_inval {
($($tt:tt)*) => {
Expand All @@ -39,10 +19,19 @@ macro_rules! err_inval {
}

#[macro_export]
macro_rules! err_unsup {
macro_rules! err_ub {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::Unsupported(
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
$crate::mir::interpret::InterpError::UndefinedBehaviour(
$crate::mir::interpret::UndefinedBehaviourInfo::$($tt)*
)
};
}

#[macro_export]
macro_rules! err_panic {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::Panic(
$crate::mir::interpret::PanicInfo::$($tt)*
)
};
}
Expand All @@ -57,14 +46,34 @@ macro_rules! err_exhaust {
}

#[macro_export]
macro_rules! err_panic {
macro_rules! throw_unsup {
($($tt:tt)*) => { return Err(err_unsup!($($tt)*).into()) };
}

#[macro_export]
macro_rules! throw_inval {
($($tt:tt)*) => { return Err(err_inval!($($tt)*).into()) };
}

#[macro_export]
macro_rules! throw_ub {
($($tt:tt)*) => {
$crate::mir::interpret::InterpError::Panic(
$crate::mir::interpret::PanicInfo::$($tt)*
)
return Err($crate::mir::interpret::InterpError::UndefinedBehaviour(
$crate::mir::interpret::UndefinedBehaviourInfo::$($tt)*
).into())
};
}

#[macro_export]
macro_rules! throw_panic {
($($tt:tt)*) => { return Err(err_panic!($($tt)*).into()) };
}

#[macro_export]
macro_rules! throw_exhaust {
($($tt:tt)*) => { return Err(err_exhaust!($($tt)*).into()) };
}

mod error;
mod value;
mod allocation;
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
self.tcx
.layout_of(self.param_env.and(ty))
.map_err(|layout| {
err_inval!(Layout(layout)).into()
})
.map_err(|layout| err_inval!(Layout(layout)).into())
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
use rustc::mir::interpret::InterpError::*;
match diagnostic.error {
Exit(_) => bug!("the CTFE program cannot exit"),
| Unsupported(_) => {},
| UndefinedBehaviour(_) => {},
| InvalidProgram(_) => {},
| ResourceExhaustion(_) => {},
| Panic(_)
=> {
Panic(_) => {
diagnostic.report_as_lint(
self.ecx.tcx,
"this expression will panic at runtime",
lint_root,
None,
);
}
_ => {},
}
None
},
Expand Down

0 comments on commit 0c4513e

Please sign in to comment.