Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miri api refactor #50967

Merged
merged 42 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9cc5d92
Add constant for `Size::from_bytes(0)`
oli-obk May 20, 2018
1606e13
Rename PrimVal to Scalar
oli-obk May 20, 2018
ef2177c
Rename ByVal(Pair) to Scalar(Pair)
oli-obk May 20, 2018
6436de8
Differentiate between interpret::Scalar and layout::Scalar
oli-obk May 20, 2018
03a92b6
Eliminate the `Pointer` wrapper type
oli-obk May 20, 2018
d732463
Rename MemoryPointer to Pointer
oli-obk May 20, 2018
3bbf2fd
Remove Pointer::zero in favor of Pointer::from
oli-obk May 20, 2018
64a75ec
change `Value::Bytes` to `Value::Bits`
oli-obk May 22, 2018
bf39c7f
Floats are scalars!
oli-obk May 22, 2018
4ca169c
Use the target types bitsize instead of the source type's
oli-obk May 22, 2018
9456ba6
Accidentally used byte-size instead of bit-size
oli-obk May 22, 2018
ea8f544
Rebase fallout
oli-obk May 22, 2018
edbdf3d
Formatting nit
oli-obk May 22, 2018
1550fd2
Use the destination type size instead of the source type size
oli-obk May 22, 2018
f82256e
primval -> scalar rename
oli-obk May 22, 2018
ff652b8
Update outdated comment
oli-obk May 22, 2018
0da702a
Remove an instance of `scalar_size` in a `Debug` impl
oli-obk May 22, 2018
cc60a22
Get rid of `scalar_size`
oli-obk May 23, 2018
c420531
Replace `ScalarKind` with `Primitive`
oli-obk May 23, 2018
97da01f
Remove the last mention of `Undef`
oli-obk May 24, 2018
98e5129
Better variable naming
oli-obk May 24, 2018
09a996b
Printing values should ignore whether bits are undefined
oli-obk May 24, 2018
bc3ba91
Printing a fn definition needs to know nothing about its ZST's value
oli-obk May 24, 2018
ca8c27e
Ensure llvm doesn't trigger an assert for crazy transmutes
oli-obk May 24, 2018
1a2964a
Simplify a ScalarPair creation
oli-obk May 24, 2018
c6d25dc
Don't ICE on horrible transmutes in pattern constants
oli-obk May 24, 2018
50628b7
Only defined bits are relevant
oli-obk May 24, 2018
cfd5fb5
Reuse `to_bits` instead of badly reinventing it
oli-obk May 24, 2018
879d8f7
Properly check defined bits range
oli-obk May 24, 2018
f1ea9ef
Remove `ty_to_primitive`
oli-obk May 24, 2018
1f9fa53
Sanity check the `bits` argument to the `from_bits` function
oli-obk May 24, 2018
569ae80
Wrongly named a closure `clamp` when it was doing truncation
oli-obk May 24, 2018
bdd23bf
`tcx.lift_to_global` > `tcx.global_tcx().lift`
oli-obk May 24, 2018
d0610fd
Add missing newlines
oli-obk May 24, 2018
6d513f7
Remove dead code
oli-obk May 24, 2018
80a1488
Prefer `to_value_with_len` over manual expanison of it
oli-obk May 24, 2018
5c8741f
Use in-band-lifetimes instead of unused explicit lifetimes
oli-obk May 24, 2018
85de4ef
Rename `amt` variables to `shift`
oli-obk May 24, 2018
fb9060a
Revert "Ensure llvm doesn't trigger an assert for crazy transmutes"
oli-obk May 24, 2018
eceeb63
Update comment
oli-obk May 25, 2018
50d3783
Sanity abort `to_bits` if used on zsts
oli-obk May 25, 2018
5f599bb
Adjust test for 32 bit targets
oli-obk May 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ for ::mir::interpret::ConstValue<'gcx> {
mem::discriminant(self).hash_stable(hcx, hasher);

