From 6def30ba6a4a3217f4571e5795ac8b3c269bbbb3 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 23 Oct 2018 18:32:50 +0200 Subject: [PATCH] Move the `memory_accessed` hook onto the `Extra` value --- src/librustc/mir/interpret/allocation.rs | 30 ++++++++++++++++++++++++ src/librustc/mir/interpret/mod.rs | 2 +- src/librustc_mir/interpret/machine.rs | 20 ---------------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index 8444cf5726f8..cf38116b0b47 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -40,6 +40,36 @@ pub struct Allocation { pub extra: Extra, } +trait AllocationExtra { + /// 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, + _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, + _size: Size, + ) -> EvalResult<'tcx> { + Ok(()) + } +} + impl Allocation { /// Creates a read-only allocation initialized by the given bytes pub fn from_bytes(slice: &[u8], align: Align) -> Self { diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 2821000ccad6..282104f78427 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -26,7 +26,7 @@ pub use self::error::{ pub use self::value::{Scalar, ConstValue}; -pub use self::allocation::Allocation; +pub use self::allocation::{Allocation, MemoryAccess}; use std::fmt; use mir; diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 27cf28ef41e8..7e42fd97c569 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -174,26 +174,6 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized { dest: PlaceTy<'tcx, Self::PointerTag>, ) -> EvalResult<'tcx>; - /// Hook for performing extra checks on a memory read access. - #[inline] - fn memory_read( - _alloc: &Allocation, - _ptr: Pointer, - _size: Size, - ) -> EvalResult<'tcx> { - Ok(()) - } - - /// Hook for performing extra checks on a memory write access. - #[inline] - fn memory_written( - _alloc: &mut Allocation, - _ptr: Pointer, - _size: Size, - ) -> EvalResult<'tcx> { - Ok(()) - } - /// Hook for performing extra checks when memory gets deallocated. #[inline] fn memory_deallocated(