mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-18 10:38:11 +00:00
move ScalarMaybeUndef into the miri engine
This commit is contained in:
parent
392ea7ad53
commit
d62aa3e085
@ -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 {
|
impl_stable_hash_for!(struct mir::interpret::Pointer {
|
||||||
alloc_id,
|
alloc_id,
|
||||||
offset
|
offset
|
||||||
|
@ -23,7 +23,7 @@ pub use self::error::{
|
|||||||
FrameInfo, ConstEvalResult,
|
FrameInfo, ConstEvalResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::value::{Scalar, ConstValue, ScalarMaybeUndef};
|
pub use self::value::{Scalar, ConstValue};
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use mir;
|
use mir;
|
||||||
|
@ -343,96 +343,3 @@ pub enum Scalar<Id=AllocId> {
|
|||||||
/// relocation and its associated offset together as a `Pointer` here.
|
/// relocation and its associated offset together as a `Pointer` here.
|
||||||
Ptr(Pointer<Id>),
|
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::{
|
use rustc::mir::interpret::{
|
||||||
GlobalId, Scalar, FrameInfo, AllocId,
|
GlobalId, Scalar, FrameInfo, AllocId,
|
||||||
EvalResult, EvalErrorKind,
|
EvalResult, EvalErrorKind,
|
||||||
ScalarMaybeUndef,
|
|
||||||
truncate, sign_extend,
|
truncate, sign_extend,
|
||||||
};
|
};
|
||||||
|
|
||||||
use syntax::source_map::{self, Span};
|
use syntax::source_map::{self, Span};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
Value, Operand, MemPlace, MPlaceTy, Place,
|
Value, Operand, MemPlace, MPlaceTy, Place, ScalarMaybeUndef,
|
||||||
Memory, Machine
|
Memory, Machine
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ use std::ptr;
|
|||||||
|
|
||||||
use rustc::ty::{self, Instance, query::TyCtxtAt};
|
use rustc::ty::{self, Instance, query::TyCtxtAt};
|
||||||
use rustc::ty::layout::{self, Align, TargetDataLayout, Size, HasDataLayout};
|
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,
|
EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
|
||||||
truncate};
|
truncate};
|
||||||
pub use rustc::mir::interpret::{write_target_uint, read_target_uint};
|
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 syntax::ast::Mutability;
|
||||||
|
|
||||||
use super::Machine;
|
use super::{Machine, ScalarMaybeUndef};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
|
||||||
pub enum MemoryKind<T> {
|
pub enum MemoryKind<T> {
|
||||||
|
@ -34,4 +34,4 @@ pub use self::memory::{Memory, MemoryKind};
|
|||||||
|
|
||||||
pub use self::machine::Machine;
|
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::{
|
use rustc::mir::interpret::{
|
||||||
GlobalId, AllocId,
|
GlobalId, AllocId,
|
||||||
ConstValue, Pointer, Scalar, ScalarMaybeUndef,
|
ConstValue, Pointer, Scalar,
|
||||||
EvalResult, EvalErrorKind
|
EvalResult, EvalErrorKind
|
||||||
};
|
};
|
||||||
use super::{EvalContext, Machine, MemPlace, MPlaceTy, MemoryKind};
|
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.
|
/// 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
|
/// 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::ty::layout::{self, Size, Align, LayoutOf, TyLayout, HasDataLayout};
|
||||||
|
|
||||||
use rustc::mir::interpret::{
|
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)]
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||||
pub struct MemPlace<Id=AllocId> {
|
pub struct MemPlace<Id=AllocId> {
|
||||||
|
@ -11,7 +11,7 @@ use std::mem;
|
|||||||
use rustc::ich::{StableHashingContext, StableHashingContextProvider};
|
use rustc::ich::{StableHashingContext, StableHashingContextProvider};
|
||||||
use rustc::mir;
|
use rustc::mir;
|
||||||
use rustc::mir::interpret::{
|
use rustc::mir::interpret::{
|
||||||
AllocId, Pointer, Scalar, ScalarMaybeUndef,
|
AllocId, Pointer, Scalar,
|
||||||
Relocations, Allocation, UndefMask,
|
Relocations, Allocation, UndefMask,
|
||||||
EvalResult, EvalErrorKind,
|
EvalResult, EvalErrorKind,
|
||||||
};
|
};
|
||||||
@ -25,7 +25,7 @@ use syntax::ast::Mutability;
|
|||||||
use syntax::source_map::Span;
|
use syntax::source_map::Span;
|
||||||
|
|
||||||
use super::eval_context::{LocalValue, StackPopCleanup};
|
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;
|
use const_eval::CompileTimeInterpreter;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[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 {
|
impl_snapshot_for!(enum ScalarMaybeUndef {
|
||||||
Scalar(s),
|
Scalar(s),
|
||||||
Undef,
|
Undef,
|
||||||
|
@ -15,11 +15,11 @@ use rustc::ty::layout::{self, Size, Primitive};
|
|||||||
use rustc::ty::{self, Ty};
|
use rustc::ty::{self, Ty};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc::mir::interpret::{
|
use rustc::mir::interpret::{
|
||||||
Scalar, AllocType, EvalResult, ScalarMaybeUndef, EvalErrorKind, PointerArithmetic
|
Scalar, AllocType, EvalResult, EvalErrorKind, PointerArithmetic
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
OpTy, Machine, EvalContext
|
OpTy, Machine, EvalContext, ScalarMaybeUndef
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! validation_failure{
|
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::{TerminatorKind, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem};
|
||||||
use rustc::mir::visit::{Visitor, PlaceContext};
|
use rustc::mir::visit::{Visitor, PlaceContext};
|
||||||
use rustc::mir::interpret::{
|
use rustc::mir::interpret::{
|
||||||
ConstEvalErr, EvalErrorKind, ScalarMaybeUndef, Scalar, GlobalId, EvalResult
|
ConstEvalErr, EvalErrorKind, Scalar, GlobalId, EvalResult
|
||||||
};
|
};
|
||||||
use rustc::ty::{TyCtxt, self, Instance};
|
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 const_eval::{CompileTimeInterpreter, eval_promoted, mk_borrowck_eval_cx};
|
||||||
use transform::{MirPass, MirSource};
|
use transform::{MirPass, MirSource};
|
||||||
use syntax::source_map::{Span, DUMMY_SP};
|
use syntax::source_map::{Span, DUMMY_SP};
|
||||||
|
Loading…
Reference in New Issue
Block a user