diff --git a/src/lib.rs b/src/lib.rs index 88bca91aa2..75397262b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,10 +27,13 @@ use rustc::ty::subst::Subst; use rustc::hir::def_id::DefId; use rustc::mir; +use rustc_data_structures::fx::FxHasher; + use syntax::ast::Mutability; use syntax::codemap::Span; use std::collections::{HashMap, BTreeMap}; +use std::hash::{Hash, Hasher}; pub use rustc::mir::interpret::*; pub use rustc_mir::interpret::*; @@ -296,7 +299,7 @@ pub fn eval_main<'a, 'tcx: 'a>( } } -#[derive(Default)] +#[derive(Clone, Default, PartialEq, Eq)] pub struct Evaluator<'tcx> { /// Environment variables set by `setenv` /// Miri does not expose env vars from the host to the emulated program @@ -306,15 +309,34 @@ pub struct Evaluator<'tcx> { pub(crate) suspended: HashMap>>, } +impl<'tcx> Hash for Evaluator<'tcx> { + fn hash(&self, state: &mut H) { + let Evaluator { + env_vars, + suspended: _, + } = self; + + env_vars.iter() + .map(|(env, ptr)| { + let mut h = FxHasher::default(); + env.hash(&mut h); + ptr.hash(&mut h); + h.finish() + }) + .fold(0u64, |acc, hash| acc.wrapping_add(hash)) + .hash(state); + } +} + pub type TlsKey = u128; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub struct TlsEntry<'tcx> { data: Scalar, // Will eventually become a map from thread IDs to `Scalar`s, if we ever support more than one thread. dtor: Option>, } -#[derive(Default)] +#[derive(Clone, Default, PartialEq, Eq)] pub struct MemoryData<'tcx> { /// The Key to use for the next thread-local allocation. next_thread_local: TlsKey, @@ -331,6 +353,19 @@ pub struct MemoryData<'tcx> { statics: HashMap, AllocId>, } +impl<'tcx> Hash for MemoryData<'tcx> { + fn hash(&self, state: &mut H) { + let MemoryData { + next_thread_local: _, + thread_local, + locks: _, + statics: _, + } = self; + + thread_local.hash(state); + } +} + impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> { type MemoryData = MemoryData<'tcx>; type MemoryKinds = memory::MemoryKind; diff --git a/src/locks.rs b/src/locks.rs index 3b67c9bb7f..9f4126ad82 100644 --- a/src/locks.rs +++ b/src/locks.rs @@ -7,7 +7,7 @@ use rustc::ty::layout::Size; //////////////////////////////////////////////////////////////////////////////// /// Information about a lock that is currently held. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct LockInfo<'tcx> { /// Stores for which lifetimes (of the original write lock) we got /// which suspensions. diff --git a/src/range_map.rs b/src/range_map.rs index fcffaf7128..76d01ad19e 100644 --- a/src/range_map.rs +++ b/src/range_map.rs @@ -7,7 +7,7 @@ use std::collections::BTreeMap; use std::ops; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct RangeMap { map: BTreeMap, }