Skip to content

Commit 769ee79

Browse files
committed
Fallout
1 parent 00e524c commit 769ee79

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

Diff for: src/librustc/mir/interpret/allocation.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
//! The virtual memory representation of the MIR interpreter
1212
13+
use super::{Pointer, EvalResult, AllocId};
14+
1315
use ty::layout::{Size, Align};
1416
use syntax::ast::Mutability;
15-
use rustc_target::abi::HasDataLayout;
1617
use std::iter;
1718
use mir;
1819
use std::ops::{Deref, DerefMut};
@@ -40,7 +41,7 @@ pub struct Allocation<Tag=(),Extra=()> {
4041
pub extra: Extra,
4142
}
4243

43-
trait AllocationExtra<Tag> {
44+
pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Default + Clone {
4445
/// Hook for performing extra checks on a memory read access.
4546
///
4647
/// Takes read-only access to the allocation so we can keep all the memory read
@@ -49,7 +50,7 @@ trait AllocationExtra<Tag> {
4950
#[inline]
5051
fn memory_read(
5152
&self,
52-
_ptr: Pointer<Self::PointerTag>,
53+
_ptr: Pointer<Tag>,
5354
_size: Size,
5455
) -> EvalResult<'tcx> {
5556
Ok(())
@@ -63,13 +64,15 @@ trait AllocationExtra<Tag> {
6364
#[inline]
6465
fn memory_written(
6566
&mut self,
66-
_ptr: Pointer<Self::PointerTag>,
67+
_ptr: Pointer<Tag>,
6768
_size: Size,
6869
) -> EvalResult<'tcx> {
6970
Ok(())
7071
}
7172
}
7273

74+
impl AllocationExtra<()> for () {}
75+
7376
impl<Tag, Extra: Default> Allocation<Tag, Extra> {
7477
/// Creates a read-only allocation initialized by the given bytes
7578
pub fn from_bytes(slice: &[u8], align: Align) -> Self {

Diff for: src/librustc_mir/interpret/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc::mir;
2020
use rustc::ty::{self, layout::{Size, TyLayout}, query::TyCtxtAt};
2121

2222
use super::{
23-
Allocation, AllocId, EvalResult, Scalar,
23+
Allocation, AllocId, EvalResult, Scalar, AllocationExtra,
2424
EvalContext, PlaceTy, MPlaceTy, OpTy, Pointer, MemoryKind,
2525
};
2626

@@ -78,7 +78,7 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
7878
type PointerTag: ::std::fmt::Debug + Default + Copy + Eq + Hash + 'static;
7979

8080
/// Extra data stored in every allocation.
81-
type AllocExtra: ::std::fmt::Debug + Default + Clone;
81+
type AllocExtra: AllocationExtra<Self::PointerTag>;
8282

8383
/// Memory's allocation map
8484
type MemoryMap:

Diff for: src/librustc_mir/interpret/memory.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_data_structures::fx::{FxHashSet, FxHashMap};
2828
use syntax::ast::Mutability;
2929

3030
use super::{
31-
Pointer, AllocId, Allocation, ConstValue, GlobalId,
31+
Pointer, AllocId, Allocation, ConstValue, GlobalId, AllocationExtra,
3232
EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
3333
Machine, AllocMap, MayLeak, ScalarMaybeUndef, ErrorHandled,
3434
};
@@ -637,7 +637,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
637637
}
638638

639639
let alloc = self.get(ptr.alloc_id)?;
640-
M::memory_read(alloc, ptr, size)?;
640+
AllocationExtra::memory_read(&alloc.extra, ptr, size)?;
641641

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

685685
let alloc = self.get_mut(ptr.alloc_id)?;
686-
M::memory_written(alloc, ptr, size)?;
686+
AllocationExtra::memory_written(&mut alloc.extra, ptr, size)?;
687687

688688
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
689689
assert_eq!(size.bytes() as usize as u64, size.bytes());

Diff for: src/librustc_mir/interpret/place.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::mir::interpret::{
2424
GlobalId, AllocId, Allocation, Scalar, EvalResult, Pointer, PointerArithmetic
2525
};
2626
use super::{
27-
EvalContext, Machine, AllocMap,
27+
EvalContext, Machine, AllocMap, AllocationExtra,
2828
Immediate, ImmTy, ScalarMaybeUndef, Operand, OpTy, MemoryKind
2929
};
3030

@@ -264,6 +264,7 @@ where
264264
Tag: ::std::fmt::Debug+Default+Copy+Eq+Hash+'static,
265265
M: Machine<'a, 'mir, 'tcx, PointerTag=Tag>,
266266
M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKinds>, Allocation<Tag, M::AllocExtra>)>,
267+
M::AllocExtra: AllocationExtra<Tag>,
267268
{
268269
/// Take a value, which represents a (thin or fat) reference, and make it a place.
269270
/// Alignment is just based on the type. This is the inverse of `create_ref`.

Diff for: src/librustc_mir/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::ty::layout::{self, Size, Align, TyLayout, LayoutOf};
1717
use rustc::ty;
1818
use rustc_data_structures::fx::FxHashSet;
1919
use rustc::mir::interpret::{
20-
Scalar, AllocType, EvalResult, EvalErrorKind
20+
Scalar, AllocType, EvalResult, EvalErrorKind,
2121
};
2222

2323
use super::{

0 commit comments

Comments
 (0)