Skip to content

Commit d62aa3e

Browse files
committed
move ScalarMaybeUndef into the miri engine
1 parent 392ea7a commit d62aa3e

File tree

11 files changed

+113
-113
lines changed

11 files changed

+113
-113
lines changed

src/librustc/ich/impls_ty.rs

-5
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,6 @@ for ::mir::interpret::ConstValue<'gcx> {
391391
}
392392
}
393393

394-
impl_stable_hash_for!(enum mir::interpret::ScalarMaybeUndef {
395-
Scalar(v),
396-
Undef
397-
});
398-
399394
impl_stable_hash_for!(struct mir::interpret::Pointer {
400395
alloc_id,
401396
offset

src/librustc/mir/interpret/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use self::error::{
2323
FrameInfo, ConstEvalResult,
2424
};
2525

26-
pub use self::value::{Scalar, ConstValue, ScalarMaybeUndef};
26+
pub use self::value::{Scalar, ConstValue};
2727

2828
use std::fmt;
2929
use mir;

src/librustc/mir/interpret/value.rs

-93
Original file line numberDiff line numberDiff line change
@@ -343,96 +343,3 @@ pub enum Scalar<Id=AllocId> {
343343
/// relocation and its associated offset together as a `Pointer` here.
344344
Ptr(Pointer<Id>),
345345
}
346-
347-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
348-
pub enum ScalarMaybeUndef<Id=AllocId> {
349-
Scalar(Scalar<Id>),
350-
Undef,
351-
}
352-
353-
impl From<Scalar> for ScalarMaybeUndef {
354-
#[inline(always)]
355-
fn from(s: Scalar) -> Self {
356-
ScalarMaybeUndef::Scalar(s)
357-
}
358-
}
359-
360-
impl<'tcx> ScalarMaybeUndef {
361-
#[inline]
362-
pub fn not_undef(self) -> EvalResult<'static, Scalar> {
363-
match self {
364-
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
365-
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
366-
}
367-
}
368-
369-
#[inline(always)]
370-
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer> {
371-
self.not_undef()?.to_ptr()
372-
}
373-
374-
#[inline(always)]
375-
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
376-
self.not_undef()?.to_bits(target_size)
377-
}
378-
379-
#[inline(always)]
380-
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
381-
self.not_undef()?.to_bool()
382-
}
383-
384-
#[inline(always)]
385-
pub fn to_char(self) -> EvalResult<'tcx, char> {
386-
self.not_undef()?.to_char()
387-
}
388-
389-
#[inline(always)]
390-
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
391-
self.not_undef()?.to_f32()
392-
}
393-
394-
#[inline(always)]
395-
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
396-
self.not_undef()?.to_f64()
397-
}
398-
399-
#[inline(always)]
400-
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
401-
self.not_undef()?.to_u8()
402-
}
403-
404-
#[inline(always)]
405-
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
406-
self.not_undef()?.to_u32()
407-
}
408-
409-
#[inline(always)]
410-
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
411-
self.not_undef()?.to_u64()
412-
}
413-
414-
#[inline(always)]
415-
pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> {
416-
self.not_undef()?.to_usize(cx)
417-
}
418-
419-
#[inline(always)]
420-
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
421-
self.not_undef()?.to_i8()
422-
}
423-
424-
#[inline(always)]
425-
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
426-
self.not_undef()?.to_i32()
427-
}
428-
429-
#[inline(always)]
430-
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
431-
self.not_undef()?.to_i64()
432-
}
433-
434-
#[inline(always)]
435-
pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> {
436-
self.not_undef()?.to_isize(cx)
437-
}
438-
}

src/librustc_mir/interpret/eval_context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ use rustc_data_structures::indexed_vec::IndexVec;
2525
use rustc::mir::interpret::{
2626
GlobalId, Scalar, FrameInfo, AllocId,
2727
EvalResult, EvalErrorKind,
28-
ScalarMaybeUndef,
2928
truncate, sign_extend,
3029
};
3130

3231
use syntax::source_map::{self, Span};
3332

