]> git.lizzy.rs Git - rust.git/commitdiff
Move the `memory_accessed` hook onto the `Extra` value
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 23 Oct 2018 16:32:50 +0000 (18:32 +0200)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 8 Nov 2018 13:52:02 +0000 (14:52 +0100)
src/librustc/mir/interpret/allocation.rs
src/librustc/mir/interpret/mod.rs
src/librustc_mir/interpret/machine.rs

index 8444cf5726f84002435ed14585ddc4a02c51baee..cf38116b0b472fb62aba4f46797eea134c7ae0e1 100644 (file)
@@ -40,6 +40,36 @@ pub struct Allocation<Tag=(),Extra=()> {
     pub extra: Extra,
 }
 
+trait AllocationExtra<Tag> {
+    /// Hook for performing extra checks on a memory read access.
+    ///
+    /// Takes read-only access to the allocation so we can keep all the memory read
+    /// operations take `&self`.  Use a `RefCell` in `AllocExtra` if you
+    /// need to mutate.
+    #[inline]
+    fn memory_read(
+        &self,
+        _ptr: Pointer<Self::PointerTag>,
+        _size: Size,
+    ) -> EvalResult<'tcx> {
+        Ok(())
+    }
+
+    /// Hook for performing extra checks on a memory write access.
+    ///
+    /// Takes read-only access to the allocation so we can keep all the memory read
+    /// operations take `&self`.  Use a `RefCell` in `AllocExtra` if you
+    /// need to mutate.
+    #[inline]
+    fn memory_written(
+        &mut self,
+        _ptr: Pointer<Self::PointerTag>,
+        _size: Size,
+    ) -> EvalResult<'tcx> {
+        Ok(())
+    }
+}
+
 impl<Tag, Extra: Default> Allocation<Tag, Extra> {
     /// Creates a read-only allocation initialized by the given bytes
     pub fn from_bytes(slice: &[u8], align: Align) -> Self {
index 2821000ccad69d64feff66594acd0167045bcd3c..282104f78427d46a8e5bb82c1972a19028ef02a0 100644 (file)
@@ -26,7 +26,7 @@ macro_rules! err {
 
 pub use self::value::{Scalar, ConstValue};
 
-pub use self::allocation::Allocation;
+pub use self::allocation::{Allocation, MemoryAccess};
 
 use std::fmt;
 use mir;
index 27cf28ef41e8ac3a261d2d0a0a1d01dd3cdc97b7..7e42fd97c569ccf0be292593d5523d35d3dc1961 100644 (file)
@@ -174,26 +174,6 @@ fn box_alloc(
         dest: PlaceTy<'tcx, Self::PointerTag>,
     ) -> EvalResult<'tcx>;
 
-    /// Hook for performing extra checks on a memory read access.
-    #[inline]
-    fn memory_read(
-        _alloc: &Allocation<Self::PointerTag, Self::AllocExtra>,
-        _ptr: Pointer<Self::PointerTag>,
-        _size: Size,
-    ) -> EvalResult<'tcx> {
-        Ok(())
-    }
-
-    /// Hook for performing extra checks on a memory write access.
-    #[inline]
-    fn memory_written(
-        _alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
-        _ptr: Pointer<Self::PointerTag>,
-        _size: Size,
-    ) -> EvalResult<'tcx> {
-        Ok(())
-    }
-
     /// Hook for performing extra checks when memory gets deallocated.
     #[inline]
     fn memory_deallocated(