Skip to content

Commit 2440e80

Browse files
committed
mir printing changes
1 parent 3e4dfc8 commit 2440e80

14 files changed

+372
-22
lines changed

compiler/rustc_middle/src/mir/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn write_graph_label<'tcx, W: std::fmt::Write>(
103103
write!(w, "{:?}: {}", Place::from(arg), escape(&body.local_decls[arg].ty))?;
104104
}
105105

106-
write!(w, ") -&gt; {}", escape(&body.return_ty()))?;
106+
write!(w, ") -&gt; {}", dot::escape_html(&format!("{}", body.return_ty())))?;
107107
write!(w, r#"<br align="left"/>"#)?;
108108

109109
for local in body.vars_and_temps_iter() {

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ impl<'tcx> Debug for VarDebugInfoContents<'tcx> {
10611061
VarDebugInfoContents::Const(c) => write!(fmt, "{}", c),
10621062
VarDebugInfoContents::Place(p) => write!(fmt, "{:?}", p),
10631063
VarDebugInfoContents::Composite { ty, fragments } => {
1064-
write!(fmt, "{:?}{{ ", ty)?;
1064+
ty::print::with_no_trimmed_paths!(write!(fmt, "{}{{ ", ty))?;
10651065
for f in fragments.iter() {
10661066
write!(fmt, "{:?}, ", f)?;
10671067
}
@@ -1722,7 +1722,8 @@ impl Debug for Place<'_> {
17221722
write!(fmt, ")")?;
17231723
}
17241724
ProjectionElem::Field(field, ty) => {
1725-
write!(fmt, ".{:?}: {:?})", field.index(), ty)?;
1725+
let ty = ty::print::with_no_trimmed_paths!(format!("{ty}"));
1726+
write!(fmt, ".{:?}: {})", field.index(), ty)?;
17261727
}
17271728
ProjectionElem::Index(ref index) => {
17281729
write!(fmt, "[{:?}]", index)?;
@@ -2009,15 +2010,19 @@ impl<'tcx> Debug for Rvalue<'tcx> {
20092010
}
20102011
Len(ref a) => write!(fmt, "Len({:?})", a),
20112012
Cast(ref kind, ref place, ref ty) => {
2012-
write!(fmt, "{:?} as {:?} ({:?})", place, ty, kind)
2013+
let ty = ty::print::with_no_trimmed_paths!(format!("{ty}"));
2014+
write!(fmt, "{:?} as {} ({:?})", place, ty, kind)
20132015
}
20142016
BinaryOp(ref op, box (ref a, ref b)) => write!(fmt, "{:?}({:?}, {:?})", op, a, b),
20152017
CheckedBinaryOp(ref op, box (ref a, ref b)) => {
20162018
write!(fmt, "Checked{:?}({:?}, {:?})", op, a, b)
20172019
}
20182020
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),
20192021
Discriminant(ref place) => write!(fmt, "discriminant({:?})", place),
2020-
NullaryOp(ref op, ref t) => write!(fmt, "{:?}({:?})", op, t),
2022+
NullaryOp(ref op, ref t) => {
2023+
let t = ty::print::with_no_trimmed_paths!(format!("{t}"));
2024+
write!(fmt, "{:?}({})", op, t)
2025+
}
20212026
ThreadLocalRef(did) => ty::tls::with(|tcx| {
20222027
let muta = tcx.static_mutability(did).unwrap().prefix_str();
20232028
write!(fmt, "&/*tls*/ {}{}", muta, tcx.def_path_str(did))
@@ -2144,7 +2149,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
21442149
}
21452150

21462151
ShallowInitBox(ref place, ref ty) => {
2147-
write!(fmt, "ShallowInitBox({:?}, {:?})", place, ty)
2152+
let ty = ty::print::with_no_trimmed_paths!(format!("{ty}"));
2153+
write!(fmt, "ShallowInitBox({:?}, {})", place, ty)
21482154
}
21492155
}
21502156
}

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,14 @@ fn write_scope_tree(
582582

583583
let mut_str = if local_decl.mutability == Mutability::Mut { "mut " } else { "" };
584584

585-
let mut indented_decl =
586-
format!("{0:1$}let {2}{3:?}: {4:?}", INDENT, indent, mut_str, local, local_decl.ty);
585+
let mut indented_decl = format!(
586+
"{0:1$}let {2}{3:?}: {4}",
587+
INDENT,
588+
indent,
589+
mut_str,
590+
local,
591+
ty::print::with_no_trimmed_paths!(format!("{}", local_decl.ty))
592+
);
587593
if let Some(user_ty) = &local_decl.user_ty {
588594
for user_ty in user_ty.projections() {
589595
write!(indented_decl, " as {:?}", user_ty).unwrap();
@@ -1049,11 +1055,11 @@ fn write_user_type_annotations(
10491055
for (index, annotation) in body.user_type_annotations.iter_enumerated() {
10501056
writeln!(
10511057
w,
1052-
"| {:?}: user_ty: {:?}, span: {}, inferred_ty: {:?}",
1058+
"| {:?}: user_ty: {:?}, span: {}, inferred_ty: {}",
10531059
index.index(),
10541060
annotation.user_ty,
10551061
tcx.sess.source_map().span_to_embeddable_string(annotation.span),
1056-
annotation.inferred_ty,
1062+
ty::print::with_no_trimmed_paths!(format!("{}", annotation.inferred_ty)),
10571063
)?;
10581064
}
10591065
if !body.user_type_annotations.is_empty() {

compiler/rustc_middle/src/ty/typeck_results.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ impl<'tcx> CanonicalUserType<'tcx> {
703703
/// A user-given type annotation attached to a constant. These arise
704704
/// from constants that are named via paths, like `Foo::<A>::new` and
705705
/// so forth.
706-
#[derive(Copy, Clone, Debug, PartialEq, TyEncodable, TyDecodable)]
706+
#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable)]
707707
#[derive(Eq, Hash, HashStable, TypeFoldable, TypeVisitable, Lift)]
708708
pub enum UserType<'tcx> {
709709
Ty(Ty<'tcx>),
@@ -712,3 +712,14 @@ pub enum UserType<'tcx> {
712712
/// given substitutions applied.
713713
TypeOf(DefId, UserSubsts<'tcx>),
714714
}
715+
716+
impl<'tcx> std::fmt::Debug for UserType<'tcx> {
717+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
718+
match self {
719+
Self::Ty(arg0) => {
720+
ty::print::with_no_trimmed_paths!(f.write_fmt(format_args!("Ty({})", arg0)))
721+
}
722+
Self::TypeOf(arg0, arg1) => f.debug_tuple("TypeOf").field(arg0).field(arg1).finish(),
723+
}
724+
}
725+
}

tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// MIR for `b::{closure#0}` 0 generator_resume
22
/* generator_layout = GeneratorLayout {
33
field_tys: {
4+
<<<<<<< master
45
_0: GeneratorSavedTy {
56
ty: impl std::future::Future<Output = ()>,
67
source_info: SourceInfo {
@@ -17,6 +18,22 @@
1718
},
1819
ignore_for_traits: false,
1920
},
21+
=======
22+
_0: Alias(
23+
Opaque,
24+
AliasTy {
25+
substs: [],
26+
def_id: DefId(0:7 ~ async_await[672b]::a::{opaque#0}),
27+
},
28+
),
29+
_1: Alias(
30+
Opaque,
31+
AliasTy {
32+
substs: [],
33+
def_id: DefId(0:7 ~ async_await[672b]::a::{opaque#0}),
34+
},
35+
),
36+
>>>>>>> mir printing changes
2037
},
2138
variant_fields: {
2239
Unresumed(0): [],

tests/mir-opt/generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// MIR for `main::{closure#0}` 0 generator_drop
22
/* generator_layout = GeneratorLayout {
33
field_tys: {
4+
<<<<<<< master
45
_0: GeneratorSavedTy {
56
ty: std::string::String,
67
source_info: SourceInfo {
@@ -9,6 +10,12 @@
910
},
1011
ignore_for_traits: false,
1112
},
13+
=======
14+
_0: Adt(
15+
std::string::String,
16+
[],
17+
),
18+
>>>>>>> mir printing changes
1219
},
1320
variant_fields: {
1421
Unresumed(0): [],

tests/mir-opt/generator_tiny.main-{closure#0}.generator_resume.0.mir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// MIR for `main::{closure#0}` 0 generator_resume
22
/* generator_layout = GeneratorLayout {
33
field_tys: {
4+
<<<<<<< master
45
_0: GeneratorSavedTy {
56
ty: HasDrop,
67
source_info: SourceInfo {
@@ -9,6 +10,12 @@
910
},
1011
ignore_for_traits: false,
1112
},
13+
=======
14+
_0: Adt(
15+
HasDrop,
16+
[],
17+
),
18+
>>>>>>> mir printing changes
1219
},
1320
variant_fields: {
1421
Unresumed(0): [],

tests/mir-opt/inline/inline_into_box_place.main.Inline.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
- bb2: {
5151
+ // + span: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
5252
+ // + user_ty: UserType(0)
53-
+ // + literal: Const { ty: alloc::raw_vec::RawVec<u32>, val: Unevaluated(alloc::raw_vec::RawVec::<T>::NEW, [u32], None) }
53+
+ // + literal: Const { ty: alloc::raw_vec::RawVec<u32>, val: Unevaluated(alloc::raw_vec::RawVec::<T>::NEW, [Uint(U32)], None) }
5454
+ Deinit(_9); // scope 3 at $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
5555
+ (_9.0: alloc::raw_vec::RawVec<u32>) = move _10; // scope 3 at $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
5656
+ (_9.1: usize) = const 0_usize; // scope 3 at $SRC_DIR/alloc/src/vec/mod.rs:LL:COL

tests/mir-opt/issue_99325.main.built.after.mir renamed to tests/mir-opt/issue_99325.main.built.after.32bit.mir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// MIR for `main` after built
22

33
| User Type Annotations
4-
| 0: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Value(Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)])) }], user_self_ty: None }) }, span: $DIR/issue_99325.rs:10:16: 10:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Unevaluated(UnevaluatedConst { def: WithOptConstParam { did: DefId(0:8 ~ issue_99325[8f58]::main::{constant#1}), const_param_did: Some(DefId(0:4 ~ issue_99325[8f58]::function_with_bytes::BYTES)) }, substs: [] }) }], user_self_ty: None }) }, span: $DIR/issue_99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
4+
| 0: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: Ref(ReStatic, Array(Uint(U8), Const { ty: Uint(Usize), kind: Value(Leaf(0x00000004)) }), Not), kind: Value(Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)])) }], user_self_ty: None }) }, span: $DIR/issue_99325.rs:11:16: 11:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: Ref(ReStatic, Array(Uint(U8), Const { ty: Uint(Usize), kind: Value(Leaf(0x00000004)) }), Not), kind: Unevaluated(UnevaluatedConst { def: WithOptConstParam { did: DefId(0:8 ~ issue_99325[8f58]::main::{constant#1}), const_param_did: Some(DefId(0:4 ~ issue_99325[8f58]::function_with_bytes::BYTES)) }, substs: [] }) }], user_self_ty: None }) }, span: $DIR/issue_99325.rs:12:16: 12:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: (); // return place in scope 0 at $DIR/issue_99325.rs:+0:15: +0:15
@@ -71,7 +71,7 @@ fn main() -> () {
7171
StorageLive(_4); // scope 0 at $DIR/issue_99325.rs:+1:16: +1:48
7272
_4 = function_with_bytes::<&*b"AAAA">() -> [return: bb1, unwind: bb19]; // scope 0 at $DIR/issue_99325.rs:+1:16: +1:48
7373
// mir::Constant
74-
// + span: $DIR/issue_99325.rs:10:16: 10:46
74+
// + span: $DIR/issue_99325.rs:11:16: 11:46
7575
// + user_ty: UserType(0)
7676
// + literal: Const { ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}, val: Value(<ZST>) }
7777
}
@@ -179,7 +179,7 @@ fn main() -> () {
179179
StorageLive(_26); // scope 0 at $DIR/issue_99325.rs:+2:16: +2:70
180180
_26 = function_with_bytes::<&*b"AAAA">() -> [return: bb10, unwind: bb19]; // scope 0 at $DIR/issue_99325.rs:+2:16: +2:70
181181
// mir::Constant
182-
// + span: $DIR/issue_99325.rs:11:16: 11:68
182+
// + span: $DIR/issue_99325.rs:12:16: 12:68
183183
// + user_ty: UserType(1)
184184
// + literal: Const { ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}, val: Value(<ZST>) }
185185
}
@@ -190,7 +190,7 @@ fn main() -> () {
190190
StorageLive(_28); // scope 0 at $DIR/issue_99325.rs:+2:72: +2:79
191191
_28 = const b"AAAA"; // scope 0 at $DIR/issue_99325.rs:+2:72: +2:79
192192
// mir::Constant
193-
// + span: $DIR/issue_99325.rs:11:72: 11:79
193+
// + span: $DIR/issue_99325.rs:12:72: 12:79
194194
// + literal: Const { ty: &[u8; 4], val: Value(Scalar(alloc4)) }
195195
_27 = &_28; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
196196
_24 = (move _25, move _27); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL

0 commit comments

Comments
 (0)