Skip to content

Commit

Permalink
Give AllocationExtras access to their entire Allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Nov 8, 2018
1 parent 769ee79 commit 5d58a03
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/librustc/mir/interpret/allocation.rs
Expand Up @@ -49,21 +49,17 @@ pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Default + Clone {
/// need to mutate.
#[inline]
fn memory_read(
&self,
_alloc: &Allocation<Tag, Self>,
_ptr: Pointer<Tag>,
_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,
_alloc: &mut Allocation<Tag, Self>,
_ptr: Pointer<Tag>,
_size: Size,
) -> EvalResult<'tcx> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/interpret/memory.rs
Expand Up @@ -637,7 +637,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
}

let alloc = self.get(ptr.alloc_id)?;
AllocationExtra::memory_read(&alloc.extra, ptr, size)?;
AllocationExtra::memory_read(alloc, ptr, size)?;

assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
assert_eq!(size.bytes() as usize as u64, size.bytes());
Expand Down Expand Up @@ -683,7 +683,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
self.clear_relocations(ptr, size)?;

let alloc = self.get_mut(ptr.alloc_id)?;
AllocationExtra::memory_written(&mut alloc.extra, ptr, size)?;
AllocationExtra::memory_written(alloc, ptr, size)?;

assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
assert_eq!(size.bytes() as usize as u64, size.bytes());
Expand Down

0 comments on commit 5d58a03

Please sign in to comment.