Skip to content

Commit 990d8aa

Browse files
committed
Auto merge of rust-lang#50967 - oli-obk:miri_api_refactor, r=eddyb
Miri api refactor r? @eddyb cc @Zoxc based on rust-lang#50916
2 parents 9823cb9 + 5f599bb commit 990d8aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1068
-988
lines changed

src/librustc/ich/impls_ty.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@ for ::mir::interpret::ConstValue<'gcx> {
394394
mem::discriminant(self).hash_stable(hcx, hasher);
395395

396396
match *self {
397-
ByVal(val) => {
397+
Scalar(val) => {
398398
val.hash_stable(hcx, hasher);
399399
}
400-
ByValPair(a, b) => {
400+
ScalarPair(a, b) => {
401401
a.hash_stable(hcx, hasher);
402402
b.hash_stable(hcx, hasher);
403403
}
@@ -410,12 +410,12 @@ for ::mir::interpret::ConstValue<'gcx> {
410410
}
411411

412412
impl_stable_hash_for!(enum mir::interpret::Value {
413-
ByVal(v),
414-
ByValPair(a, b),
413+
Scalar(v),
414+
ScalarPair(a, b),
415415
ByRef(ptr, align)
416416
});
417417

418-
impl_stable_hash_for!(struct mir::interpret::MemoryPointer {
418+
impl_stable_hash_for!(struct mir::interpret::Pointer {
419419
alloc_id,
420420
offset
421421
});
@@ -473,13 +473,24 @@ impl_stable_hash_for!(enum ::syntax::ast::Mutability {
473473
Mutable
474474
});
475475

476-
impl_stable_hash_for!(struct mir::interpret::Pointer{primval});
477476

478-
impl_stable_hash_for!(enum mir::interpret::PrimVal {
479-
Bytes(b),
480-
Ptr(p),
481-
Undef
482-
});
477+
impl<'a> HashStable<StableHashingContext<'a>>
478+
for ::mir::interpret::Scalar {
479+
fn hash_stable<W: StableHasherResult>(&self,
480+
hcx: &mut StableHashingContext<'a>,
481+
hasher: &mut StableHasher<W>) {
482+
use mir::interpret::Scalar::*;
483+
484+
mem::discriminant(self).hash_stable(hcx, hasher);
485+
match *self {
486+
Bits { bits, defined } => {
487+
bits.hash_stable(hcx, hasher);
488+
defined.hash_stable(hcx, hasher);
489+
},
490+
Ptr(ptr) => ptr.hash_stable(hcx, hasher),
491+
}
492+
}
493+
}
483494

484495
impl_stable_hash_for!(struct ty::Const<'tcx> {
485496
ty,

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#![feature(trusted_len)]
6969
#![feature(catch_expr)]
7070
#![feature(test)]
71+
#![feature(in_band_lifetimes)]
7172

7273
#![recursion_limit="512"]
7374

src/librustc/mir/interpret/error.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ty::{FnSig, Ty, layout};
55
use ty::layout::{Size, Align};
66

77
use super::{
8-
MemoryPointer, Lock, AccessKind
8+
Pointer, Lock, AccessKind
99
};
1010

1111
use backtrace::Backtrace;
@@ -38,15 +38,15 @@ pub enum EvalErrorKind<'tcx, O> {
3838
MachineError(String),
3939
FunctionPointerTyMismatch(FnSig<'tcx>, FnSig<'tcx>),
4040
NoMirFor(String),
41-
UnterminatedCString(MemoryPointer),
41+
UnterminatedCString(Pointer),
4242
DanglingPointerDeref,
4343
DoubleFree,
4444
InvalidMemoryAccess,
4545
InvalidFunctionPointer,
4646
InvalidBool,
4747
InvalidDiscriminant,
4848
PointerOutOfBounds {
49-
ptr: MemoryPointer,
49+
ptr: Pointer,
5050
access: bool,
5151
allocation_size: Size,
5252
},
@@ -76,26 +76,26 @@ pub enum EvalErrorKind<'tcx, O> {
7676
has: Align,
7777
},
7878
MemoryLockViolation {
79-
ptr: MemoryPointer,
79+
ptr: Pointer,
8080
len: u64,
8181
frame: usize,
8282
access: AccessKind,
8383
lock: Lock,
8484
},
8585
MemoryAcquireConflict {
86-
ptr: MemoryPointer,
86+
ptr: Pointer,
8787
len: u64,
8888
kind: AccessKind,
8989
lock: Lock,
9090
},
9191
InvalidMemoryLockRelease {
92-
ptr: MemoryPointer,
92+
ptr: Pointer,
9393
len: u64,
9494
frame: usize,
9595
lock: Lock,
9696
},
9797
DeallocatedLockedMemory {
98-
ptr: MemoryPointer,
98+
ptr: Pointer,
9999
lock: Lock,
100100
},
101101
ValidationFailure(String),

src/librustc/mir/interpret/mod.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod value;
1010

1111
pub use self::error::{EvalError, EvalResult, EvalErrorKind, AssertMessage};
1212

13-
pub use self::value::{PrimVal, PrimValKind, Value, Pointer, ConstValue};
13+
pub use self::value::{Scalar, Value, ConstValue};
1414

1515
use std::fmt;
1616
use mir;
@@ -110,42 +110,49 @@ impl<T: layout::HasDataLayout> PointerArithmetic for T {}
110110

111111

112112
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
113-
pub struct MemoryPointer {
113+
pub struct Pointer {
114114
pub alloc_id: AllocId,
115115
pub offset: Size,
116116
}
117117

118-
impl<'tcx> MemoryPointer {
118+
/// Produces a `Pointer` which points to the beginning of the Allocation
119+
impl From<AllocId> for Pointer {
120+
fn from(alloc_id: AllocId) -> Self {
121+
Pointer::new(alloc_id, Size::ZERO)
122+
}
123+
}
124+
125+
impl<'tcx> Pointer {
119126
pub fn new(alloc_id: AllocId, offset: Size) -> Self {
120-
MemoryPointer { alloc_id, offset }
127+
Pointer { alloc_id, offset }
121128
}
122129

123130
pub(crate) fn wrapping_signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> Self {
124-
MemoryPointer::new(
131+
Pointer::new(
125132
self.alloc_id,
126133
Size::from_bytes(cx.data_layout().wrapping_signed_offset(self.offset.bytes(), i)),
127134
)
128135
}
129136

130137
pub fn overflowing_signed_offset<C: HasDataLayout>(self, i: i128, cx: C) -> (Self, bool) {
131138
let (res, over) = cx.data_layout().overflowing_signed_offset(self.offset.bytes(), i);
132-
(MemoryPointer::new(self.alloc_id, Size::from_bytes(res)), over)
139+
(Pointer::new(self.alloc_id, Size::from_bytes(res)), over)
133140
}
134141

135142
pub(crate) fn signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> EvalResult<'tcx, Self> {
136-
Ok(MemoryPointer::new(
143+
Ok(Pointer::new(
137144
self.alloc_id,
138145
Size::from_bytes(cx.data_layout().signed_offset(self.offset.bytes(), i)?),
139146
))
140147
}
141148

142149
pub fn overflowing_offset<C: HasDataLayout>(self, i: Size, cx: C) -> (Self, bool) {
143150
let (res, over) = cx.data_layout().overflowing_offset(self.offset.bytes(), i.bytes());
144-
(MemoryPointer::new(self.alloc_id, Size::from_bytes(res)), over)
151+
(Pointer::new(self.alloc_id, Size::from_bytes(res)), over)
145152
}
146153

147154
pub fn offset<C: HasDataLayout>(self, i: Size, cx: C) -> EvalResult<'tcx, Self> {
148-
Ok(MemoryPointer::new(
155+
Ok(Pointer::new(
149156
self.alloc_id,
150157
Size::from_bytes(cx.data_layout().offset(self.offset.bytes(), i.bytes())?),
151158
))
@@ -355,7 +362,7 @@ pub struct Allocation {
355362

356363
impl Allocation {
357364
pub fn from_bytes(slice: &[u8], align: Align) -> Self {
358-
let mut undef_mask = UndefMask::new(Size::from_bytes(0));
365+
let mut undef_mask = UndefMask::new(Size::ZERO);
359366
undef_mask.grow(Size::from_bytes(slice.len() as u64), true);
360367
Self {
361368
bytes: slice.to_owned(),
@@ -467,7 +474,7 @@ impl UndefMask {
467474
pub fn new(size: Size) -> Self {
468475
let mut m = UndefMask {
469476
blocks: vec![],
470-
len: Size::from_bytes(0),
477+
len: Size::ZERO,
471478
};
472479
m.grow(size, false);
473480
m

0 commit comments

Comments
 (0)