Skip to content

Commit 936b567

Browse files
committed
Minimal changes to make miri work
1 parent 871c1de commit 936b567

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

compiler/rustc_const_eval/src/interpret/machine.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_target::spec::abi::Abi as CallAbi;
1616
use crate::const_eval::CheckAlignment;
1717

1818
use super::{
19-
AllocId, AllocRange, Allocation, AllocBytes, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult,
20-
MemoryKind, OpTy, Operand, PlaceTy, Pointer, Provenance, Scalar, StackPopUnwind,
19+
AllocBytes, AllocId, AllocRange, Allocation, ConstAllocation, Frame, ImmTy, InterpCx,
20+
InterpResult, MemoryKind, OpTy, Operand, PlaceTy, Pointer, Provenance, Scalar, StackPopUnwind,
2121
};
2222

2323
/// Data returned by Machine::stack_pop,
@@ -111,7 +111,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
111111
/// Memory's allocation map
112112
type MemoryMap: AllocMap<
113113
AllocId,
114-
(MemoryKind<Self::MemoryKind>, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>),
114+
(
115+
MemoryKind<Self::MemoryKind>,
116+
Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>,
117+
),
115118
> + Default
116119
+ Clone;
117120

compiler/rustc_const_eval/src/interpret/memory.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
581581
ptr: Pointer<Option<M::Provenance>>,
582582
size: Size,
583583
align: Align,
584-
) -> InterpResult<'tcx, Option<AllocRef<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>> {
584+
) -> InterpResult<'tcx, Option<AllocRef<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
585+
{
585586
let ptr_and_alloc = self.check_and_deref_ptr(
586587
ptr,
587588
size,
@@ -653,7 +654,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
653654
ptr: Pointer<Option<M::Provenance>>,
654655
size: Size,
655656
align: Align,
656-
) -> InterpResult<'tcx, Option<AllocRefMut<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>> {
657+
) -> InterpResult<'tcx, Option<AllocRefMut<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
658+
{
657659
let parts = self.get_ptr_access(ptr, size, align)?;
658660
if let Some((alloc_id, offset, prov)) = parts {
659661
let tcx = *self.tcx;
@@ -924,7 +926,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
924926
}
925927

926928
/// Reading and writing.
927-
impl<'tcx, 'a, Prov: Provenance, Extra, Bytes: AllocBytes> AllocRefMut<'a, 'tcx, Prov, Extra, Bytes> {
929+
impl<'tcx, 'a, Prov: Provenance, Extra, Bytes: AllocBytes>
930+
AllocRefMut<'a, 'tcx, Prov, Extra, Bytes>
931+
{
928932
/// `range` is relative to this allocation reference, not the base of the allocation.
929933
pub fn write_scalar(&mut self, range: AllocRange, val: Scalar<Prov>) -> InterpResult<'tcx> {
930934
let range = self.range.subrange(range);

compiler/rustc_const_eval/src/interpret/place.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ where
340340
pub(super) fn get_place_alloc(
341341
&self,
342342
place: &MPlaceTy<'tcx, M::Provenance>,
343-
) -> InterpResult<'tcx, Option<AllocRef<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>> {
343+
) -> InterpResult<'tcx, Option<AllocRef<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
344+
{
344345
assert!(place.layout.is_sized());
345346
assert!(!place.meta.has_meta());
346347
let size = place.layout.size;
@@ -351,7 +352,8 @@ where
351352
pub(super) fn get_place_alloc_mut(
352353
&mut self,
353354
place: &MPlaceTy<'tcx, M::Provenance>,
354-
) -> InterpResult<'tcx, Option<AllocRefMut<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>> {
355+
) -> InterpResult<'tcx, Option<AllocRefMut<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
356+
{
355357
assert!(place.layout.is_sized());
356358
assert!(!place.meta.has_meta());
357359
let size = place.layout.size;

compiler/rustc_middle/src/mir/interpret/allocation.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ pub use init_mask::{InitChunk, InitChunkIter};
3232

3333
/// Functionality required for the bytes of an `Allocation`.
3434
pub trait AllocBytes:
35-
Clone
36-
+ fmt::Debug
37-
+ Eq
38-
+ PartialEq
39-
+ Hash
40-
+ Deref<Target = [u8]>
41-
+ DerefMut<Target = [u8]>
35+
Clone + fmt::Debug + Eq + PartialEq + Hash + Deref<Target = [u8]> + DerefMut<Target = [u8]>
4236
{
4337
/// Adjust the bytes to the specified alignment -- by default, this is a no-op.
4438
fn adjust_to_align(self, _align: Align) -> Self;
@@ -271,11 +265,7 @@ impl AllocRange {
271265
// The constructors are all without extra; the extra gets added by a machine hook later.
272266
impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
273267
/// Creates an allocation from an existing `Bytes` value - this is needed for miri FFI support
274-
pub fn from_raw_bytes(
275-
bytes: Bytes,
276-
align: Align,
277-
mutability: Mutability,
278-
) -> Self {
268+
pub fn from_raw_bytes(bytes: Bytes, align: Align, mutability: Mutability) -> Self {
279269
let size = Size::from_bytes(bytes.len());
280270
Self {
281271
bytes,

compiler/rustc_middle/src/mir/interpret/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ pub use self::error::{
127127
pub use self::value::{get_slice_bytes, ConstAlloc, ConstValue, Scalar};
128128

129129
pub use self::allocation::{
130-
alloc_range, AllocBytes, AllocError, AllocRange, AllocResult, Allocation, ConstAllocation, InitChunk,
131-
InitChunkIter,
130+
alloc_range, AllocBytes, AllocError, AllocRange, AllocResult, Allocation, ConstAllocation,
131+
InitChunk, InitChunkIter,
132132
};
133133

134134
pub use self::pointer::{Pointer, PointerArithmetic, Provenance};

src/tools/miri/src/machine.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
771771

772772
type Provenance = Provenance;
773773
type ProvenanceExtra = ProvenanceExtra;
774+
type Bytes = Box<[u8]>;
774775

775776
type MemoryMap = MonoHashMap<
776777
AllocId,
777-
(MemoryKind<MiriMemoryKind>, Allocation<Provenance, Self::AllocExtra>),
778+
(MemoryKind<MiriMemoryKind>, Allocation<Provenance, Self::AllocExtra, Self::Bytes>),
778779
>;
779780

780781
const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global);

0 commit comments

Comments
 (0)