Skip to content

Render const pointers in MIR more compactly #68516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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