Skip to content

Commit

Permalink
Wrap the miri ErrorKind in an Rc to reduce work in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 30, 2018
1 parent 7d7efa7 commit c70fd68
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ for ::mir::interpret::EvalError<'gcx> {
hasher: &mut StableHasher<W>) {
use mir::interpret::EvalErrorKind::*;

mem::discriminant(&self.kind).hash_stable(hcx, hasher);
mem::discriminant(&*self.kind).hash_stable(hcx, hasher);

match self.kind {
match *self.kind {
DanglingPointerDeref |
DoubleFree |
InvalidMemoryAccess |
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::error::Error;
use std::{fmt, env};
use std::rc::Rc;

use mir;
use ty::{FnSig, Ty, layout};
Expand All @@ -14,7 +15,7 @@ use backtrace::Backtrace;

#[derive(Debug, Clone)]
pub struct EvalError<'tcx> {
pub kind: EvalErrorKind<'tcx>,
pub kind: Rc<EvalErrorKind<'tcx>>,
pub backtrace: Option<Backtrace>,
}

Expand All @@ -25,7 +26,7 @@ impl<'tcx> From<EvalErrorKind<'tcx>> for EvalError<'tcx> {
_ => None
};
EvalError {
kind,
kind: Rc::new(kind),
backtrace,
}
}
Expand Down Expand Up @@ -131,7 +132,7 @@ pub type EvalResult<'tcx, T = ()> = Result<T, EvalError<'tcx>>;
impl<'tcx> Error for EvalError<'tcx> {
fn description(&self) -> &str {
use self::EvalErrorKind::*;
match self.kind {
match *self.kind {
MachineError(ref inner) => inner,
FunctionPointerTyMismatch(..) =>
"tried to call a function through a function pointer of a different type",
Expand Down Expand Up @@ -252,7 +253,7 @@ impl<'tcx> Error for EvalError<'tcx> {
impl<'tcx> fmt::Display for EvalError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::EvalErrorKind::*;
match self.kind {
match *self.kind {
PointerOutOfBounds { ptr, access, allocation_size } => {
write!(f, "{} at offset {}, outside bounds of allocation {} which has size {}",
if access { "memory access" } else { "pointer computed" },
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ impl<'a, 'tcx> Lift<'tcx> for interpret::EvalError<'a> {
type Lifted = interpret::EvalError<'tcx>;
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
use ::mir::interpret::EvalErrorKind::*;
let kind = match self.kind {
let kind = match *self.kind {
MachineError(ref err) => MachineError(err.clone()),
FunctionPointerTyMismatch(a, b) => FunctionPointerTyMismatch(
tcx.lift(&a)?,
Expand Down Expand Up @@ -712,7 +712,7 @@ impl<'a, 'tcx> Lift<'tcx> for interpret::EvalError<'a> {
TypeckError => TypeckError,
};
Some(interpret::EvalError {
kind,
kind: Rc::new(kind),
backtrace: self.backtrace.clone(),
})
}
Expand Down

0 comments on commit c70fd68

Please sign in to comment.