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

+23-32
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

+1-1
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

-3
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

+1-4
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

+1-4
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

+1-4
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

+1-4
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

-3
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

-3
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

-3
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 }) }

src/test/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ promoted[0] in BAR: &[&i32; 1] = {
88

99
bb0: {
1010
_3 = const {alloc1: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
11-
// ty::Const
12-
// + ty: &i32
13-
// + val: Value(Scalar(alloc1))
1411
// mir::Constant
1512
// + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34
1613
// + literal: Const { ty: &i32, val: Value(Scalar(alloc1)) }

src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@
1818
- StorageLive(_5); // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
1919
- _5 = const {alloc1: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:9:33: 9:34
2020
+ _6 = const BAR::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44
21-
// ty::Const
22-
- // + ty: &i32
23-
- // + val: Value(Scalar(alloc1))
24-
+ // + ty: &[&i32; 1]
25-
+ // + val: Unevaluated(BAR, [], Some(promoted[0]))
2621
// mir::Constant
2722
- // + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34
2823
- // + literal: Const { ty: &i32, val: Value(Scalar(alloc1)) }
2924
- _4 = &(*_5); // scope 0 at $DIR/const-promotion-extern-static.rs:9:32: 9:34
3025
- _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35
3126
- _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44
3227
+ // + span: $DIR/const-promotion-extern-static.rs:9:31: 9:44
33-
+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[e01c]::BAR), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }
28+
+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(BAR, [], Some(promoted[0])) }
3429
+ _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44
3530
_1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44
3631
- StorageDead(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:9:34: 9:35

src/test/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ promoted[0] in FOO: &[&i32; 1] = {
88

99
bb0: {
1010
_3 = const {alloc3: *const i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
11-
// ty::Const
12-
// + ty: *const i32
13-
// + val: Value(Scalar(alloc3))
1411
// mir::Constant
1512
// + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
1613
// + literal: Const { ty: *const i32, val: Value(Scalar(alloc3)) }

src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@
2020
- StorageLive(_5); // scope 1 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
2121
- _5 = const {alloc3: *const i32}; // scope 1 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
2222
+ _6 = const FOO::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55
23-
// ty::Const
24-
- // + ty: *const i32
25-
- // + val: Value(Scalar(alloc3))
26-
+ // + ty: &[&i32; 1]
27-
+ // + val: Unevaluated(FOO, [], Some(promoted[0]))
2823
// mir::Constant
2924
- // + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
3025
- // + literal: Const { ty: *const i32, val: Value(Scalar(alloc3)) }
3126
- _4 = &(*_5); // scope 1 at $DIR/const-promotion-extern-static.rs:13:41: 13:43
3227
- _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
3328
- _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55
3429
+ // + span: $DIR/const-promotion-extern-static.rs:13:31: 13:55
35-
+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[e01c]::FOO), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }
30+
+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(FOO, [], Some(promoted[0])) }
3631
+ _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55
3732
_1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55
3833
- StorageDead(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:13:45: 13:46

src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.diff

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@
2626
StorageLive(_2); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
2727
StorageLive(_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
2828
_9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
29-
// ty::Const
30-
// + ty: &[i32; 3]
31-
// + val: Unevaluated(main, [], Some(promoted[0]))
3229
// mir::Constant
3330
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
34-
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[fbcf]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }
31+
// + literal: Const { ty: &[i32; 3], val: Unevaluated(main, [], Some(promoted[0])) }
3532
_3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3633
_2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3734
_1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35

0 commit comments

Comments
 (0)