Skip to content

Commit 5217e4c

Browse files
committed
Move ScalarMaybeUndef into value.rs
1 parent 771e237 commit 5217e4c

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

0 commit comments

Comments
 (0)