Skip to content

Commit 48f6941

Browse files
committed
Move ScalarMaybeUndef back to rustc
1 parent 7db0483 commit 48f6941

File tree

3 files changed

+129
-129
lines changed

3 files changed

+129
-129
lines changed

src/librustc/mir/interpret/mod.rs

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

src/librustc_mir/interpret/operand.rs

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

15128
/// A `Value` represents a single immediate self-contained Rust value.
15229
///

src/librustc_mir/interpret/snapshot.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ impl<'a, Ctx> Snapshot<'a, Ctx> for Scalar
195195
}
196196
}
197197

198-
impl_stable_hash_for!(enum ::interpret::ScalarMaybeUndef {
199-
Scalar(v),
200-
Undef
201-
});
202-
203198
impl_snapshot_for!(enum ScalarMaybeUndef {
204199
Scalar(s),
205200
Undef,

0 commit comments

Comments
 (0)