match *self {
ByVal(val) => {
Scalar(val) => {
val.hash_stable(hcx, hasher);
}
ByValPair(a, b) => {
ScalarPair(a, b) => {
a.hash_stable(hcx, hasher);
b.hash_stable(hcx, hasher);
}
Expand All @@ -410,12 +410,12 @@ for ::mir::interpret::ConstValue<'gcx> {
}

impl_stable_hash_for!(enum mir::interpret::Value {
ByVal(v),
ByValPair(a, b),
Scalar(v),
ScalarPair(a, b),
ByRef(ptr, align)
});

impl_stable_hash_for!(struct mir::interpret::MemoryPointer {
impl_stable_hash_for!(struct mir::interpret::Pointer {
alloc_id,
offset
});
Expand Down Expand Up @@ -473,13 +473,24 @@ impl_stable_hash_for!(enum ::syntax::ast::Mutability {
Mutable
});

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

impl_stable_hash_for!(enum mir::interpret::PrimVal {
Bytes(b),
Ptr(p),
Undef
});
impl<'a> HashStable<StableHashingContext<'a>>
for ::mir::interpret::Scalar {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
use mir::interpret::Scalar::*;

mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
Bits { bits, defined } => {
bits.hash_stable(hcx, hasher);
defined.hash_stable(hcx, hasher);
},
Ptr(ptr) => ptr.hash_stable(hcx, hasher),
}
}
}

impl_stable_hash_for!(struct ty::Const<'tcx> {
ty,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#![feature(trusted_len)]
#![feature(catch_expr)]
#![feature(test)]
#![feature(in_band_lifetimes)]

#![recursion_limit="512"]

Expand Down
14 changes: 7 additions & 7 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ty::{FnSig, Ty, layout};
use ty::layout::{Size, Align};

use super::{
MemoryPointer, Lock, AccessKind
Pointer, Lock, AccessKind
};

use backtrace::Backtrace;
Expand Down Expand Up @@ -38,15 +38,15 @@ pub enum EvalErrorKind<'tcx, O> {
MachineError(String),
FunctionPointerTyMismatch(FnSig<'tcx>, FnSig<'tcx>),
NoMirFor(String),
UnterminatedCString(MemoryPointer),
UnterminatedCString(Pointer),
DanglingPointerDeref,
DoubleFree,
InvalidMemoryAccess,
InvalidFunctionPointer,
InvalidBool,
InvalidDiscriminant,
PointerOutOfBounds {
ptr: MemoryPointer,
ptr: Pointer,
access: bool,
allocation_size: Size,
},
Expand Down Expand Up @@ -76,26 +76,26 @@ pub enum EvalErrorKind<'tcx, O> {
has: Align,
},
MemoryLockViolation {
ptr: MemoryPointer,
ptr: Pointer,
len: u64,
frame: usize,
access: AccessKind,
lock: Lock,
},
MemoryAcquireConflict {
ptr: MemoryPointer,
ptr: Pointer,
len: u64,
kind: AccessKind,
lock: Lock,
},
InvalidMemoryLockRelease {
ptr: MemoryPointer,
ptr: Pointer,
len: u64,
frame: usize,
lock: Lock,
},
DeallocatedLockedMemory {
ptr: MemoryPointer,
ptr: Pointer,
lock: Lock,
},
ValidationFailure(String),
Expand Down
29 changes: 18 additions & 11 deletions src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod value;

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

pub use self::value::{PrimVal, PrimValKind, Value, Pointer, ConstValue};
pub use self::value::{Scalar, Value, ConstValue};

use std::fmt;
use mir;
Expand Down Expand Up @@ -110,42 +110,49 @@ impl<T: layout::HasDataLayout> PointerArithmetic for T {}


#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
pub struct MemoryPointer {
pub struct Pointer {
pub alloc_id: AllocId,
pub offset: Size,
}

impl<'tcx> MemoryPointer {
/// Produces a `Pointer` which points to the beginning of the Allocation
impl From<AllocId> for Pointer {
fn from(alloc_id: AllocId) -> Self {
Pointer::new(alloc_id, Size::ZERO)
}
}

impl<'tcx> Pointer {
pub fn new(alloc_id: AllocId, offset: Size) -> Self {
MemoryPointer { alloc_id, offset }
Pointer { alloc_id, offset }
}

pub(crate) fn wrapping_signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> Self {
MemoryPointer::new(
Pointer::new(
self.alloc_id,
Size::from_bytes(cx.data_layout().wrapping_signed_offset(self.offset.bytes(), i)),
)
}

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

pub(crate) fn signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> EvalResult<'tcx, Self> {
Ok(MemoryPointer::new(
Ok(Pointer::new(
self.alloc_id,
Size::from_bytes(cx.data_layout().signed_offset(self.offset.bytes(), i)?),
))
}

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

pub fn offset<C: HasDataLayout>(self, i: Size, cx: C) -> EvalResult<'tcx, Self> {
Ok(MemoryPointer::new(
Ok(Pointer::new(
self.alloc_id,
Size::from_bytes(cx.data_layout().offset(self.offset.bytes(), i.bytes())?),
))
Expand Down Expand Up @@ -355,7 +362,7 @@ pub struct Allocation {

impl Allocation {
pub fn from_bytes(slice: &[u8], align: Align) -> Self {
let mut undef_mask = UndefMask::new(Size::from_bytes(0));
let mut undef_mask = UndefMask::new(Size::ZERO);
undef_mask.grow(Size::from_bytes(slice.len() as u64), true);
Self {
bytes: slice.to_owned(),
Expand Down Expand Up @@ -467,7 +474,7 @@ impl UndefMask {
pub fn new(size: Size) -> Self {
let mut m = UndefMask {
blocks: vec![],
len: Size::from_bytes(0),
len: Size::ZERO,
};
m.grow(size, false);
m
Expand Down
Loading