Skip to content

Commit 6099356

Browse files
committed
Move ScalarMaybeUndef back to rustc
1 parent 064515d commit 6099356

File tree

2 files changed

+115
-115
lines changed

2 files changed

+115
-115
lines changed

src/librustc/mir/interpret/mod.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,3 +696,117 @@ fn bit_index(bits: Size) -> (usize, usize) {
696696
assert_eq!(b as usize as u64, b);
697697
(a as usize, b as usize)
698698
}
699+
700+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
701+
pub enum ScalarMaybeUndef<Tag=(), Id=AllocId> {
702+
Scalar(Scalar<Tag, Id>),
703+
Undef,
704+
}
705+
706+
impl<Tag> From<Scalar<Tag>> for ScalarMaybeUndef<Tag> {
707+
#[inline(always)]
708+
fn from(s: Scalar<Tag>) -> Self {
709+
ScalarMaybeUndef::Scalar(s)
710+
}
711+
}
712+
713+
impl<'tcx> ScalarMaybeUndef<()> {
714+
#[inline]
715+
pub fn with_default_tag<Tag>(self) -> ScalarMaybeUndef<Tag>
716+
where Tag: Default
717+
{
718+
match self {
719+
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.with_default_tag()),
720+
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
721+
}
722+
}
723+
}
724+
725+
impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
726+
#[inline]
727+
pub fn erase_tag(self) -> ScalarMaybeUndef
728+
{
729+
match self {
730+
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.erase_tag()),
731+
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
732+
}
733+
}
734+
735+
#[inline]
736+
pub fn not_undef(self) -> EvalResult<'static, Scalar<Tag>> {
737+
match self {
738+
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
739+
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
740+
}
741+
}
742+
743+
#[inline(always)]
744+
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer<Tag>> {
745+
self.not_undef()?.to_ptr()
746+
}
747+
748+
#[inline(always)]
749+
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
750+
self.not_undef()?.to_bits(target_size)
751+
}
752+
753+
#[inline(always)]
754+
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
755+
self.not_undef()?.to_bool()
756+
}
757+
758+
#[inline(always)]
759+
pub fn to_char(self) -> EvalResult<'tcx, char> {
760+
self.not_undef()?.to_char()
761+
}
762+
763+
#[inline(always)]
764+
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
765+
self.not_undef()?.to_f32()
766+
}
767+
768+
#[inline(always)]
769+
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
770+
self.not_undef()?.to_f64()
771+
}
772+
773+
#[inline(always)]
774+
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
775+
self.not_undef()?.to_u8()
776+
}
777+
778+
#[inline(always)]
779+
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
780+
self.not_undef()?.to_u32()
781+
}
782+
783+
#[inline(always)]
784+
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
785+
self.not_undef()?.to_u64()
786+
}
787+
788+
#[inline(always)]
789+
pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> {
790+
self.not_undef()?.to_usize(cx)
791+
}
792+
793+
#[inline(always)]
794+
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
795+
self.not_undef()?.to_i8()
796+
}
797+
798+
#[inline(always)]
799+
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
800+
self.not_undef()?.to_i32()
801+
}
802+
803+
#[inline(always)]
804+
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
805+
self.not_undef()?.to_i64()
806+
}
807+
808+
#[inline(always)]
809+
pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> {
810+
self.not_undef()?.to_isize(cx)
811+
}
812+
}

src/librustc_mir/interpret/operand.rs

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -22,121 +22,7 @@ use rustc::mir::interpret::{
2222
EvalResult, EvalErrorKind
2323
};
2424
use super::{EvalContext, Machine, MemPlace, MPlaceTy, MemoryKind};
25-
26-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
27-
pub enum ScalarMaybeUndef<Tag=(), Id=AllocId> {
28-
Scalar(Scalar<Tag, Id>),
29-
Undef,
30-
}
31-
32-
impl<Tag> From<Scalar<Tag>> for ScalarMaybeUndef<Tag> {
33-
#[inline(always)]
34-
fn from(s: Scalar<Tag>) -> Self {
35-
ScalarMaybeUndef::Scalar(s)
36-
}
37-
}
38-
39-
impl<'tcx> ScalarMaybeUndef<()> {
40-
#[inline]
41-
pub fn with_default_tag<Tag>(self) -> ScalarMaybeUndef<Tag>
42-
where Tag: Default
43-
{
44-
match self {
45-
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.with_default_tag()),
46-
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
47-
}
48-
}
49-
}
50-
51-
impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
52-
#[inline]
53-
pub fn erase_tag(self) -> ScalarMaybeUndef
54-
{
55-
match self {
56-
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.erase_tag()),
57-
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
58-
}
59-
}
60-
61-
#[inline]
62-
pub fn not_undef(self) -> EvalResult<'static, Scalar<Tag>> {
63-
match self {
64-
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
65-
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
66-
}
67-
}
68-
69-
#[inline(always)]
70-
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer<Tag>> {
71-
self.not_undef()?.to_ptr()
72-
}
73-
74-
#[inline(always)]
75-
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
76-
self.not_undef()?.to_bits(target_size)
77-
}
78-
79-
#[inline(always)]
80-
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
81-
self.not_undef()?.to_bool()
82-
}
83-
84-
#[inline(always)]
85-
pub fn to_char(self) -> EvalResult<'tcx, char> {
86-
self.not_undef()?.to_char()
87-
}
88-
89-
#[inline(always)]
90-
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
91-
self.not_undef()?.to_f32()
92-
}
93-
94-
#[inline(always)]
95-
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
96-
self.not_undef()?.to_f64()
97-
}
98-
99-
#[inline(always)]
100-
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
101-
self.not_undef()?.to_u8()
102-
}
103-
104-
#[inline(always)]
105-
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
106-
self.not_undef()?.to_u32()
107-
}
108-
109-
#[inline(always)]
110-
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
111-
self.not_undef()?.to_u64()
112-
}
113-
114-
#[inline(always)]
115-
pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> {
116-
self.not_undef()?.to_usize(cx)
117-
}
118-
119-
#[inline(always)]
120-
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
121-
self.not_undef()?.to_i8()
122-
}
123-
124-
#[inline(always)]
125-
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
126-
self.not_undef()?.to_i32()
127-
}
128-
129-
#[inline(always)]
130-
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
131-
self.not_undef()?.to_i64()
132-
}
133-
134-
#[inline(always)]
135-
pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> {
136-
self.not_undef()?.to_isize(cx)
137-
}
138-
}
139-
25+
pub use rustc::mir::interpret::ScalarMaybeUndef;
14026

14127
/// A `Value` represents a single immediate self-contained Rust value.
14228
///

0 commit comments

Comments
 (0)