Skip to content

Commit

Permalink
Render const pointers in MIR more compactly
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 24, 2020
1 parent dee12bb commit 9a2d5e8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/librustc/mir/interpret/mod.rs
Expand Up @@ -166,9 +166,15 @@ pub enum LitToConstError {
Reported,
}

#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd, Debug)]
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct AllocId(pub u64);

impl fmt::Debug for AllocId {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "alloc{}", self.0)
}
}

impl rustc_serialize::UseSpecializedEncodable for AllocId {}
impl rustc_serialize::UseSpecializedDecodable for AllocId {}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/interpret/pointer.rs
Expand Up @@ -133,13 +133,13 @@ static_assert_size!(Pointer, 16);

impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Pointer<Tag, Id> {
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}.{:#x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
write!(f, "{:?}+{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
}
}
// Specialization for no tag
impl<Id: fmt::Debug> fmt::Debug for Pointer<(), Id> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}.{:#x}", self.alloc_id, self.offset.bytes())
write!(f, "{:?}+{:x}", self.alloc_id, self.offset.bytes())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/const-promotion-extern-static.rs
Expand Up @@ -14,7 +14,7 @@ fn main() {}
// START rustc.FOO.PromoteTemps.before.mir
// bb0: {
// ...
// _5 = const Scalar(AllocId(1).0x0) : &i32;
// _5 = const Scalar(alloc1+0) : &i32;
// _4 = &(*_5);
// _3 = [move _4];
// _2 = &_3;
Expand All @@ -31,7 +31,7 @@ fn main() {}
// START rustc.BAR.PromoteTemps.before.mir
// bb0: {
// ...
// _5 = const Scalar(AllocId(0).0x0) : &i32;
// _5 = const Scalar(alloc0+0) : &i32;
// _4 = &(*_5);
// _3 = [move _4];
// _2 = &_3;
Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/const_prop/read_immutable_static.rs
Expand Up @@ -10,10 +10,10 @@ fn main() {
// START rustc.main.ConstProp.before.mir
// bb0: {
// ...
// _3 = const Scalar(AllocId(0).0x0) : &u8;
// _3 = const Scalar(alloc0+0) : &u8;
// _2 = (*_3);
// ...
// _5 = const Scalar(AllocId(0).0x0) : &u8;
// _5 = const Scalar(alloc0+0) : &u8;
// _4 = (*_5);
// _1 = Add(move _2, move _4);
// ...
Expand Down

0 comments on commit 9a2d5e8

Please sign in to comment.