Skip to content

Commit 7d99e80

Browse files
committed
MIR printing: print the path of uneval'd const; refer to promoteds in a consistent way
1 parent 3521a2f commit 7d99e80

File tree

79 files changed

+114
-101
lines changed

Some content is hidden

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

79 files changed

+114
-101
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
6767
trace!(
6868
"eval_body_using_ecx: pushing stack frame for global: {}{}",
6969
with_no_trimmed_paths!(ecx.tcx.def_path_str(cid.instance.def_id())),
70-
cid.promoted.map_or_else(String::new, |p| format!("::promoted[{p:?}]"))
70+
cid.promoted.map_or_else(String::new, |p| format!("::{p:?}"))
7171
);
7272

7373
ecx.push_stack_frame(

compiler/rustc_middle/src/mir/consts.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_target::abi::{HasDataLayout, Size};
77

88
use crate::mir::interpret::{alloc_range, AllocId, ConstAllocation, ErrorHandled, Scalar};
99
use crate::mir::{pretty_print_const_value, Promoted};
10+
use crate::ty::print::with_no_trimmed_paths;
1011
use crate::ty::GenericArgsRef;
1112
use crate::ty::ScalarInt;
1213
use crate::ty::{self, print::pretty_print_const, Ty, TyCtxt};
@@ -489,9 +490,18 @@ impl<'tcx> Display for Const<'tcx> {
489490
Const::Ty(c) => pretty_print_const(c, fmt, true),
490491
Const::Val(val, ty) => pretty_print_const_value(val, ty, fmt),
491492
// FIXME(valtrees): Correctly print mir constants.
492-
Const::Unevaluated(..) => {
493-
fmt.write_str("_")?;
494-
Ok(())
493+
Const::Unevaluated(c, _ty) => {
494+
ty::tls::with(move |tcx| {
495+
let c = tcx.lift(c).unwrap();
496+
// Matches `GlobalId` printing.
497+
let instance =
498+
with_no_trimmed_paths!(tcx.def_path_str_with_args(c.def, c.args));
499+
write!(fmt, "{instance}")?;
500+
if let Some(promoted) = c.promoted {
501+
write!(fmt, "::{promoted:?}")?;
502+
}
503+
Ok(())
504+
})
495505
}
496506
}
497507
}

compiler/rustc_middle/src/mir/pretty.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
496496
_ => tcx.is_closure_like(def_id),
497497
};
498498
match (kind, body.source.promoted) {
499-
(_, Some(i)) => write!(w, "{i:?} in ")?,
499+
(_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts
500500
(DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
501501
(DefKind::Static(hir::Mutability::Not), _) => write!(w, "static ")?,
502502
(DefKind::Static(hir::Mutability::Mut), _) => write!(w, "static mut ")?,
@@ -509,6 +509,9 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
509509
// see notes on #41697 elsewhere
510510
write!(w, "{}", tcx.def_path_str(def_id))?
511511
}
512+
if let Some(p) = body.source.promoted {
513+
write!(w, "::{p:?}")?;
514+
}
512515

513516
if body.source.promoted.is_none() && is_function {
514517
write!(w, "(")?;

tests/mir-opt/building/custom/consts.consts.built.after.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ fn consts() -> () {
1010

1111
bb0: {
1212
_1 = const 5_u8;
13-
_2 = const _;
13+
_2 = const consts::<C>::{constant#0};
1414
_3 = const C;
15-
_4 = const _;
15+
_4 = const D;
1616
_5 = consts::<10>;
1717
return;
1818
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `BAR::promoted[0]` after SimplifyCfg-elaborate-drops
22

3-
promoted[0] in BAR: &[&i32; 1] = {
3+
const BAR::promoted[0]: &[&i32; 1] = {
44
let mut _0: &[&i32; 1];
55
let mut _1: [&i32; 1];
66
let mut _2: &i32;

tests/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- _4 = &(*_5);
2121
- _3 = [move _4];
2222
- _2 = &_3;
23-
+ _6 = const _;
23+
+ _6 = const BAR::promoted[0];
2424
+ _2 = &(*_6);
2525
_1 = move _2 as &[&i32] (PointerCoercion(Unsize));
2626
- StorageDead(_4);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `FOO::promoted[0]` after SimplifyCfg-elaborate-drops
22

3-
promoted[0] in FOO: &[&i32; 1] = {
3+
const FOO::promoted[0]: &[&i32; 1] = {
44
let mut _0: &[&i32; 1];
55
let mut _1: [&i32; 1];
66
let mut _2: &i32;

tests/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- _4 = &(*_5);
2323
- _3 = [move _4];
2424
- _2 = &_3;
25-
+ _6 = const _;
25+
+ _6 = const FOO::promoted[0];
2626
+ _2 = &(*_6);
2727
_1 = move _2 as &[&i32] (PointerCoercion(Unsize));
2828
- StorageDead(_4);

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
StorageLive(_1);
2626
StorageLive(_2);
2727
StorageLive(_3);
28-
_9 = const _;
28+
_9 = const main::promoted[0];
2929
_3 = &(*_9);
3030
_2 = &raw const (*_3);
3131
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
StorageLive(_1);
2626
StorageLive(_2);
2727
StorageLive(_3);
28-
_9 = const _;
28+
_9 = const main::promoted[0];
2929
_3 = &(*_9);
3030
_2 = &raw const (*_3);
3131
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
StorageLive(_1);
2626
StorageLive(_2);
2727
StorageLive(_3);
28-
_9 = const _;
28+
_9 = const main::promoted[0];
2929
_3 = &(*_9);
3030
_2 = &raw const (*_3);
3131
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
StorageLive(_1);
2626
StorageLive(_2);
2727
StorageLive(_3);
28-
_9 = const _;
28+
_9 = const main::promoted[0];
2929
_3 = &(*_9);
3030
_2 = &raw const (*_3);
3131
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
bb0: {
1010
StorageLive(_1);
11-
_1 = const _;
11+
_1 = const <bool as NeedsDrop>::NEEDS;
1212
- switchInt(move _1) -> [0: bb2, otherwise: bb1];
1313
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
1414
}

tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
bb0: {
1010
StorageLive(_1);
11-
_1 = const _;
11+
_1 = const <bool as NeedsDrop>::NEEDS;
1212
- switchInt(move _1) -> [0: bb2, otherwise: bb1];
1313
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
1414
}

tests/mir-opt/const_prop/overwrite_with_const_with_params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<T> SizeOfConst<T> {
1414
fn size_of<T>() -> usize {
1515
// CHECK-LABEL: fn size_of(
1616
// CHECK: _1 = const 0_usize;
17-
// CHECK-NEXT: _1 = const _;
17+
// CHECK-NEXT: _1 = const SizeOfConst::<T>::SIZE;
1818
// CHECK-NEXT: _0 = _1;
1919
let mut a = 0;
2020
a = SizeOfConst::<T>::SIZE;

tests/mir-opt/const_prop/overwrite_with_const_with_params.size_of.GVN.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
bb0: {
1212
StorageLive(_1);
1313
_1 = const 0_usize;
14-
_1 = const _;
14+
_1 = const SizeOfConst::<T>::SIZE;
1515
_0 = _1;
1616
StorageDead(_1);
1717
return;

tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
+ nop;
1818
StorageLive(_2);
1919
StorageLive(_3);
20-
_3 = const _;
20+
_3 = const main::FOO;
2121
_2 = &raw const (*_3);
2222
_1 = move _2 as usize (PointerExposeAddress);
2323
StorageDead(_2);

tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
+ nop;
1818
StorageLive(_2);
1919
StorageLive(_3);
20-
_3 = const _;
20+
_3 = const main::FOO;
2121
_2 = &raw const (*_3);
2222
_1 = move _2 as usize (PointerExposeAddress);
2323
StorageDead(_2);

tests/mir-opt/const_prop/pointer_expose_address.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn read(_: usize) { }
77
// EMIT_MIR pointer_expose_address.main.GVN.diff
88
fn main() {
99
// CHECK-LABEL: fn main(
10-
// CHECK: [[ptr:_.*]] = const _;
10+
// CHECK: [[ptr:_.*]] = const main::FOO;
1111
// CHECK: [[ref:_.*]] = &raw const (*[[ptr]]);
1212
// CHECK: [[x:_.*]] = move [[ref]] as usize (PointerExposeAddress);
1313
// CHECK: = read([[x]])

tests/mir-opt/const_prop/ref_deref.main.GVN.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
bb0: {
1515
StorageLive(_1);
1616
StorageLive(_2);
17-
_4 = const _;
17+
_4 = const main::promoted[0];
1818
_2 = &(*_4);
1919
- _1 = (*_2);
2020
+ _1 = const 4_i32;

tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
bb0: {
1515
StorageLive(_1);
1616
StorageLive(_2);
17-
_4 = const _;
17+
_4 = const main::promoted[0];
1818
_2 = &((*_4).1: i32);
1919
- _1 = (*_2);
2020
+ _1 = const 5_i32;

tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
StorageLive(_2);
2222
StorageLive(_3);
2323
StorageLive(_4);
24-
_9 = const _;
24+
_9 = const main::promoted[0];
2525
- _4 = _9;
2626
- _3 = _4;
2727
- _2 = move _3 as &[u32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
StorageLive(_2);
2222
StorageLive(_3);
2323
StorageLive(_4);
24-
_9 = const _;
24+
_9 = const main::promoted[0];
2525
- _4 = _9;
2626
- _3 = _4;
2727
- _2 = move _3 as &[u32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
StorageLive(_2);
2222
StorageLive(_3);
2323
StorageLive(_4);
24-
_9 = const _;
24+
_9 = const main::promoted[0];
2525
- _4 = _9;
2626
- _3 = _4;
2727
- _2 = move _3 as &[u32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
StorageLive(_2);
2222
StorageLive(_3);
2323
StorageLive(_4);
24-
_9 = const _;
24+
_9 = const main::promoted[0];
2525
- _4 = _9;
2626
- _3 = _4;
2727
- _2 = move _3 as &[u32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/transmute.invalid_char.GVN.32bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88

99
bb0: {
10-
- _0 = const _ as char (Transmute);
10+
- _0 = const core::num::<impl i32>::MAX as char (Transmute);
1111
+ _0 = const {transmute(0x7fffffff): char};
1212
return;
1313
}

tests/mir-opt/const_prop/transmute.invalid_char.GVN.64bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88

99
bb0: {
10-
- _0 = const _ as char (Transmute);
10+
- _0 = const core::num::<impl i32>::MAX as char (Transmute);
1111
+ _0 = const {transmute(0x7fffffff): char};
1212
return;
1313
}

tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
StorageDead(_5);
5454
StorageDead(_4);
5555
StorageLive(_7);
56-
_7 = const _;
56+
_7 = const core::num::<impl i32>::MAX;
5757
StorageLive(_8);
5858
StorageLive(_9);
5959
- _9 = _7;

tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
StorageDead(_5);
5454
StorageDead(_4);
5555
StorageLive(_7);
56-
_7 = const _;
56+
_7 = const core::num::<impl i32>::MAX;
5757
StorageLive(_8);
5858
StorageLive(_9);
5959
- _9 = _7;

tests/mir-opt/dataflow-const-prop/checked.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
// CHECK: [[c]] = const 3_i32;
2424
let c = a + b;
2525

26-
// CHECK: [[d]] = const _;
26+
// CHECK: [[d]] = const core::num::<impl i32>::MAX;
2727
let d = i32::MAX;
2828

2929
// CHECK: assert(!const true,

tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.32bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
bb0: {
2525
StorageLive(_1);
26-
_1 = const _;
26+
_1 = const constant::C;
2727
StorageLive(_2);
2828
- _3 = discriminant(_1);
2929
- switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1];

tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
bb0: {
2525
StorageLive(_1);
26-
_1 = const _;
26+
_1 = const constant::C;
2727
StorageLive(_2);
2828
- _3 = discriminant(_1);
2929
- switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1];

tests/mir-opt/dataflow-const-prop/enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn constant() {
3434
// CHECK: debug x => [[x:_.*]];
3535
const C: E = E::V1(0);
3636

37-
// CHECK: [[e]] = const _;
37+
// CHECK: [[e]] = const constant::C;
3838
let e = C;
3939
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb2, otherwise: bb1];
4040
// CHECK: [[target_bb]]: {

tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
StorageLive(_2);
3030
StorageLive(_3);
3131
StorageLive(_4);
32-
_14 = const _;
32+
_14 = const main::promoted[0];
3333
_4 = _14;
3434
_3 = _4;
3535
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
@@ -52,7 +52,7 @@
5252
StorageDead(_2);
5353
StorageLive(_9);
5454
StorageLive(_10);
55-
_10 = const _;
55+
_10 = const main::SLICE;
5656
StorageLive(_11);
5757
_11 = const 1_usize;
5858
- _12 = Len((*_10));

tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
StorageLive(_2);
3030
StorageLive(_3);
3131
StorageLive(_4);
32-
_14 = const _;
32+
_14 = const main::promoted[0];
3333
_4 = _14;
3434
_3 = _4;
3535
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
@@ -52,7 +52,7 @@
5252
StorageDead(_2);
5353
StorageLive(_9);
5454
StorageLive(_10);
55-
_10 = const _;
55+
_10 = const main::SLICE;
5656
StorageLive(_11);
5757
_11 = const 1_usize;
5858
- _12 = Len((*_10));

tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
StorageLive(_2);
3030
StorageLive(_3);
3131
StorageLive(_4);
32-
_14 = const _;
32+
_14 = const main::promoted[0];
3333
_4 = _14;
3434
_3 = _4;
3535
_2 = move _3 as &[u32] (PointerCoercion(Unsize));
@@ -52,7 +52,7 @@
5252
StorageDead(_2);
5353
StorageLive(_9);
5454
StorageLive(_10);
55-
_10 = const _;
55+
_10 = const main::SLICE;
5656
StorageLive(_11);
5757
_11 = const 1_usize;
5858
- _12 = Len((*_10));

0 commit comments

Comments
 (0)