rename memory::Kind to memory::MemoryKind

This commit is contained in:
Oliver Schneider 2017-08-09 14:53:22 +02:00
parent bba753deac
commit 81f5de7f05
9 changed files with 48 additions and 48 deletions

View File

@ -16,7 +16,7 @@ use super::{
use tls::MemoryExt;
use super::memory::Kind;
use super::memory::MemoryKind;
pub trait EvalContextExt<'tcx> {
fn call_c_abi(
@ -113,7 +113,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
self.write_null(dest, dest_ty)?;
} else {
let align = self.memory.pointer_size();
let ptr = self.memory.allocate(size, align, Kind::C.into())?;
let ptr = self.memory.allocate(size, align, MemoryKind::C.into())?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
}
@ -121,7 +121,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
"free" => {
let ptr = args[0].into_ptr(&mut self.memory)?;
if !ptr.is_null()? {
self.memory.deallocate(ptr.to_ptr()?, None, Kind::C.into())?;
self.memory.deallocate(ptr.to_ptr()?, None, MemoryKind::C.into())?;
}
}
@ -251,7 +251,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
}
if let Some(old) = success {
if let Some(var) = old {
self.memory.deallocate(var, None, Kind::Env.into())?;
self.memory.deallocate(var, None, MemoryKind::Env.into())?;
}
self.write_null(dest, dest_ty)?;
} else {
@ -274,12 +274,12 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
}
if let Some((name, value)) = new {
// +1 for the null terminator
let value_copy = self.memory.allocate((value.len() + 1) as u64, 1, Kind::Env.into())?;
let value_copy = self.memory.allocate((value.len() + 1) as u64, 1, MemoryKind::Env.into())?;
self.memory.write_bytes(value_copy.into(), &value)?;
let trailing_zero_ptr = value_copy.offset(value.len() as u64, &self)?.into();
self.memory.write_bytes(trailing_zero_ptr, &[0])?;
if let Some(var) = self.machine_data.env_vars.insert(name.to_owned(), value_copy) {
self.memory.deallocate(var, None, Kind::Env.into())?;
self.memory.deallocate(var, None, MemoryKind::Env.into())?;
}
self.write_null(dest, dest_ty)?;
} else {
@ -501,7 +501,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
if !align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(align));
}
let ptr = self.memory.allocate(size, align, Kind::Rust.into())?;
let ptr = self.memory.allocate(size, align, MemoryKind::Rust.into())?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
"alloc::heap::::__rust_alloc_zeroed" => {
@ -513,7 +513,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
if !align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(align));
}
let ptr = self.memory.allocate(size, align, Kind::Rust.into())?;
let ptr = self.memory.allocate(size, align, MemoryKind::Rust.into())?;
self.memory.write_repeat(ptr.into(), 0, size)?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
@ -527,7 +527,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
if !align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(align));
}
self.memory.deallocate(ptr, Some((old_size, align)), Kind::Rust.into())?;
self.memory.deallocate(ptr, Some((old_size, align)), MemoryKind::Rust.into())?;
}
"alloc::heap::::__rust_realloc" => {
let ptr = args[0].into_ptr(&mut self.memory)?.to_ptr()?;
@ -544,7 +544,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
if !new_align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(new_align));
}
let new_ptr = self.memory.reallocate(ptr, old_size, old_align, new_size, new_align, Kind::Rust.into())?;
let new_ptr = self.memory.reallocate(ptr, old_size, old_align, new_size, new_align, MemoryKind::Rust.into())?;
self.write_primval(dest, PrimVal::Ptr(new_ptr), dest_ty)?;
}

View File

