Skip to content

Commit 64c9712

Browse files
authored
Rollup merge of #86566 - fee1-dead:mir-pretty-print, r=oli-obk
Use `use_verbose` for `mir::Constant` Fixes #79799.
2 parents 2322097 + 6370567 commit 64c9712

12 files changed

+19
-60
lines changed

compiler/rustc_mir/src/util/pretty.rs

+19-27
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ impl ExtraComments<'tcx> {
426426
}
427427
}
428428

429-
fn use_verbose(ty: &&TyS<'tcx>) -> bool {
429+
fn use_verbose(ty: &&TyS<'tcx>, fn_def: bool) -> bool {
430430
match ty.kind() {
431431
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false,
432432
// Unit type
433433
ty::Tuple(g_args) if g_args.is_empty() => false,
434-
ty::Tuple(g_args) => g_args.iter().any(|g_arg| use_verbose(&g_arg.expect_ty())),
435-
ty::Array(ty, _) => use_verbose(ty),
436-
ty::FnDef(..) => false,
434+
ty::Tuple(g_args) => g_args.iter().any(|g_arg| use_verbose(&g_arg.expect_ty(), fn_def)),
435+
ty::Array(ty, _) => use_verbose(ty, fn_def),
436+
ty::FnDef(..) => fn_def,
437437
_ => true,
438438
}
439439
}
@@ -442,28 +442,20 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
442442
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
443443
self.super_constant(constant, location);
444444
let Constant { span, user_ty, literal } = constant;
445-
match literal.ty().kind() {
446-
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char => {}
447-
// Unit type
448-
ty::Tuple(tys) if tys.is_empty() => {}
449-
_ => {
450-
self.push("mir::Constant");
451-
self.push(&format!(
452-
"+ span: {}",
453-
self.tcx.sess.source_map().span_to_embeddable_string(*span)
454-
));
455-
if let Some(user_ty) = user_ty {
456-
self.push(&format!("+ user_ty: {:?}", user_ty));
457-
}
458-
match literal {
459-
ConstantKind::Ty(literal) => self.push(&format!("+ literal: {:?}", literal)),
460-
ConstantKind::Val(val, ty) => {
461-
// To keep the diffs small, we render this almost like we render ty::Const
462-
self.push(&format!(
463-
"+ literal: Const {{ ty: {}, val: Value({:?}) }}",
464-
ty, val
465-
))
466-
}
445+
if use_verbose(&literal.ty(), true) {
446+
self.push("mir::Constant");
447+
self.push(&format!(
448+
"+ span: {}",
449+
self.tcx.sess.source_map().span_to_embeddable_string(*span)
450+
));
451+
if let Some(user_ty) = user_ty {
452+
self.push(&format!("+ user_ty: {:?}", user_ty));
453+
}
454+
match literal {
455+
ConstantKind::Ty(literal) => self.push(&format!("+ literal: {:?}", literal)),
456+
ConstantKind::Val(val, ty) => {
457+
// To keep the diffs small, we render this almost like we render ty::Const
458+
self.push(&format!("+ literal: Const {{ ty: {}, val: Value({:?}) }}", ty, val))
467459
}
468460
}
469461
}
@@ -472,7 +464,7 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
472464
fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, _: Location) {
473465
self.super_const(constant);
474466
let ty::Const { ty, val, .. } = constant;
475-
if use_verbose(ty) {
467+
if use_verbose(ty, false) {
476468
self.push("ty::Const");
477469
self.push(&format!("+ ty: {:?}", ty));
478470
let val = match val {

src/test/mir-opt/const_prop/checked_add.main.ConstProp.diff

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
- _2 = CheckedAdd(const 1_u32, const 1_u32); // scope 0 at $DIR/checked_add.rs:5:18: 5:23
1515
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> bb1; // scope 0 at $DIR/checked_add.rs:5:18: 5:23
1616
+ _2 = const (2_u32, false); // scope 0 at $DIR/checked_add.rs:5:18: 5:23
17-
+ // mir::Constant
18-
+ // + span: $DIR/checked_add.rs:5:18: 5:23
19-
+ // + literal: Const { ty: (u32, bool), val: Value(ByRef { alloc: Allocation { bytes: [2, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [31], len: Size { raw: 8 } }, align: Align { pow2: 2 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
2017
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> bb1; // scope 0 at $DIR/checked_add.rs:5:18: 5:23
2118
}
2219

src/test/mir-opt/const_prop/indirect.main.ConstProp.diff

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
- assert(!move (_3.1: bool), "attempt to compute `{} + {}`, which would overflow", move _2, const 1_u8) -> bb1; // scope 0 at $DIR/indirect.rs:5:13: 5:29
1919
+ _2 = const 2_u8; // scope 0 at $DIR/indirect.rs:5:13: 5:25
2020
+ _3 = const (3_u8, false); // scope 0 at $DIR/indirect.rs:5:13: 5:29
21-
+ // mir::Constant
22-
+ // + span: $DIR/indirect.rs:5:13: 5:29
23-
+ // + literal: Const { ty: (u8, bool), val: Value(ByRef { alloc: Allocation { bytes: [3, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [3], len: Size { raw: 2 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
2421
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u8, const 1_u8) -> bb1; // scope 0 at $DIR/indirect.rs:5:13: 5:29
2522
}
2623

src/test/mir-opt/const_prop/issue_67019.main.ConstProp.diff

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
(_3.1: u8) = const 2_u8; // scope 0 at $DIR/issue-67019.rs:11:11: 11:17
1616
- (_2.0: (u8, u8)) = move _3; // scope 0 at $DIR/issue-67019.rs:11:10: 11:19
1717
+ (_2.0: (u8, u8)) = const (1_u8, 2_u8); // scope 0 at $DIR/issue-67019.rs:11:10: 11:19
18-
+ // mir::Constant
19-
+ // + span: $DIR/issue-67019.rs:11:10: 11:19
20-
+ // + literal: Const { ty: (u8, u8), val: Value(ByRef { alloc: Allocation { bytes: [1, 2], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [3], len: Size { raw: 2 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
2118
StorageDead(_3); // scope 0 at $DIR/issue-67019.rs:11:18: 11:19
2219
_1 = test(move _2) -> bb1; // scope 0 at $DIR/issue-67019.rs:11:5: 11:20
2320
// mir::Constant

src/test/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
StorageLive(_2); // scope 1 at $DIR/mutable_variable_aggregate.rs:7:9: 7:10
2121
- _2 = _1; // scope 1 at $DIR/mutable_variable_aggregate.rs:7:13: 7:14
2222
+ _2 = const (42_i32, 99_i32); // scope 1 at $DIR/mutable_variable_aggregate.rs:7:13: 7:14
23-
+ // mir::Constant
24-
+ // + span: $DIR/mutable_variable_aggregate.rs:7:13: 7:14
25-
+ // + literal: Const { ty: (i32, i32), val: Value(ByRef { alloc: Allocation { bytes: [42, 0, 0, 0, 99, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 2 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
2623
nop; // scope 0 at $DIR/mutable_variable_aggregate.rs:4:11: 8:2
2724
StorageDead(_2); // scope 1 at $DIR/mutable_variable_aggregate.rs:8:1: 8:2
2825
StorageDead(_1); // scope 0 at $DIR/mutable_variable_aggregate.rs:8:1: 8:2

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

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
- _2 = CheckedAdd(const 2_i32, const 2_i32); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
2828
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
2929
+ _2 = const (4_i32, false); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
30-
+ // mir::Constant
31-
+ // + span: $DIR/optimizes_into_variable.rs:12:13: 12:18
32-
+ // + literal: Const { ty: (i32, bool), val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [31], len: Size { raw: 8 } }, align: Align { pow2: 2 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
3330
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
3431
}
3532

src/test/mir-opt/const_prop/optimizes_into_variable.main.ConstProp.64bit.diff

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
- _2 = CheckedAdd(const 2_i32, const 2_i32); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
2828
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
2929
+ _2 = const (4_i32, false); // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
30-
+ // mir::Constant
31-
+ // + span: $DIR/optimizes_into_variable.rs:12:13: 12:18
32-
+ // + literal: Const { ty: (i32, bool), val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [31], len: Size { raw: 8 } }, align: Align { pow2: 2 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
3330
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_i32, const 2_i32) -> bb1; // scope 0 at $DIR/optimizes_into_variable.rs:12:13: 12:18
3431
}
3532

src/test/mir-opt/const_prop/return_place.add.ConstProp.diff

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
- _1 = CheckedAdd(const 2_u32, const 2_u32); // scope 0 at $DIR/return_place.rs:6:5: 6:10
1010
- assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> bb1; // scope 0 at $DIR/return_place.rs:6:5: 6:10
1111
+ _1 = const (4_u32, false); // scope 0 at $DIR/return_place.rs:6:5: 6:10
12-
+ // mir::Constant
13-
+ // + span: $DIR/return_place.rs:6:5: 6:10
14-
+ // + literal: Const { ty: (u32, bool), val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [31], len: Size { raw: 8 } }, align: Align { pow2: 2 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
1512
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> bb1; // scope 0 at $DIR/return_place.rs:6:5: 6:10
1613
}
1714