3433
use super::{
35-
Value, Operand, MemPlace, MPlaceTy, Place,
34+
Value, Operand, MemPlace, MPlaceTy, Place, ScalarMaybeUndef,
3635
Memory, Machine
3736
};
3837

src/librustc_mir/interpret/memory.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ use std::ptr;
2121

2222
use rustc::ty::{self, Instance, query::TyCtxtAt};
2323
use rustc::ty::layout::{self, Align, TargetDataLayout, Size, HasDataLayout};
24-
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ConstValue, ScalarMaybeUndef, GlobalId,
24+
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ConstValue, GlobalId,
2525
EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
2626
truncate};
2727
pub use rustc::mir::interpret::{write_target_uint, read_target_uint};
2828
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
2929

3030
use syntax::ast::Mutability;
3131

32-
use super::Machine;
32+
use super::{Machine, ScalarMaybeUndef};
3333

3434
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
3535
pub enum MemoryKind<T> {

src/librustc_mir/interpret/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ pub use self::memory::{Memory, MemoryKind};
3434

3535
pub use self::machine::Machine;
3636

37-
pub use self::operand::{Value, ValTy, Operand, OpTy};
37+
pub use self::operand::{ScalarMaybeUndef, Value, ValTy, Operand, OpTy};

src/librustc_mir/interpret/operand.rs

+95-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,105 @@ use rustc::ty::layout::{self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerEx
1919

2020
use rustc::mir::interpret::{
2121
GlobalId, AllocId,
22-
ConstValue, Pointer, Scalar, ScalarMaybeUndef,
22+
ConstValue, Pointer, Scalar,
2323
EvalResult, EvalErrorKind
2424
};
2525
use super::{EvalContext, Machine, MemPlace, MPlaceTy, MemoryKind};
2626

27+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
28+
pub enum ScalarMaybeUndef<Id=AllocId> {
29+
Scalar(Scalar<Id>),
30+
Undef,
31+
}
32+
33+
impl From<Scalar> for ScalarMaybeUndef {
34+
#[inline(always)]
35+
fn from(s: Scalar) -> Self {
36+
ScalarMaybeUndef::Scalar(s)
37+
}
38+
}
39+
40+
impl<'tcx> ScalarMaybeUndef {
41+
#[inline]
42+
pub fn not_undef(self) -> EvalResult<'static, Scalar> {
43+
match self {
44+
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
45+
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
46+
}
47+
}
48+
49+
#[inline(always)]
50+
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer> {
51+
self.not_undef()?.to_ptr()
52+
}
53+
54+
#[inline(always)]
55+
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
56+
self.not_undef()?.to_bits(target_size)
57+
}
58+
59+
#[inline(always)]
60+
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
61+
self.not_undef()?.to_bool()
62+
}
63+
64+
#[inline(always)]
65+
pub fn to_char(self) -> EvalResult<'tcx, char> {
66+
self.not_undef()?.to_char()
67+
}
68+
69+
#[inline(always)]
70+
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
71+
self.not_undef()?.to_f32()
72+
}
73+
74+
#[inline(always)]
75+
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
76+
self.not_undef()?.to_f64()
77+
}
78+
79+
#[inline(always)]
80+
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
81+
self.not_undef()?.to_u8()
82+
}
83+
84+
#[inline(always)]
85+
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
86+
self.not_undef()?.to_u32()
87+
}
88+
89+
#[inline(always)]
90+
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
91+
self.not_undef()?.to_u64()
92+
}
93+
94+
#[inline(always)]
95+
pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> {
96+
self.not_undef()?.to_usize(cx)
97+
}
98+
99+
#[inline(always)]
100+
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
101+
self.not_undef()?.to_i8()
102+
}
103+
104+
#[inline(always)]
105+
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
106+
self.not_undef()?.to_i32()
107+
}
108+
109+
#[inline(always)]
110+
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
111+
self.not_undef()?.to_i64()
112+
}
113+
114+
#[inline(always)]
115+
pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> {
116+
self.not_undef()?.to_isize(cx)
117+
}
118+
}
119+
120+
27121
/// A `Value` represents a single immediate self-contained Rust value.
28122
///
29123
/// For optimization of a few very common cases, there is also a representation for a pair of