@ -71,7 +71,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
// Return value
let size = ecx.tcx.data_layout.pointer_size.bytes();
let align = ecx.tcx.data_layout.pointer_align.abi();
let ret_ptr = ecx.memory_mut().allocate(size, align, Kind::Stack)?;
let ret_ptr = ecx.memory_mut().allocate(size, align, MemoryKind::Stack)?;
cleanup_ptr = Some(ret_ptr);
// Push our stack frame
@ -114,7 +114,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
while ecx.step()? {}
ecx.run_tls_dtors()?;
if let Some(cleanup_ptr) = cleanup_ptr {
ecx.memory_mut().deallocate(cleanup_ptr, None, Kind::Stack)?;
ecx.memory_mut().deallocate(cleanup_ptr, None, MemoryKind::Stack)?;
}
Ok(())
}
@ -161,7 +161,7 @@ struct MemoryData<'tcx> {
impl<'tcx> Machine<'tcx> for Evaluator {
type Data = EvaluatorData;
type MemoryData = MemoryData<'tcx>;
type MemoryKinds = memory::Kind;
type MemoryKinds = memory::MemoryKind;
/// Returns Ok() when the function was handled, fail otherwise
fn eval_fn_call<'a>(
@ -198,8 +198,8 @@ impl<'tcx> Machine<'tcx> for Evaluator {
ecx.ptr_op(bin_op, left, left_ty, right, right_ty)
}
fn mark_static_initialized(m: memory::Kind) -> EvalResult<'tcx> {
use memory::Kind::*;
fn mark_static_initialized(m: memory::MemoryKind) -> EvalResult<'tcx> {
use memory::MemoryKind::*;
match m {
// FIXME: This could be allowed, but not for env vars set during miri execution
Env => err!(Unimplemented("statics can't refer to env vars".to_owned())),
@ -218,7 +218,7 @@ impl<'tcx> Machine<'tcx> for Evaluator {
Ok(PrimVal::Bytes(align.into()))
} else {
ecx.memory
.allocate(size, align, Kind::Machine(memory::Kind::Rust))
.allocate(size, align, MemoryKind::Machine(memory::MemoryKind::Rust))
.map(PrimVal::Ptr)
}
}

View File

@ -1,6 +1,6 @@
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum Kind {
pub enum MemoryKind {
/// Error if deallocated any other way than `rust_deallocate`
Rust,
/// Error if deallocated any other way than `free`
@ -9,8 +9,8 @@ pub enum Kind {
Env,
}
impl Into<::rustc_miri::interpret::Kind<Kind>> for Kind {
fn into(self) -> ::rustc_miri::interpret::Kind<Kind> {
::rustc_miri::interpret::Kind::Machine(self)
impl Into<::rustc_miri::interpret::MemoryKind<MemoryKind>> for MemoryKind {
fn into(self) -> ::rustc_miri::interpret::MemoryKind<MemoryKind> {
::rustc_miri::interpret::MemoryKind::Machine(self)
}
}

View File

@ -10,7 +10,7 @@ use super::{
GlobalId, Lvalue, Value,
PrimVal,
EvalContext, StackPopCleanup, PtrAndAlign,
Kind,
MemoryKind,
};
use rustc_const_math::ConstInt;
@ -33,7 +33,7 @@ pub fn eval_body_as_primval<'a, 'tcx>(
if !ecx.globals.contains_key(&cid) {
let size = ecx.type_size_with_substs(mir.return_ty, instance.substs)?.expect("unsized global");
let align = ecx.type_align_with_substs(mir.return_ty, instance.substs)?;
let ptr = ecx.memory.allocate(size, align, Kind::UninitializedStatic)?;
let ptr = ecx.memory.allocate(size, align, MemoryKind::UninitializedStatic)?;
let aligned = !ecx.is_packed(mir.return_ty)?;
ecx.globals.insert(cid, PtrAndAlign { ptr: ptr.into(), aligned });
let mutable = !mir.return_ty.is_freeze(

View File

@ -20,7 +20,7 @@ use super::{
EvalError, EvalResult, EvalErrorKind,
GlobalId, Lvalue, LvalueExtra,
Memory, MemoryPointer, HasMemory,
Kind as MemoryKind,
MemoryKind,
operator,
PrimVal, PrimValKind, Value, Pointer,
ValidationQuery,

View File

@ -151,7 +151,7 @@ pub struct Allocation<M> {
/// Use the `mark_static_initalized` method of `Memory` to ensure that an error occurs, if the memory of this
/// allocation is modified or deallocated in the future.
/// Helps guarantee that stack allocations aren't deallocated via `rust_deallocate`
pub kind: Kind<M>,
pub kind: MemoryKind<M>,
/// Memory regions that are locked by some function
locks: RangeMap<LockInfo>,
}
@ -172,7 +172,7 @@ impl<M> Allocation<M> {
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum Kind<T> {
pub enum MemoryKind<T> {
/// Error if deallocated except during a stack pop
Stack,
/// Static in the process of being initialized.
@ -302,7 +302,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
return Ok(MemoryPointer::new(alloc_id, 0));
}
let ptr = self.allocate(bytes.len() as u64, 1, Kind::UninitializedStatic)?;
let ptr = self.allocate(bytes.len() as u64, 1, MemoryKind::UninitializedStatic)?;
self.write_bytes(ptr.into(), bytes)?;
self.mark_static_initalized(ptr.alloc_id, Mutability::Immutable)?;
self.literal_alloc_cache.insert(bytes.to_vec(), ptr.alloc_id);
@ -313,7 +313,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
&mut self,
size: u64,
align: u64,
kind: Kind<M::MemoryKinds>,
kind: MemoryKind<M::MemoryKinds>,
) -> EvalResult<'tcx, MemoryPointer> {
assert_ne!(align, 0);
assert!(align.is_power_of_two());
@ -349,7 +349,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
old_align: u64,
new_size: u64,
new_align: u64,
kind: Kind<M::MemoryKinds>,
kind: MemoryKind<M::MemoryKinds>,
) -> EvalResult<'tcx, MemoryPointer> {
use std::cmp::min;
@ -374,7 +374,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
&mut self,
ptr: MemoryPointer,
size_and_align: Option<(u64, u64)>,
kind: Kind<M::MemoryKinds>,
kind: MemoryKind<M::MemoryKinds>,
) -> EvalResult<'tcx> {
if ptr.offset != 0 {
return err!(DeallocateNonBasePtr);
@ -753,11 +753,11 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
}
let immutable = match (alloc.kind, alloc.mutable) {
(Kind::UninitializedStatic, _) => " (static in the process of initialization)".to_owned(),
(Kind::Static, Mutability::Mutable) => " (static mut)".to_owned(),
(Kind::Static, Mutability::Immutable) => " (immutable)".to_owned(),
(Kind::Machine(m), _) => format!(" ({:?})", m),
(Kind::Stack, _) => " (stack)".to_owned(),
(MemoryKind::UninitializedStatic, _) => " (static in the process of initialization)".to_owned(),
(MemoryKind::Static, Mutability::Mutable) => " (static mut)".to_owned(),
(MemoryKind::Static, Mutability::Immutable) => " (immutable)".to_owned(),
(MemoryKind::Machine(m), _) => format!(" ({:?})", m),
(MemoryKind::Stack, _) => " (stack)".to_owned(),
};
trace!("{}({} bytes, alignment {}){}", msg, alloc.bytes.len(), alloc.align, immutable);
@ -784,7 +784,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
let leaks: Vec<_> = self.alloc_map
.iter()
.filter_map(|(&key, val)| {
if val.kind != Kind::Static {
if val.kind != MemoryKind::Static {
Some(AllocIdKind::Runtime(key).into_alloc_id())
} else {
None
@ -856,7 +856,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
/// mark an allocation pointed to by a static as static and initialized
pub fn mark_inner_allocation(&mut self, alloc: AllocId, mutability: Mutability) -> EvalResult<'tcx> {
// relocations into other statics are not "inner allocations"
if self.get(alloc).ok().map_or(false, |alloc| alloc.kind != Kind::UninitializedStatic) {
if self.get(alloc).ok().map_or(false, |alloc| alloc.kind != MemoryKind::UninitializedStatic) {
self.mark_static_initalized(alloc, mutability)?;
}
Ok(())
@ -876,16 +876,16 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
match *kind {
// const eval results can refer to "locals".
// E.g. `const Foo: &u32 = &1;` refers to the temp local that stores the `1`
Kind::Stack |
MemoryKind::Stack |
// The entire point of this function
Kind::UninitializedStatic => {},
Kind::Machine(m) => M::mark_static_initialized(m)?,
Kind::Static => {
MemoryKind::UninitializedStatic => {},
MemoryKind::Machine(m) => M::mark_static_initialized(m)?,
MemoryKind::Static => {
trace!("mark_static_initalized: skipping already initialized static referred to by static currently being initialized");
return Ok(());
},
}
*kind = Kind::Static;
*kind = MemoryKind::Static;
*mutable = mutability;
// take out the relocations vector to free the borrow on self, so we can call
// mark recursively

View File

@ -46,7 +46,7 @@ pub use self::memory::{
AllocId,
Memory,
MemoryPointer,
Kind,
MemoryKind,
HasMemory,
};

View File

@ -15,7 +15,7 @@ use super::{
EvalResult,
EvalContext, StackPopCleanup, TyAndPacked, PtrAndAlign,
GlobalId, Lvalue,
HasMemory, Kind,
HasMemory, MemoryKind,
Machine,
};
@ -179,7 +179,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
// FIXME: check that it's `#[linkage = "extern_weak"]`
trace!("Initializing an extern global with NULL");
let ptr_size = self.memory.pointer_size();
let ptr = self.memory.allocate(ptr_size, ptr_size, Kind::UninitializedStatic)?;
let ptr = self.memory.allocate(ptr_size, ptr_size, MemoryKind::UninitializedStatic)?;
self.memory.write_usize(ptr, 0)?;
self.memory.mark_static_initalized(ptr.alloc_id, mutability)?;
self.globals.insert(cid, PtrAndAlign { ptr: ptr.into(), aligned: true });
@ -188,7 +188,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
let mir = self.load_mir(instance.def)?;
let size = self.type_size_with_substs(mir.return_ty, substs)?.expect("unsized global");
let align = self.type_align_with_substs(mir.return_ty, substs)?;
let ptr = self.memory.allocate(size, align, Kind::UninitializedStatic)?;
let ptr = self.memory.allocate(size, align, MemoryKind::UninitializedStatic)?;
let aligned = !self.is_packed(mir.return_ty)?;
self.globals.insert(cid, PtrAndAlign { ptr: ptr.into(), aligned });
let internally_mutable = !mir.return_ty.is_freeze(
@ -265,7 +265,7 @@ impl<'a, 'b, 'tcx, M: Machine<'tcx>> Visitor<'tcx> for ConstantExtractor<'a, 'b,
self.try(|this| {
let size = this.ecx.type_size_with_substs(mir.return_ty, this.instance.substs)?.expect("unsized global");
let align = this.ecx.type_align_with_substs(mir.return_ty, this.instance.substs)?;
let ptr = this.ecx.memory.allocate(size, align, Kind::UninitializedStatic)?;
let ptr = this.ecx.memory.allocate(size, align, MemoryKind::UninitializedStatic)?;
let aligned = !this.ecx.is_packed(mir.return_ty)?;
this.ecx.globals.insert(cid, PtrAndAlign { ptr: ptr.into(), aligned });
trace!("pushing stack frame for {:?}", index);

View File

@ -8,7 +8,7 @@ use syntax::ast::{self, Mutability};
use super::{
EvalResult,
EvalContext, eval_context,
MemoryPointer, Kind,
MemoryPointer, MemoryKind,
Value, PrimVal,
Machine,
};
@ -51,7 +51,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
let ptr_size = self.memory.pointer_size();
let methods = ::rustc::traits::get_vtable_methods(self.tcx, trait_ref);
let vtable = self.memory.allocate(ptr_size * (3 + methods.count() as u64), ptr_size, Kind::UninitializedStatic)?;
let vtable = self.memory.allocate(ptr_size * (3 + methods.count() as u64), ptr_size, MemoryKind::UninitializedStatic)?;
let drop = eval_context::resolve_drop_in_place(self.tcx, ty);
let drop = self.memory.create_fn_alloc(drop);