Skip to content

Commit 99ed98b

Browse files
committed
Move ScalarMaybeUndef into value.rs
1 parent 2108b6b commit 99ed98b

File tree

2 files changed

+129
-129
lines changed

2 files changed

+129
-129
lines changed

src/librustc/mir/interpret/mod.rs

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

src/librustc/mir/interpret/value.rs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,131 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
392392
Scalar::Ptr(ptr)
393393
}
394394
}
395+
396+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)]
397+
pub enum ScalarMaybeUndef<Tag=(), Id=AllocId> {
398+
Scalar(Scalar<Tag, Id>),
399+
Undef,
400+
}
401+
402+
impl<Tag> From<Scalar<Tag>> for ScalarMaybeUndef<Tag> {
403+
#[inline(always)]
404+
fn from(s: Scalar<Tag>) -> Self {
405+
ScalarMaybeUndef::Scalar(s)
406+
}
407+
}
408+
409+
impl<Tag> fmt::Display for ScalarMaybeUndef<Tag> {
410+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
411+
match self {
412+
ScalarMaybeUndef::Undef => write!(f, "uninitialized bytes"),
413+
ScalarMaybeUndef::Scalar(s) => write!(f, "{}", s),
414+
}
415+
}
416+
}
417+
418+
impl<'tcx> ScalarMaybeUndef<()> {
419+
#[inline]
420+
pub fn with_default_tag<Tag>(self) -> ScalarMaybeUndef<Tag>
421+
where Tag: Default
422+
{
423+
match self {
424+
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.with_default_tag()),
425+
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
426+
}
427+
}
428+
}
429+
430+
impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
431+
#[inline]
432+
pub fn erase_tag(self) -> ScalarMaybeUndef
433+
{
434+
match self {
435+
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.erase_tag()),
436+
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
437+
}
438+
}
439+
440+
#[inline]
441+
pub fn not_undef(self) -> EvalResult<'static, Scalar<Tag>> {
442+
match self {
443+
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
444+
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
445+
}
446+
}
447+
448+
#[inline(always)]
449+
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer<Tag>> {
450+
self.not_undef()?.to_ptr()
451+
}
452+
453+
#[inline(always)]
454+
pub fn to_bits(self, target_size: Size) -> EvalResult<'tcx, u128> {
455+
self.not_undef()?.to_bits(target_size)
456+
}
457+
458+
#[inline(always)]
459+
pub fn to_bool(self) -> EvalResult<'tcx, bool> {
460+
self.not_undef()?.to_bool()
461+
}
462+
463+
#[inline(always)]
464+
pub fn to_char(self) -> EvalResult<'tcx, char> {
465+
self.not_undef()?.to_char()
466+
}
467+
468+
#[inline(always)]
469+
pub fn to_f32(self) -> EvalResult<'tcx, f32> {
470+
self.not_undef()?.to_f32()
471+
}
472+
473+
#[inline(always)]
474+
pub fn to_f64(self) -> EvalResult<'tcx, f64> {
475+
self.not_undef()?.to_f64()
476+
}
477+
478+
#[inline(always)]
479+
pub fn to_u8(self) -> EvalResult<'tcx, u8> {
480+
self.not_undef()?.to_u8()
481+
}
482+
483+
#[inline(always)]
484+
pub fn to_u32(self) -> EvalResult<'tcx, u32> {
485+
self.not_undef()?.to_u32()
486+
}
487+
488+
#[inline(always)]
489+
pub fn to_u64(self) -> EvalResult<'tcx, u64> {
490+
self.not_undef()?.to_u64()
491+
}
492+
493+
#[inline(always)]
494+
pub fn to_usize(self, cx: &impl HasDataLayout) -> EvalResult<'tcx, u64> {
495+
self.not_undef()?.to_usize(cx)
496+
}
497+
498+
#[inline(always)]
499+
pub fn to_i8(self) -> EvalResult<'tcx, i8> {
500+
self.not_undef()?.to_i8()
501+
}
502+
503+
#[inline(always)]
504+
pub fn to_i32(self) -> EvalResult<'tcx, i32> {
505+
self.not_undef()?.to_i32()
506+
}
507+
508+
#[inline(always)]
509+
pub fn to_i64(self) -> EvalResult<'tcx, i64> {
510+
self.not_undef()?.to_i64()
511+
}
512+
513+
#[inline(always)]
514+
pub fn to_isize(self, cx: &impl HasDataLayout) -> EvalResult<'tcx, i64> {
515+
self.not_undef()?.to_isize(cx)
516+
}
517+
}
518+
519+
impl_stable_hash_for!(enum ::mir::interpret::ScalarMaybeUndef {
520+
Scalar(v),
521+
Undef
522+
});

0 commit comments

Comments
 (0)