src/test/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.diff

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
StorageLive(_3); // scope 1 at $DIR/tuple_literal_propagation.rs:5:13: 5:14
1919
- _3 = _1; // scope 1 at $DIR/tuple_literal_propagation.rs:5:13: 5:14
2020
+ _3 = const (1_u32, 2_u32); // scope 1 at $DIR/tuple_literal_propagation.rs:5:13: 5:14
21-
+ // mir::Constant
22-
+ // + span: $DIR/tuple_literal_propagation.rs:5:13: 5:14
23-
+ // + literal: Const { ty: (u32, u32), val: Value(ByRef { alloc: Allocation { bytes: [1, 0, 0, 0, 2, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 2 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
2421
_2 = consume(move _3) -> bb1; // scope 1 at $DIR/tuple_literal_propagation.rs:5:5: 5:15
2522
// mir::Constant
2623
// + span: $DIR/tuple_literal_propagation.rs:5:5: 5:12

src/test/mir-opt/deaggregator_test.bar.Deaggregator.diff

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
- _0 = Baz { x: move _2, y: const 0f32, z: const false }; // scope 0 at $DIR/deaggregator_test.rs:9:5: 9:35
1313
+ (_0.0: usize) = move _2; // scope 0 at $DIR/deaggregator_test.rs:9:5: 9:35
1414
+ (_0.1: f32) = const 0f32; // scope 0 at $DIR/deaggregator_test.rs:9:5: 9:35
15-
// mir::Constant
16-
// + span: $DIR/deaggregator_test.rs:9:20: 9:23
17-
// + literal: Const { ty: f32, val: Value(Scalar(0x00000000)) }
1815
+ (_0.2: bool) = const false; // scope 0 at $DIR/deaggregator_test.rs:9:5: 9:35
1916
StorageDead(_2); // scope 0 at $DIR/deaggregator_test.rs:9:34: 9:35
2017
return; // scope 0 at $DIR/deaggregator_test.rs:10:2: 10:2

