Skip to content

Commit df3cabb

Browse files
committed
Move ScalarMaybeUndef into value.rs
1 parent 8a6f62b commit df3cabb

File tree

2 files changed

+120
-120
lines changed

2 files changed

+120
-120
lines changed

src/librustc/mir/interpret/mod.rs

Lines changed: 1 addition & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub use self::error::{
2424
FrameInfo, ConstEvalResult, ErrorHandled,
2525
};
2626

27-
pub use self::value::{Scalar, ConstValue};
27+
pub use self::value::{Scalar, ConstValue, ScalarMaybeUndef};
2828

2929
pub use self::allocation::{
3030
Allocation, MemoryAccess, AllocationExtra,
@@ -567,122 +567,3 @@ pub fn truncate(value: u128, size: Size) -> u128 {
567567
// truncate (shift left to drop out leftover values, shift right to fill with zeroes)
568568
(value << shift) >> shift
569569
}
570-
571-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
572-
pub enum ScalarMaybeUndef<Tag=(), Id=AllocId> {
573-
Scalar(Scalar<Tag, Id>),
574-
Undef,
575-
}
576-
577-
impl<Tag> From<Scalar<Tag>> for ScalarMaybeUndef<Tag> {
578-
#[inline(always)]
579-
fn from(s: Scalar<Tag>) -> Self {
580-
ScalarMaybeUndef::Scalar(s)
581-
}
582-
}
583-
584-
impl<'tcx> ScalarMaybeUndef<()> {
585-
#[inline]
586-
pub fn with_default_tag<Tag>(self) -> ScalarMaybeUndef<Tag>
587-
where Tag: Default
588-
{
589-
match self {
590-
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.with_default_tag()),
591-
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
592-
}
593-
}
594-
}
595-
596-
impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
597-
#[inline]
598-
pub fn erase_tag(self) -> ScalarMaybeUndef
599-
{
600-
match self {
601-
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.erase_tag()),
602-
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
603-
}
604-
}
605-
606-
#[inline]
607-
pub fn not_undef(self) -> EvalResult<'static, Scalar<Tag>> {
608-
match self {
609-
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
610-
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
611-
}
612-
}
613-
614-
#[inline(always)]
615-
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer<Tag>> {
616-
self.not_undef()?.to_ptr()
617-
}
618-
619-
#[inline(always)]
620-
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
621-
self.not_undef()?.to_bits(target_size)
622-
}
623-
624-
#[inline(always)]
625-
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
626-
self.not_undef()?.to_bool()
627-
}
628-
629-
#[inline(always)]
630-
pub fn to_char(self) -> EvalResult<'tcx, char> {
631-
self.not_undef()?.to_char()
632-
}
633-
634-
#[inline(always)]
635-
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
636-
self.not_undef()?.to_f32()
637-
}
638-
639-
#[inline(always)]
640-
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
641-
self.not_undef()?.to_f64()
642-
}
643-
644-
#[inline(always)]
645-
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
646-
self.not_undef()?.to_u8()
647-
}
648-
649-
#[inline(always)]
650-
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
651-
self.not_undef()?.to_u32()
652-
}
653-
654-
#[inline(always)]
655-
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
656-
self.not_undef()?.to_u64()
657-
}
658-
659-
#[inline(always)]
660-
pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> {
661-
self.not_undef()?.to_usize(cx)
662-
}
663-
664-
#[inline(always)]
665-
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
666-
self.not_undef()?.to_i8()
667-
}
668-
669-
#[inline(always)]
670-
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
671-
self.not_undef()?.to_i32()
672-
}
673-
674-
#[inline(always)]
675-
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
676-
self.not_undef()?.to_i64()
677-
}
678-
679-
#[inline(always)]
680-
pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> {
681-
self.not_undef()?.to_isize(cx)
682-
}
683-
}
684-
685-
impl_stable_hash_for!(enum ::mir::interpret::ScalarMaybeUndef {
686-
Scalar(v),
687-
Undef
688-
});

src/librustc/mir/interpret/value.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,122 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
355355
Scalar::Ptr(ptr)
356356
}
357357
}
358+
359+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
360+
pub enum ScalarMaybeUndef<Tag=(), Id=AllocId> {
361+
Scalar(Scalar<Tag, Id>),
362+
Undef,
363+
}
364+
365+
impl<Tag> From<Scalar<Tag>> for ScalarMaybeUndef<Tag> {
366+
#[inline(always)]
367+
fn from(s: Scalar<Tag>) -> Self {
368+
ScalarMaybeUndef::Scalar(s)
369+
}
370+
}
371+
372+
impl<'tcx> ScalarMaybeUndef<()> {
373+
#[inline]
374+
pub fn with_default_tag<Tag>(self) -> ScalarMaybeUndef<Tag>
375+
where Tag: Default
376+
{
377+
match self {
378+
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.with_default_tag()),
379+
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
380+
}
381+
}
382+
}
383+
384+
impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
385+
#[inline]
386+
pub fn erase_tag(self) -> ScalarMaybeUndef
387+
{
388+
match self {
389+
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.erase_tag()),
390+
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
391+
}
392+
}
393+
394+
#[inline]
395+
pub fn not_undef(self) -> EvalResult<'static, Scalar<Tag>> {
396+
match self {
397+
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
398+
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
399+
}
400+
}
401+
402+
#[inline(always)]
403+
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer<Tag>> {
404+
self.not_undef()?.to_ptr()
405+
}
406+
407+
#[inline(always)]
408+
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
409+
self.not_undef()?.to_bits(target_size)
410+
}
411+
412+
#[inline(always)]
413+
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
414+
self.not_undef()?.to_bool()
415+
}
416+
417+
#[inline(always)]
418+
pub fn to_char(self) -> EvalResult<'tcx, char> {
419+
self.not_undef()?.to_char()
420+
}
421+
422+
#[inline(always)]
423+
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
424+
self.not_undef()?.to_f32()
425+
}
426+
427+
#[inline(always)]
428+
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
429+
self.not_undef()?.to_f64()
430+
}
431+
432+
#[inline(always)]
433+
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
434+
self.not_undef()?.to_u8()
435+
}
436+
437+
#[inline(always)]
438+
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
439+
self.not_undef()?.to_u32()
440+
}
441+
442+
#[inline(always)]
443+
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
444+
self.not_undef()?.to_u64()
445+
}
446+
447+
#[inline(always)]
448+
pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> {
449+
self.not_undef()?.to_usize(cx)
450+
}
451+
452+
#[inline(always)]
453+
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
454+
self.not_undef()?.to_i8()
455+
}
456+
457+
#[inline(always)]
458+
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
459+
self.not_undef()?.to_i32()
460+
}
461+
462+
#[inline(always)]
463+
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
464+
self.not_undef()?.to_i64()
465+
}
466+
467+
#[inline(always)]
468+
pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> {
469+
self.not_undef()?.to_isize(cx)
470+
}
471+
}
472+
473+
impl_stable_hash_for!(enum ::mir::interpret::ScalarMaybeUndef {
474+
Scalar(v),
475+
Undef
476+
});

0 commit comments

Comments
 (0)