Skip to content

Commit 6def30b

Browse files
committed
Move the memory_accessed hook onto the Extra value
1 parent 48f6941 commit 6def30b

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,36 @@ pub struct Allocation<Tag=(),Extra=()> {
4040
pub extra: Extra,
4141
}
4242

43+
trait AllocationExtra<Tag> {
44+
/// Hook for performing extra checks on a memory read access.
45+
///
46+
/// Takes read-only access to the allocation so we can keep all the memory read
47+
/// operations take `&self`. Use a `RefCell` in `AllocExtra` if you
48+
/// need to mutate.
49+
#[inline]
50+
fn memory_read(
51+
&self,
52+
_ptr: Pointer<Self::PointerTag>,
53+
_size: Size,
54+
) -> EvalResult<'tcx> {
55+
Ok(())
56+
}
57+
58+
/// Hook for performing extra checks on a memory write access.
59+
///
60+
/// Takes read-only access to the allocation so we can keep all the memory read
61+
/// operations take `&self`. Use a `RefCell` in `AllocExtra` if you
62+
/// need to mutate.
63+
#[inline]
64+
fn memory_written(
65+
&mut self,
66+
_ptr: Pointer<Self::PointerTag>,
67+
_size: Size,
68+
) -> EvalResult<'tcx> {
69+
Ok(())
70+
}
71+
}
72+
4373
impl<Tag, Extra: Default> Allocation<Tag, Extra> {
4474
/// Creates a read-only allocation initialized by the given bytes
4575
pub fn from_bytes(slice: &[u8], align: Align) -> Self {

src/librustc/mir/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use self::error::{
2626

2727
pub use self::value::{Scalar, ConstValue};
2828

29-
pub use self::allocation::Allocation;
29+
pub use self::allocation::{Allocation, MemoryAccess};
3030

3131
use std::fmt;
3232
use mir;

src/librustc_mir/interpret/machine.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,26 +174,6 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
174174
dest: PlaceTy<'tcx, Self::PointerTag>,
175175
) -> EvalResult<'tcx>;
176176

177-
/// Hook for performing extra checks on a memory read access.
178-
#[inline]
179-
fn memory_read(
180-
_alloc: &Allocation<Self::PointerTag, Self::AllocExtra>,
181-
_ptr: Pointer<Self::PointerTag>,
182-
_size: Size,
183-
) -> EvalResult<'tcx> {
184-
Ok(())
185-
}
186-
187-
/// Hook for performing extra checks on a memory write access.
188-
#[inline]
189-
fn memory_written(
190-
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
191-
_ptr: Pointer<Self::PointerTag>,
192-
_size: Size,
193-
) -> EvalResult<'tcx> {
194-
Ok(())
195-
}
196-
197177
/// Hook for performing extra checks when memory gets deallocated.
198178
#[inline]
199179
fn memory_deallocated(

0 commit comments

Comments
 (0)