src/librustc_mir/interpret/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use rustc::ty::{self, Ty};
1919
use rustc::ty::layout::{self, Size, Align, LayoutOf, TyLayout, HasDataLayout};
2020

2121
use rustc::mir::interpret::{
22-
GlobalId, AllocId, Scalar, EvalResult, Pointer, ScalarMaybeUndef, PointerArithmetic
22+
GlobalId, AllocId, Scalar, EvalResult, Pointer, PointerArithmetic
2323
};
24-
use super::{EvalContext, Machine, Value, ValTy, Operand, OpTy, MemoryKind};
24+
use super::{EvalContext, Machine, Value, ValTy, ScalarMaybeUndef, Operand, OpTy, MemoryKind};
2525

2626
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
2727
pub struct MemPlace<Id=AllocId> {

src/librustc_mir/interpret/snapshot.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::mem;
1111
use rustc::ich::{StableHashingContext, StableHashingContextProvider};
1212
use rustc::mir;
1313
use rustc::mir::interpret::{
14-
AllocId, Pointer, Scalar, ScalarMaybeUndef,
14+
AllocId, Pointer, Scalar,
1515
Relocations, Allocation, UndefMask,
1616
EvalResult, EvalErrorKind,
1717
};
@@ -25,7 +25,7 @@ use syntax::ast::Mutability;
2525
use syntax::source_map::Span;
2626

2727
use super::eval_context::{LocalValue, StackPopCleanup};
28-
use super::{Frame, Memory, Operand, MemPlace, Place, Value};
28+
use super::{Frame, Memory, Operand, MemPlace, Place, Value, ScalarMaybeUndef};
2929
use const_eval::CompileTimeInterpreter;
3030

3131
#[derive(Default)]
@@ -193,6 +193,11 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for Scalar
193193
}
194194
}
195195

196+
impl_stable_hash_for!(enum ::interpret::ScalarMaybeUndef {
197+
Scalar(v),
198+
Undef
199+
});
200+
196201
impl_snapshot_for!(enum ScalarMaybeUndef {
197202
Scalar(s),
198203
Undef,

src/librustc_mir/interpret/validity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use rustc::ty::layout::{self, Size, Primitive};
1515
use rustc::ty::{self, Ty};
1616
use rustc_data_structures::fx::FxHashSet;
1717
use rustc::mir::interpret::{
18-
Scalar, AllocType, EvalResult, ScalarMaybeUndef, EvalErrorKind, PointerArithmetic
18+
Scalar, AllocType, EvalResult, EvalErrorKind, PointerArithmetic
1919
};
2020

2121
use super::{
22-
OpTy, Machine, EvalContext
22+
OpTy, Machine, EvalContext, ScalarMaybeUndef
2323
};
2424

2525
macro_rules! validation_failure{

src/librustc_mir/transform/const_prop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use rustc::mir::{NullOp, UnOp, StatementKind, Statement, BasicBlock, LocalKind};
1818
use rustc::mir::{TerminatorKind, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem};
1919
use rustc::mir::visit::{Visitor, PlaceContext};
2020
use rustc::mir::interpret::{
21-
ConstEvalErr, EvalErrorKind, ScalarMaybeUndef, Scalar, GlobalId, EvalResult
21+
ConstEvalErr, EvalErrorKind, Scalar, GlobalId, EvalResult
2222
};
2323
use rustc::ty::{TyCtxt, self, Instance};
24-
use interpret::{self, EvalContext, Value, OpTy, MemoryKind};
24+
use interpret::{self, EvalContext, Value, OpTy, MemoryKind, ScalarMaybeUndef};
2525
use const_eval::{CompileTimeInterpreter, eval_promoted, mk_borrowck_eval_cx};
2626
use transform::{MirPass, MirSource};
2727
use syntax::source_map::{Span, DUMMY_SP};

0 commit comments

Comments
 (0)