Skip to content

Commit 9ecd75b

Browse files
committed
Auto merge of #94209 - lcnr:print-mir-consts, r=oli-obk
change `mir::Constant` in mir dumps this removes duplicate information and avoids printing the `stable_crate_id` in mir dumps which broke CI in #94059 r? `@oli-obk` cc `@b-naber`
2 parents 58a721a + ee0b564 commit 9ecd75b

File tree

69 files changed

+107
-349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+107
-349
lines changed

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ fn use_verbose<'tcx>(ty: Ty<'tcx>, fn_def: bool) -> bool {
436436
}
437437

438438
impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
439-
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
440-
self.super_constant(constant, location);
439+
fn visit_constant(&mut self, constant: &Constant<'tcx>, _location: Location) {
441440
let Constant { span, user_ty, literal } = constant;
442441
if use_verbose(literal.ty(), true) {
443442
self.push("mir::Constant");
@@ -448,38 +447,30 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
448447
if let Some(user_ty) = user_ty {
449448
self.push(&format!("+ user_ty: {:?}", user_ty));
450449
}
451-
match literal {
452-
ConstantKind::Ty(literal) => self.push(&format!("+ literal: {:?}", literal)),
453-
ConstantKind::Val(val, ty) => {
454-
// To keep the diffs small, we render this almost like we render ty::Const
455-
self.push(&format!("+ literal: Const {{ ty: {}, val: Value({:?}) }}", ty, val))
456-
}
457-
}
458-
}
459-
}
460450

461-
fn visit_const(&mut self, constant: ty::Const<'tcx>, _: Location) {
462-
self.super_const(constant);
463-
let ty = constant.ty();
464-
let val = constant.val();
465-
if use_verbose(ty, false) {
466-
self.push("ty::Const");
467-
self.push(&format!("+ ty: {:?}", ty));
468-
let val = match val {
469-
ty::ConstKind::Param(p) => format!("Param({})", p),
470-
ty::ConstKind::Infer(infer) => format!("Infer({:?})", infer),
471-
ty::ConstKind::Bound(idx, var) => format!("Bound({:?}, {:?})", idx, var),
472-
ty::ConstKind::Placeholder(ph) => format!("PlaceHolder({:?})", ph),
473-
ty::ConstKind::Unevaluated(uv) => format!(
474-
"Unevaluated({}, {:?}, {:?})",
475-
self.tcx.def_path_str(uv.def.did),
476-
uv.substs,
477-
uv.promoted,
478-
),
479-
ty::ConstKind::Value(val) => format!("Value({:?})", val),
480-
ty::ConstKind::Error(_) => "Error".to_string(),
451+
let val = match literal {
452+
ConstantKind::Ty(ct) => match ct.val() {
453+
ty::ConstKind::Param(p) => format!("Param({})", p),
454+
ty::ConstKind::Unevaluated(uv) => format!(
455+
"Unevaluated({}, {:?}, {:?})",
456+
self.tcx.def_path_str(uv.def.did),
457+
uv.substs,
458+
uv.promoted,
459+
),
460+
ty::ConstKind::Value(val) => format!("Value({:?})", val),
461+
ty::ConstKind::Error(_) => "Error".to_string(),
462+
// These variants shouldn't exist in the MIR.
463+
ty::ConstKind::Placeholder(_)
464+
| ty::ConstKind::Infer(_)
465+
| ty::ConstKind::Bound(..) => bug!("unexpected MIR constant: {:?}", literal),
466+
},
467+
// To keep the diffs small, we render this like we render `ty::Const::Value`.
468+
//
469+
// This changes once `ty::Const::Value` is represented using valtrees.
470+
ConstantKind::Val(val, _) => format!("Value({:?})", val),
481471
};
482-
self.push(&format!("+ val: {}", val));
472+
473+
self.push(&format!("+ literal: Const {{ ty: {}, val: {} }}", literal.ty(), val));
483474
}
484475
}
485476

src/test/mir-opt/box_expr.main.ElaborateDrops.before.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() -> () {
4747
_6 = std::mem::drop::<Box<S>>(move _7) -> [return: bb4, unwind: bb6]; // scope 1 at $DIR/box_expr.rs:8:5: 8:12
4848
// mir::Constant
4949
// + span: $DIR/box_expr.rs:8:5: 8:9
50-
// + literal: Const { ty: fn(std::boxed::Box<S>) {std::mem::drop::<std::boxed::Box<S>>}, val: Value(Scalar(<ZST>)) }
50+
// + literal: Const { ty: fn(Box<S>) {std::mem::drop::<Box<S>>}, val: Value(Scalar(<ZST>)) }
5151
}
5252

5353
bb4: {

src/test/mir-opt/byte_slice.main.SimplifyCfg-elaborate-drops.after.mir

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ fn main() -> () {
1414
bb0: {
1515
StorageLive(_1); // scope 0 at $DIR/byte_slice.rs:5:9: 5:10
1616
_1 = const b"foo"; // scope 0 at $DIR/byte_slice.rs:5:13: 5:19
17-
// ty::Const
18-
// + ty: &[u8; 3]
19-
// + val: Value(Scalar(alloc1))
2017
// mir::Constant
2118
// + span: $DIR/byte_slice.rs:5:13: 5:19
2219
// + literal: Const { ty: &[u8; 3], val: Value(Scalar(alloc1)) }

src/test/mir-opt/const_allocation.main.ConstProp.after.32bit.mir

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1111
_2 = const {alloc1: &&[(Option<i32>, &[&str])]}; // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
12-
// ty::Const
13-
// + ty: &&[(std::option::Option<i32>, &[&str])]
14-
// + val: Value(Scalar(alloc1))
1512
// mir::Constant
1613
// + span: $DIR/const_allocation.rs:8:5: 8:8
17-
// + literal: Const { ty: &&[(std::option::Option<i32>, &[&str])], val: Value(Scalar(alloc1)) }
14+
// + literal: Const { ty: &&[(Option<i32>, &[&str])], val: Value(Scalar(alloc1)) }
1815
_1 = (*_2); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1916
StorageDead(_2); // scope 0 at $DIR/const_allocation.rs:8:8: 8:9
2017
StorageDead(_1); // scope 0 at $DIR/const_allocation.rs:8:8: 8:9

src/test/mir-opt/const_allocation.main.ConstProp.after.64bit.mir

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1111
_2 = const {alloc1: &&[(Option<i32>, &[&str])]}; // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
12-
// ty::Const
13-
// + ty: &&[(std::option::Option<i32>, &[&str])]
14-
// + val: Value(Scalar(alloc1))
1512
// mir::Constant
1613
// + span: $DIR/const_allocation.rs:8:5: 8:8
17-
// + literal: Const { ty: &&[(std::option::Option<i32>, &[&str])], val: Value(Scalar(alloc1)) }
14+
// + literal: Const { ty: &&[(Option<i32>, &[&str])], val: Value(Scalar(alloc1)) }
1815
_1 = (*_2); // scope 0 at $DIR/const_allocation.rs:8:5: 8:8
1916
StorageDead(_2); // scope 0 at $DIR/const_allocation.rs:8:8: 8:9
2017
StorageDead(_1); // scope 0 at $DIR/const_allocation.rs:8:8: 8:9

src/test/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1111
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]}; // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
12-
// ty::Const
13-
// + ty: &&[(std::option::Option<i32>, &[&u8])]
14-
// + val: Value(Scalar(alloc1))
1512
// mir::Constant
1613
// + span: $DIR/const_allocation2.rs:5:5: 5:8
17-
// + literal: Const { ty: &&[(std::option::Option<i32>, &[&u8])], val: Value(Scalar(alloc1)) }
14+
// + literal: Const { ty: &&[(Option<i32>, &[&u8])], val: Value(Scalar(alloc1)) }
1815
_1 = (*_2); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1916
StorageDead(_2); // scope 0 at $DIR/const_allocation2.rs:5:8: 5:9
2017
StorageDead(_1); // scope 0 at $DIR/const_allocation2.rs:5:8: 5:9

src/test/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1111
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]}; // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
12-
// ty::Const
13-
// + ty: &&[(std::option::Option<i32>, &[&u8])]
14-
// + val: Value(Scalar(alloc1))
1512
// mir::Constant
1613
// + span: $DIR/const_allocation2.rs:5:5: 5:8
17-
// + literal: Const { ty: &&[(std::option::Option<i32>, &[&u8])], val: Value(Scalar(alloc1)) }
14+
// + literal: Const { ty: &&[(Option<i32>, &[&u8])], val: Value(Scalar(alloc1)) }
1815
_1 = (*_2); // scope 0 at $DIR/const_allocation2.rs:5:5: 5:8
1916
StorageDead(_2); // scope 0 at $DIR/const_allocation2.rs:5:8: 5:9
2017
StorageDead(_1); // scope 0 at $DIR/const_allocation2.rs:5:8: 5:9

