move MemoryData to memory.rs; remove all the Hashing stuff
This commit is contained in:
parent
72918c1a97
commit
d889da43f8
74
src/lib.rs
74
src/lib.rs
@ -18,14 +18,11 @@ use rustc::ty::layout::{TyLayout, LayoutOf, Size};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::mir;
|
||||
|
||||
use rustc_data_structures::fx::FxHasher;
|
||||
|
||||
use syntax::ast::Mutability;
|
||||
use syntax::attr;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub use rustc::mir::interpret::*;
|
||||
pub use rustc_mir::interpret::*;
|
||||
@ -43,7 +40,7 @@ use fn_call::EvalContextExt as MissingFnsEvalContextExt;
|
||||
use operator::EvalContextExt as OperatorEvalContextExt;
|
||||
use intrinsic::EvalContextExt as IntrinsicEvalContextExt;
|
||||
use tls::EvalContextExt as TlsEvalContextExt;
|
||||
use memory::MemoryKind as MiriMemoryKind;
|
||||
use memory::{MemoryKind as MiriMemoryKind, TlsKey, TlsEntry, MemoryData};
|
||||
use locks::LockInfo;
|
||||
use range_map::RangeMap;
|
||||
use helpers::FalibleScalarExt;
|
||||
@ -214,75 +211,12 @@ pub struct Evaluator<'tcx> {
|
||||
_dummy : PhantomData<&'tcx ()>,
|
||||
}
|
||||
|
||||
impl<'tcx> Hash for Evaluator<'tcx> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
let Evaluator {
|
||||
env_vars,
|
||||
_dummy: _,
|
||||
} = 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, 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<ty::Instance<'tcx>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct MemoryData<'tcx> {
|
||||
/// The Key to use for the next thread-local allocation.
|
||||
next_thread_local: TlsKey,
|
||||
|
||||
/// pthreads-style thread-local storage.
|
||||
thread_local: BTreeMap<TlsKey, TlsEntry<'tcx>>,
|
||||
|
||||
/// Memory regions that are locked by some function
|
||||
///
|
||||
/// Only mutable (static mut, heap, stack) allocations have an entry in this map.
|
||||
/// The entry is created when allocating the memory and deleted after deallocation.
|
||||
locks: HashMap<AllocId, RangeMap<LockInfo<'tcx>>>,
|
||||
}
|
||||
|
||||
impl<'tcx> MemoryData<'tcx> {
|
||||
fn new() -> Self {
|
||||
MemoryData {
|
||||
next_thread_local: 1, // start with 1 as we must not use 0 on Windows
|
||||
thread_local: BTreeMap::new(),
|
||||
locks: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Hash for MemoryData<'tcx> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
let MemoryData {
|
||||
next_thread_local: _,
|
||||
thread_local,
|
||||
locks: _,
|
||||
} = self;
|
||||
|
||||
thread_local.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
|
||||
type MemoryData = MemoryData<'tcx>;
|
||||
type MemoryData = memory::MemoryData<'tcx>;
|
||||
type MemoryKinds = memory::MemoryKind;
|
||||
|
||||
const MUT_STATIC_KIND: Option<memory::MemoryKind> = Some(memory::MemoryKind::MutStatic);
|
||||
const DETECT_LOOPS: bool = false;
|
||||
|
||||
/// Returns Ok() when the function was handled, fail otherwise
|
||||
fn find_fn<'a>(
|
||||
|
@ -1,4 +1,44 @@
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)]
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
|
||||
use rustc::ty;
|
||||
|
||||
use super::{AllocId, Scalar, LockInfo, RangeMap};
|
||||
|
||||
pub type TlsKey = u128;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct TlsEntry<'tcx> {
|
||||
pub(crate) data: Scalar, // Will eventually become a map from thread IDs to `Scalar`s, if we ever support more than one thread.
|
||||
pub(crate) dtor: Option<ty::Instance<'tcx>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct MemoryData<'tcx> {
|
||||
/// The Key to use for the next thread-local allocation.
|
||||
pub(crate) next_thread_local: TlsKey,
|
||||
|
||||
/// pthreads-style thread-local storage.
|
||||
pub(crate) thread_local: BTreeMap<TlsKey, TlsEntry<'tcx>>,
|
||||
|
||||
/// Memory regions that are locked by some function
|
||||
///
|
||||
/// Only mutable (static mut, heap, stack) allocations have an entry in this map.
|
||||
/// The entry is created when allocating the memory and deleted after deallocation.
|
||||
pub(crate) locks: HashMap<AllocId, RangeMap<LockInfo<'tcx>>>,
|
||||
}
|
||||
|
||||
impl<'tcx> MemoryData<'tcx> {
|
||||
pub(crate) fn new() -> Self {
|
||||
MemoryData {
|
||||
next_thread_local: 1, // start with 1 as we must not use 0 on Windows
|
||||
thread_local: BTreeMap::new(),
|
||||
locks: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum MemoryKind {
|
||||
/// `__rust_alloc` memory
|
||||
Rust,
|
||||
|
Loading…
x
Reference in New Issue
Block a user