Skip to content

Commit 1d56b8a

Browse files
committed
Make unevaluated DefId rendering deterministic
1 parent 5582b19 commit 1d56b8a

20 files changed

+37
-23
lines changed

compiler/rustc_mir/src/util/pretty.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,21 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
465465
if use_verbose(ty) {
466466
self.push("ty::Const");
467467
self.push(&format!("+ ty: {:?}", ty));
468-
self.push(&format!("+ val: {:?}", val));
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(_) => format!("Error"),
481+
};
482+
self.push(&format!("+ val: {}", val));
469483
}
470484
}
471485

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- // + ty: &i32
2323
- // + val: Value(Scalar(alloc0))
2424
+ // + ty: &[&i32; 1]
25-
+ // + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[317d]::BAR), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
25+
+ // + val: Unevaluated(BAR, [], Some(promoted[0]))
2626
// mir::Constant
2727
- // + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34
2828
- // + literal: Const { ty: &i32, val: Value(Scalar(alloc0)) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- // + ty: *const i32
2525
- // + val: Value(Scalar(alloc2))
2626
+ // + ty: &[&i32; 1]
27-
+ // + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
27+
+ // + val: Unevaluated(FOO, [], Some(promoted[0]))
2828
// mir::Constant
2929
- // + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
3030
- // + literal: Const { ty: *const i32, val: Value(Scalar(alloc2)) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
2929
// ty::Const
3030
// + ty: &[i32; 3]
31-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
31+
// + val: Unevaluated(main, [], Some(promoted[0]))
3232
// mir::Constant
3333
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3434
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
2929
// ty::Const
3030
// + ty: &[i32; 3]
31-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
31+
// + val: Unevaluated(main, [], Some(promoted[0]))
3232
// mir::Constant
3333
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3434
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_3 = const FOO; // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
2020
// ty::Const
2121
// + ty: &i32
22-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main::FOO), const_param_did: None }, substs: [], promoted: None })
22+
// + val: Unevaluated(FOO, [], None)
2323
// mir::Constant
2424
// + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
2525
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main::FOO), const_param_did: None }, substs: [], promoted: None }) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
_4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10
1515
// ty::Const
1616
// + ty: &i32
17-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
17+
// + val: Unevaluated(main, [], Some(promoted[0]))
1818
// mir::Constant
1919
// + span: $DIR/ref_deref.rs:5:6: 5:10
2020
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/const_prop/ref_deref.main.PromoteTemps.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
+ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10
1818
+ // ty::Const
1919
+ // + ty: &i32
20-
+ // + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
20+
+ // + val: Unevaluated(main, [], Some(promoted[0]))
2121
+ // mir::Constant
2222
+ // + span: $DIR/ref_deref.rs:5:6: 5:10
2323
+ // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
_4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17
1515
// ty::Const
1616
// + ty: &(i32, i32)
17-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
17+
// + val: Unevaluated(main, [], Some(promoted[0]))
1818
// mir::Constant
1919
// + span: $DIR/ref_deref_project.rs:5:6: 5:17
2020
// + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/const_prop/ref_deref_project.main.PromoteTemps.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
+ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17
1818
+ // ty::Const
1919
+ // + ty: &(i32, i32)
20-
+ // + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
20+
+ // + val: Unevaluated(main, [], Some(promoted[0]))
2121
+ // mir::Constant
2222
+ // + span: $DIR/ref_deref_project.rs:5:6: 5:17
2323
+ // + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
_9 = const main::promoted[0]; // scope 0 at $DIR/slice_len.rs:5:6: 5:19
2222
// ty::Const
2323
// + ty: &[u32; 3]
24-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
24+
// + val: Unevaluated(main, [], Some(promoted[0]))
2525
// mir::Constant
2626
// + span: $DIR/slice_len.rs:5:6: 5:19
2727
// + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
_9 = const main::promoted[0]; // scope 0 at $DIR/slice_len.rs:5:6: 5:19
2222
// ty::Const
2323
// + ty: &[u32; 3]
24-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
24+
// + val: Unevaluated(main, [], Some(promoted[0]))
2525
// mir::Constant
2626
// + span: $DIR/slice_len.rs:5:6: 5:19
2727
// + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn bar() -> bool {
3535
_10 = const bar::promoted[1]; // scope 1 at $DIR/inline-retag.rs:12:7: 12:9
3636
// ty::Const
3737
// + ty: &i32
38-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[317d]::bar), const_param_did: None }, substs: [], promoted: Some(promoted[1]) })
38+
// + val: Unevaluated(bar, [], Some(promoted[1]))
3939
// mir::Constant
4040
// + span: $DIR/inline-retag.rs:12:7: 12:9
4141
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[317d]::bar), const_param_did: None }, substs: [], promoted: Some(promoted[1]) }) }
@@ -49,7 +49,7 @@ fn bar() -> bool {
4949
_9 = const bar::promoted[0]; // scope 1 at $DIR/inline-retag.rs:12:11: 12:14
5050
// ty::Const
5151
// + ty: &i32
52-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[317d]::bar), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
52+
// + val: Unevaluated(bar, [], Some(promoted[0]))
5353
// mir::Constant
5454
// + span: $DIR/inline-retag.rs:12:11: 12:14
5555
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[317d]::bar), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
_20 = const main::promoted[0]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
6464
// ty::Const
6565
// + ty: &i32
66-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
66+
// + val: Unevaluated(main, [], Some(promoted[0]))
6767
// mir::Constant
6868
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
6969
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
_20 = const main::promoted[0]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
6464
// ty::Const
6565
// + ty: &i32
66-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
66+
// + val: Unevaluated(main, [], Some(promoted[0]))
6767
// mir::Constant
6868
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
6969
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
_28 = const main::promoted[0]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
8585
// ty::Const
8686
// + ty: &i32
87-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
87+
// + val: Unevaluated(main, [], Some(promoted[0]))
8888
// mir::Constant
8989
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
9090
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
_28 = const main::promoted[0]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
8585
// ty::Const
8686
// + ty: &i32
87-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
87+
// + val: Unevaluated(main, [], Some(promoted[0]))
8888
// mir::Constant
8989
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
9090
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
_19 = const discriminant::<T>::promoted[2]; // scope 0 at $DIR/lower_intrinsics.rs:70:42: 70:44
4848
// ty::Const
4949
// + ty: &i32
50-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[8787]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[2]) })
50+
// + val: Unevaluated(discriminant, [T], Some(promoted[2]))
5151
// mir::Constant
5252
// + span: $DIR/lower_intrinsics.rs:70:42: 70:44
5353
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[8787]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[2]) }) }
@@ -71,7 +71,7 @@
7171
_18 = const discriminant::<T>::promoted[1]; // scope 0 at $DIR/lower_intrinsics.rs:71:42: 71:45
7272
// ty::Const
7373
// + ty: &()
74-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[8787]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[1]) })
74+
// + val: Unevaluated(discriminant, [T], Some(promoted[1]))
7575
// mir::Constant
7676
// + span: $DIR/lower_intrinsics.rs:71:42: 71:45
7777
// + literal: Const { ty: &(), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[8787]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[1]) }) }
@@ -95,7 +95,7 @@
9595
_17 = const discriminant::<T>::promoted[0]; // scope 0 at $DIR/lower_intrinsics.rs:72:42: 72:47
9696
// ty::Const
9797
// + ty: &E
98-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[8787]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[0]) })
98+
// + val: Unevaluated(discriminant, [T], Some(promoted[0]))
9999
// mir::Constant
100100
// + span: $DIR/lower_intrinsics.rs:72:42: 72:47
101101
// + literal: Const { ty: &E, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[8787]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[0]) }) }

0 commit comments

Comments
 (0)