src/test/mir-opt/const_allocation3.main.ConstProp.after.32bit.mir

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1111
_2 = const {alloc1: &&Packed}; // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
12-
// ty::Const
13-
// + ty: &&Packed
14-
// + val: Value(Scalar(alloc1))
1512
// mir::Constant
1613
// + span: $DIR/const_allocation3.rs:5:5: 5:8
1714
// + literal: Const { ty: &&Packed, val: Value(Scalar(alloc1)) }

src/test/mir-opt/const_allocation3.main.ConstProp.after.64bit.mir

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ fn main() -> () {
99
StorageLive(_1); // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1010
StorageLive(_2); // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
1111
_2 = const {alloc1: &&Packed}; // scope 0 at $DIR/const_allocation3.rs:5:5: 5:8
12-
// ty::Const
13-
// + ty: &&Packed
14-
// + val: Value(Scalar(alloc1))
1512
// mir::Constant
1613
// + span: $DIR/const_allocation3.rs:5:5: 5:8
1714
// + literal: Const { ty: &&Packed, val: Value(Scalar(alloc1)) }

src/test/mir-opt/const_debuginfo.main.ConstDebugInfo.diff

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@
7575
StorageDead(_5); // scope 3 at $DIR/const_debuginfo.rs:12:23: 12:24
7676
StorageLive(_9); // scope 4 at $DIR/const_debuginfo.rs:14:9: 14:10
7777
_9 = const "hello, world!"; // scope 4 at $DIR/const_debuginfo.rs:14:13: 14:28
78-
// ty::Const
79-
// + ty: &str
80-
// + val: Value(Slice { data: Allocation { bytes: [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [8191], len: Size { raw: 13 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 13 })
8178
// mir::Constant
8279
// + span: $DIR/const_debuginfo.rs:14:13: 14:28
8380
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [8191], len: Size { raw: 13 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 13 }) }

0 commit comments

Comments
 (0)