move ScalarMaybeUndef into the miri engine
This commit is contained in:
parent
392ea7ad53
commit
d62aa3e085
11 changed files with 113 additions and 113 deletions
|
@ -391,11 +391,6 @@ for ::mir::interpret::ConstValue<'gcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(enum mir::interpret::ScalarMaybeUndef {
|
||||
Scalar(v),
|
||||
Undef
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct mir::interpret::Pointer {
|
||||
alloc_id,
|
||||
offset
|
||||
|
|
|
@ -23,7 +23,7 @@ pub use self::error::{
|
|||
FrameInfo, ConstEvalResult,
|
||||
};
|
||||
|
||||
pub use self::value::{Scalar, ConstValue, ScalarMaybeUndef};
|
||||
pub use self::value::{Scalar, ConstValue};
|
||||
|
||||
use std::fmt;
|
||||
use mir;
|
||||
|
|
|
@ -343,96 +343,3 @@ pub enum Scalar<Id=AllocId> {
|
|||
/// relocation and its associated offset together as a `Pointer` here.
|
||||
Ptr(Pointer<Id>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
|
||||
pub enum ScalarMaybeUndef<Id=AllocId> {
|
||||
Scalar(Scalar<Id>),
|
||||
Undef,
|
||||
}
|
||||
|
||||
impl From<Scalar> for ScalarMaybeUndef {
|
||||
#[inline(always)]
|
||||
fn from(s: Scalar) -> Self {
|
||||
ScalarMaybeUndef::Scalar(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ScalarMaybeUndef {
|
||||
#[inline]
|
||||
pub fn not_undef(self) -> EvalResult<'static, Scalar> {
|
||||
match self {
|
||||
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
|
||||
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer> {
|
||||
self.not_undef()?.to_ptr()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
|
||||
self.not_undef()?.to_bits(target_size)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
|
||||
self.not_undef()?.to_bool()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_char(self) -> EvalResult<'tcx, char> {
|
||||
self.not_undef()?.to_char()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
|
||||
self.not_undef()?.to_f32()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
|
||||
self.not_undef()?.to_f64()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
|
||||
self.not_undef()?.to_u8()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
|
||||
self.not_undef()?.to_u32()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
|
||||
self.not_undef()?.to_u64()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> {
|
||||
self.not_undef()?.to_usize(cx)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
|
||||
self.not_undef()?.to_i8()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
|
||||
self.not_undef()?.to_i32()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
|
||||
self.not_undef()?.to_i64()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> {
|
||||
self.not_undef()?.to_isize(cx)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,14 +25,13 @@ use rustc_data_structures::indexed_vec::IndexVec;
|
|||
use rustc::mir::interpret::{
|
||||
GlobalId, Scalar, FrameInfo, AllocId,
|
||||
EvalResult, EvalErrorKind,
|
||||
ScalarMaybeUndef,
|
||||
truncate, sign_extend,
|
||||
};
|
||||
|
||||
use syntax::source_map::{self, Span};
|
||||
|
||||
use super::{
|
||||
Value, Operand, MemPlace, MPlaceTy, Place,
|
||||
Value, Operand, MemPlace, MPlaceTy, Place, ScalarMaybeUndef,
|
||||
Memory, Machine
|
||||
};
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ use std::ptr;
|
|||
|
||||
use rustc::ty::{self, Instance, query::TyCtxtAt};
|
||||
use rustc::ty::layout::{self, Align, TargetDataLayout, Size, HasDataLayout};
|
||||
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ConstValue, ScalarMaybeUndef, GlobalId,
|
||||
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ConstValue, GlobalId,
|
||||
EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
|
||||
truncate};
|
||||
pub use rustc::mir::interpret::{write_target_uint, read_target_uint};
|
||||
|
@ -29,7 +29,7 @@ use rustc_data_structures::fx::{FxHashSet, FxHashMap};
|
|||
|
||||
use syntax::ast::Mutability;
|
||||
|
||||
use super::Machine;
|
||||
use super::{Machine, ScalarMaybeUndef};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
|
||||
pub enum MemoryKind<T> {
|
||||
|
|
|
@ -34,4 +34,4 @@ pub use self::memory::{Memory, MemoryKind};
|
|||
|
||||
pub use self::machine::Machine;
|
||||
|
||||
pub use self::operand::{Value, ValTy, Operand, OpTy};
|
||||
pub use self::operand::{ScalarMaybeUndef, Value, ValTy, Operand, OpTy};
|
||||
|
|
|
@ -19,11 +19,105 @@ use rustc::ty::layout::{self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerEx
|
|||
|
||||
use rustc::mir::interpret::{
|
||||
GlobalId, AllocId,
|
||||
ConstValue, Pointer, Scalar, ScalarMaybeUndef,
|
||||
ConstValue, Pointer, Scalar,
|
||||
EvalResult, EvalErrorKind
|
||||
};
|
||||
use super::{EvalContext, Machine, MemPlace, MPlaceTy, MemoryKind};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
|
||||
pub enum ScalarMaybeUndef<Id=AllocId> {
|
||||
Scalar(Scalar<Id>),
|
||||
Undef,
|
||||
}
|
||||
|
||||
impl From<Scalar> for ScalarMaybeUndef {
|
||||
#[inline(always)]
|
||||
fn from(s: Scalar) -> Self {
|
||||
ScalarMaybeUndef::Scalar(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ScalarMaybeUndef {
|
||||
#[inline]
|
||||
pub fn not_undef(self) -> EvalResult<'static, Scalar> {
|
||||
match self {
|
||||
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
|
||||
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer> {
|
||||
self.not_undef()?.to_ptr()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
|
||||
self.not_undef()?.to_bits(target_size)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
|
||||
self.not_undef()?.to_bool()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_char(self) -> EvalResult<'tcx, char> {
|
||||
self.not_undef()?.to_char()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
|
||||
self.not_undef()?.to_f32()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
|
||||
self.not_undef()?.to_f64()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
|
||||
self.not_undef()?.to_u8()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
|
||||
self.not_undef()?.to_u32()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
|
||||
self.not_undef()?.to_u64()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> {
|
||||
self.not_undef()?.to_usize(cx)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
|
||||
self.not_undef()?.to_i8()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
|
||||
self.not_undef()?.to_i32()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
|
||||
self.not_undef()?.to_i64()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> {
|
||||
self.not_undef()?.to_isize(cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A `Value` represents a single immediate self-contained Rust value.
|
||||
///
|
||||
/// For optimization of a few very common cases, there is also a representation for a pair of
|
||||
|
|
|
@ -19,9 +19,9 @@ use rustc::ty::{self, Ty};
|
|||
use rustc::ty::layout::{self, Size, Align, LayoutOf, TyLayout, HasDataLayout};
|
||||
|
||||
use rustc::mir::interpret::{
|
||||
GlobalId, AllocId, Scalar, EvalResult, Pointer, ScalarMaybeUndef, PointerArithmetic
|
||||
GlobalId, AllocId, Scalar, EvalResult, Pointer, PointerArithmetic
|
||||
};
|
||||
use super::{EvalContext, Machine, Value, ValTy, Operand, OpTy, MemoryKind};
|
||||
use super::{EvalContext, Machine, Value, ValTy, ScalarMaybeUndef, Operand, OpTy, MemoryKind};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub struct MemPlace<Id=AllocId> {
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::mem;
|
|||
use rustc::ich::{StableHashingContext, StableHashingContextProvider};
|
||||
use rustc::mir;
|
||||
use rustc::mir::interpret::{
|
||||
AllocId, Pointer, Scalar, ScalarMaybeUndef,
|
||||
AllocId, Pointer, Scalar,
|
||||
Relocations, Allocation, UndefMask,
|
||||
EvalResult, EvalErrorKind,
|
||||
};
|
||||
|
@ -25,7 +25,7 @@ use syntax::ast::Mutability;
|
|||
use syntax::source_map::Span;
|
||||
|
||||
use super::eval_context::{LocalValue, StackPopCleanup};
|
||||
use super::{Frame, Memory, Operand, MemPlace, Place, Value};
|
||||
use super::{Frame, Memory, Operand, MemPlace, Place, Value, ScalarMaybeUndef};
|
||||
use const_eval::CompileTimeInterpreter;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -193,6 +193,11 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for Scalar
|
|||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(enum ::interpret::ScalarMaybeUndef {
|
||||
Scalar(v),
|
||||
Undef
|
||||
});
|
||||
|
||||
impl_snapshot_for!(enum ScalarMaybeUndef {
|
||||
Scalar(s),
|
||||
Undef,
|
||||
|
|
|
@ -15,11 +15,11 @@ use rustc::ty::layout::{self, Size, Primitive};
|
|||
use rustc::ty::{self, Ty};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc::mir::interpret::{
|
||||
Scalar, AllocType, EvalResult, ScalarMaybeUndef, EvalErrorKind, PointerArithmetic
|
||||
Scalar, AllocType, EvalResult, EvalErrorKind, PointerArithmetic
|
||||
};
|
||||
|
||||
use super::{
|
||||
OpTy, Machine, EvalContext
|
||||
OpTy, Machine, EvalContext, ScalarMaybeUndef
|
||||
};
|
||||
|
||||
macro_rules! validation_failure{
|
||||
|
|
|
@ -18,10 +18,10 @@ use rustc::mir::{NullOp, UnOp, StatementKind, Statement, BasicBlock, LocalKind};
|
|||
use rustc::mir::{TerminatorKind, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem};
|
||||
use rustc::mir::visit::{Visitor, PlaceContext};
|
||||
use rustc::mir::interpret::{
|
||||
ConstEvalErr, EvalErrorKind, ScalarMaybeUndef, Scalar, GlobalId, EvalResult
|
||||
ConstEvalErr, EvalErrorKind, Scalar, GlobalId, EvalResult
|
||||
};
|
||||
use rustc::ty::{TyCtxt, self, Instance};
|
||||
use interpret::{self, EvalContext, Value, OpTy, MemoryKind};
|
||||
use interpret::{self, EvalContext, Value, OpTy, MemoryKind, ScalarMaybeUndef};
|
||||
use const_eval::{CompileTimeInterpreter, eval_promoted, mk_borrowck_eval_cx};
|
||||
use transform::{MirPass, MirSource};
|
||||
use syntax::source_map::{Span, DUMMY_SP};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue