]> git.lizzy.rs Git - rust.git/commitdiff
rename `memory::Kind` to `memory::MemoryKind`
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 9 Aug 2017 12:53:22 +0000 (14:53 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 9 Aug 2017 12:53:22 +0000 (14:53 +0200)
miri/fn_call.rs
miri/lib.rs
miri/memory.rs
src/librustc_mir/interpret/const_eval.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/mod.rs
src/librustc_mir/interpret/step.rs
src/librustc_mir/interpret/traits.rs

index 8b07b577bdda54fbe32c611e3b72b3281f7f11be..26263a854dd036472f41f365fe12da2ff6ce629e 100644 (file)
@@ -16,7 +16,7 @@
 
 use tls::MemoryExt;
 
-use super::memory::Kind;
+use super::memory::MemoryKind;
 
 pub trait EvalContextExt<'tcx> {
     fn call_c_abi(
@@ -113,7 +113,7 @@ fn call_c_abi(
                     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 @@ fn call_c_abi(
             "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 @@ fn call_c_abi(
                 }
                 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 @@ fn call_c_abi(
                 }
                 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 @@ fn call_missing_fn(
                 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 @@ fn call_missing_fn(
                 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 @@ fn call_missing_fn(
                 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 @@ fn call_missing_fn(
                 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)?;
             }
 
index 1dc1682b17f350a0a4be460bddc4c700a368296d..c93b938e9bd5a3fecdcb6171cba2595fcb133e43 100644 (file)
@@ -71,7 +71,7 @@ fn run_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 @@ fn run_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 @@ fn try_ptr_op<'a>(
         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 @@ fn box_alloc<'a>(
             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)
         }
     }
index 55e6026280ca5cd2a3805093203f86103512e63b..110540c0cf1d2555c7e9436ae3ffb7d7272d3f17 100644 (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)
     }
 }
index 525a17ae59cbc6800485597ff8521405cd97f652..f11734a588a179d13f3e1ff0a4857043149e2149 100644 (file)
@@ -10,7 +10,7 @@
     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(
index eb6e33a52f64753c2aacb9b349151cc6500adb85..fd609d5fec1c82d4f0389aa1b0430fa2bf1f8d43 100644 (file)
@@ -20,7 +20,7 @@
     EvalError, EvalResult, EvalErrorKind,
     GlobalId, Lvalue, LvalueExtra,
     Memory, MemoryPointer, HasMemory,
-    Kind as MemoryKind,
+    MemoryKind,
     operator,
     PrimVal, PrimValKind, Value, Pointer,
     ValidationQuery,
index 1ea814d57141b3f31bfd0378a0982b4320d9b008..33644d64902dd3df1972046759f35469610d77c8 100644 (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 @@ fn check_locks<'tcx>(&self, frame: Option<usize>, offset: u64, len: u64, access:
 }
 
 #[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 @@ pub fn allocate_cached(&mut self, bytes: &[u8]) -> EvalResult<'tcx, MemoryPointe
             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 @@ pub fn allocate(
         &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 @@ pub fn reallocate(
         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 @@ pub fn deallocate(
         &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 @@ pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
             }
 
             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 @@ pub fn leak_report(&self) -> usize {
         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 @@ pub fn mark_static_initalized(&mut self, alloc_id: AllocId, mutability: Mutabili
                 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
index a4c317056118f9064616f5455b8f809b26eba4f8..392724757ebeccee68356205a461caafbd5d9fab 100644 (file)
@@ -46,7 +46,7 @@ macro_rules! err {
     AllocId,
     Memory,
     MemoryPointer,
-    Kind,
+    MemoryKind,
     HasMemory,
 };
 
index e275a4e0a35ced30a4cfb9526485e2e4fab4c548..a85d8d05c3269ad4e3fc32b3ec75008017b82f86 100644 (file)
@@ -15,7 +15,7 @@
     EvalResult,
     EvalContext, StackPopCleanup, TyAndPacked, PtrAndAlign,
     GlobalId, Lvalue,
-    HasMemory, Kind,
+    HasMemory, MemoryKind,
     Machine,
 };
 
@@ -179,7 +179,7 @@ fn global_item(
             // 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 @@ fn global_item(
         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 @@ fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: mir::Loca
                 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);
index a1821e58a996ffe82dbe5f953773994006a8863f..3b642591917b342a5428dede84eda456d8e1b75e 100644 (file)
@@ -8,7 +8,7 @@
 use super::{
     EvalResult,
     EvalContext, eval_context,
-    MemoryPointer, Kind,
+    MemoryPointer, MemoryKind,
     Value, PrimVal,
     Machine,
 };
@@ -51,7 +51,7 @@ pub fn get_vtable(&mut self, ty: Ty<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) ->
 
         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);