src/test/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
StorageLive(_3); // scope 0 at $DIR/if-condition-int.rs:53:8: 53:9
1313
_3 = _1; // scope 0 at $DIR/if-condition-int.rs:53:8: 53:9
1414
_2 = Eq(move _3, const -42f32); // scope 0 at $DIR/if-condition-int.rs:53:8: 53:18
15-
// mir::Constant
16-
// + span: $DIR/if-condition-int.rs:53:13: 53:18
17-
// + literal: Const { ty: f32, val: Value(Scalar(0xc2280000)) }
1815
StorageDead(_3); // scope 0 at $DIR/if-condition-int.rs:53:17: 53:18
1916
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/if-condition-int.rs:53:5: 53:35
2017
}

src/test/mir-opt/simplify_locals_removes_unused_consts.main.SimplifyLocals.diff

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
// mir::Constant
3939
// + span: $DIR/simplify-locals-removes-unused-consts.rs:14:5: 14:12
4040
// + literal: Const { ty: fn(((), ())) {use_zst}, val: Value(Scalar(<ZST>)) }
41-
// mir::Constant
42-
// + span: $DIR/simplify-locals-removes-unused-consts.rs:14:5: 14:22
43-
// + literal: Const { ty: ((), ()), val: Value(Scalar(<ZST>)) }
4441
}
4542

4643
bb1: {

0 commit comments

Comments
 (0)