Skip to content

Commit

Permalink
mir: pretty-print Rvalue::Aggregate correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 17, 2020
1 parent 2472e04 commit aabed93
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 42 deletions.
32 changes: 17 additions & 15 deletions src/librustc_middle/mir/mod.rs
Expand Up @@ -2242,39 +2242,41 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}

Aggregate(ref kind, ref places) => {
fn fmt_tuple(fmt: &mut Formatter<'_>, places: &[Operand<'_>]) -> fmt::Result {
let mut tuple_fmt = fmt.debug_tuple("");
let fmt_tuple = |fmt: &mut Formatter<'_>, name: &str| {
let mut tuple_fmt = fmt.debug_tuple(name);
for place in places {
tuple_fmt.field(place);
}
tuple_fmt.finish()
}
};

match **kind {
AggregateKind::Array(_) => write!(fmt, "{:?}", places),

AggregateKind::Tuple => match places.len() {
0 => write!(fmt, "()"),
1 => write!(fmt, "({:?},)", places[0]),
_ => fmt_tuple(fmt, places),
},
AggregateKind::Tuple => {
if places.is_empty() {
write!(fmt, "()")
} else {
fmt_tuple(fmt, "")
}
}

AggregateKind::Adt(adt_def, variant, substs, _user_ty, _) => {
let variant_def = &adt_def.variants[variant];

let f = &mut *fmt;
ty::tls::with(|tcx| {
let name = ty::tls::with(|tcx| {
let mut name = String::new();
let substs = tcx.lift(&substs).expect("could not lift for printing");
FmtPrinter::new(tcx, f, Namespace::ValueNS)
FmtPrinter::new(tcx, &mut name, Namespace::ValueNS)
.print_def_path(variant_def.def_id, substs)?;
Ok(())
Ok(name)
})?;

match variant_def.ctor_kind {
CtorKind::Const => Ok(()),
CtorKind::Fn => fmt_tuple(fmt, places),
CtorKind::Const => fmt.write_str(&name),
CtorKind::Fn => fmt_tuple(fmt, &name),
CtorKind::Fictive => {
let mut struct_fmt = fmt.debug_struct("");
let mut struct_fmt = fmt.debug_struct(&name);
for (field, place) in variant_def.fields.iter().zip(places) {
struct_fmt.field(&field.ident.as_str(), place);
}
Expand Down
Expand Up @@ -15,7 +15,7 @@
StorageLive(_1); // bb0[0]: scope 0 at $DIR/discriminant.rs:6:9: 6:10
StorageLive(_2); // bb0[1]: scope 0 at $DIR/discriminant.rs:6:13: 6:64
StorageLive(_3); // bb0[2]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
- _3 = std::option::Option::<bool>::Some(const true,); // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
- _3 = std::option::Option::<bool>::Some(const true); // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
+ _3 = const {transmute(0x01): std::option::Option<bool>}; // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
// ty::Const
- // + ty: bool
Expand Down
Expand Up @@ -15,7 +15,7 @@
StorageLive(_1); // bb0[0]: scope 0 at $DIR/discriminant.rs:6:9: 6:10
StorageLive(_2); // bb0[1]: scope 0 at $DIR/discriminant.rs:6:13: 6:64
StorageLive(_3); // bb0[2]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
- _3 = std::option::Option::<bool>::Some(const true,); // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
- _3 = std::option::Option::<bool>::Some(const true); // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
+ _3 = const {transmute(0x01): std::option::Option<bool>}; // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
// ty::Const
- // + ty: bool
Expand Down
Expand Up @@ -18,7 +18,7 @@
bb1: {
StorageLive(_5); // bb1[0]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:16: 13:17
_5 = _2; // bb1[1]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:16: 13:17
- _0 = Foo::B(move _5,); // bb1[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:9: 13:18
- _0 = Foo::B(move _5); // bb1[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:9: 13:18
- StorageDead(_5); // bb1[3]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:17: 13:18
- goto -> bb3; // bb1[4]: scope 0 at $DIR/deaggregator_test_enum_2.rs:10:5: 14:6
+ ((_0 as B).0: i32) = move _5; // bb1[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:9: 13:18
Expand All @@ -30,7 +30,7 @@
bb2: {
StorageLive(_4); // bb2[0]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:16: 11:17
_4 = _2; // bb2[1]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:16: 11:17
- _0 = Foo::A(move _4,); // bb2[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:9: 11:18
- _0 = Foo::A(move _4); // bb2[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:9: 11:18
- StorageDead(_4); // bb2[3]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:17: 11:18
- goto -> bb3; // bb2[4]: scope 0 at $DIR/deaggregator_test_enum_2.rs:10:5: 14:6
+ ((_0 as A).0: i32) = move _4; // bb2[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:9: 11:18
Expand Down
Expand Up @@ -13,12 +13,12 @@
StorageLive(_2); // bb0[0]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:6: 10:15
StorageLive(_3); // bb0[1]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:13: 10:14
_3 = _1; // bb0[2]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:13: 10:14
- _2 = Foo::A(move _3,); // bb0[3]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:6: 10:15
- _2 = Foo::A(move _3); // bb0[3]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:6: 10:15
- StorageDead(_3); // bb0[4]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:14: 10:15
- StorageLive(_4); // bb0[5]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:17: 10:26
- StorageLive(_5); // bb0[6]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:24: 10:25
- _5 = _1; // bb0[7]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:24: 10:25
- _4 = Foo::A(move _5,); // bb0[8]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:17: 10:26
- _4 = Foo::A(move _5); // bb0[8]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:17: 10:26
- StorageDead(_5); // bb0[9]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:25: 10:26
- _0 = [move _2, move _4]; // bb0[10]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:5: 10:27
- StorageDead(_4); // bb0[11]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:26: 10:27
Expand Down
Expand Up @@ -21,15 +21,15 @@ yields ()

bb0: {
StorageLive(_3); // bb0[0]: scope 0 at $DIR/generator-storage-dead-unwind.rs:23:13: 23:14
_3 = Foo(const 5i32,); // bb0[1]: scope 0 at $DIR/generator-storage-dead-unwind.rs:23:17: 23:23
_3 = Foo(const 5i32); // bb0[1]: scope 0 at $DIR/generator-storage-dead-unwind.rs:23:17: 23:23
// ty::Const
// + ty: i32
// + val: Value(Scalar(0x00000005))
// mir::Constant
// + span: $DIR/generator-storage-dead-unwind.rs:23:21: 23:22
// + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) }
StorageLive(_4); // bb0[2]: scope 1 at $DIR/generator-storage-dead-unwind.rs:24:13: 24:14
_4 = Bar(const 6i32,); // bb0[3]: scope 1 at $DIR/generator-storage-dead-unwind.rs:24:17: 24:23
_4 = Bar(const 6i32); // bb0[3]: scope 1 at $DIR/generator-storage-dead-unwind.rs:24:17: 24:23
// ty::Const
// + ty: i32
// + val: Value(Scalar(0x00000006))
Expand Down
Expand Up @@ -34,7 +34,7 @@ fn main::{{closure}}#0(_1: std::pin::Pin<&mut [generator@$DIR/generator-tiny.rs:
StorageLive(_6); // bb2[0]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
StorageLive(_7); // bb2[1]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
_7 = (); // bb2[2]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
_0 = std::ops::GeneratorState::<(), ()>::Yielded(move _7,); // bb2[3]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
_0 = std::ops::GeneratorState::<(), ()>::Yielded(move _7); // bb2[3]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
discriminant((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:18:16: 24:6 {u8, HasDrop, ()}]))) = 3; // bb2[4]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
return; // bb2[5]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
}
Expand Down
Expand Up @@ -80,7 +80,7 @@ fn main() -> () {
StorageLive(_3); // bb5[0]: scope 1 at $DIR/issue-41888.rs:9:13: 9:20
StorageLive(_4); // bb5[1]: scope 1 at $DIR/issue-41888.rs:9:18: 9:19
_4 = K; // bb5[2]: scope 1 at $DIR/issue-41888.rs:9:18: 9:19
_3 = E::F(move _4,); // bb5[3]: scope 1 at $DIR/issue-41888.rs:9:13: 9:20
_3 = E::F(move _4); // bb5[3]: scope 1 at $DIR/issue-41888.rs:9:13: 9:20
StorageDead(_4); // bb5[4]: scope 1 at $DIR/issue-41888.rs:9:19: 9:20
goto -> bb14; // bb5[5]: scope 1 at $DIR/issue-41888.rs:9:9: 9:10
}
Expand Down
Expand Up @@ -115,7 +115,7 @@ fn test() -> std::option::Option<std::boxed::Box<u32>> {

bb12: {
StorageDead(_2); // bb12[0]: scope 0 at $DIR/issue-62289.rs:9:20: 9:21
_0 = std::option::Option::<std::boxed::Box<u32>>::Some(move _1,); // bb12[1]: scope 0 at $DIR/issue-62289.rs:9:5: 9:22
_0 = std::option::Option::<std::boxed::Box<u32>>::Some(move _1); // bb12[1]: scope 0 at $DIR/issue-62289.rs:9:5: 9:22
drop(_1) -> bb13; // bb12[2]: scope 0 at $DIR/issue-62289.rs:9:21: 9:22
}

Expand Down
Expand Up @@ -26,7 +26,7 @@ fn full_tested_match() -> () {
bb0: {
StorageLive(_1); // bb0[0]: scope 0 at $DIR/match_false_edges.rs:15:13: 19:6
StorageLive(_2); // bb0[1]: scope 0 at $DIR/match_false_edges.rs:15:19: 15:27
_2 = std::option::Option::<i32>::Some(const 42i32,); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:15:19: 15:27
_2 = std::option::Option::<i32>::Some(const 42i32); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:15:19: 15:27
// ty::Const
// + ty: i32
// + val: Value(Scalar(0x0000002a))
Expand Down
Expand Up @@ -25,7 +25,7 @@ fn full_tested_match2() -> () {
bb0: {
StorageLive(_1); // bb0[0]: scope 0 at $DIR/match_false_edges.rs:26:13: 30:6
StorageLive(_2); // bb0[1]: scope 0 at $DIR/match_false_edges.rs:26:19: 26:27
_2 = std::option::Option::<i32>::Some(const 42i32,); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:26:19: 26:27
_2 = std::option::Option::<i32>::Some(const 42i32); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:26:19: 26:27
// ty::Const
// + ty: i32
// + val: Value(Scalar(0x0000002a))
Expand Down
Expand Up @@ -36,7 +36,7 @@ fn main() -> () {
bb0: {
StorageLive(_1); // bb0[0]: scope 0 at $DIR/match_false_edges.rs:35:13: 40:6
StorageLive(_2); // bb0[1]: scope 0 at $DIR/match_false_edges.rs:35:19: 35:26
_2 = std::option::Option::<i32>::Some(const 1i32,); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:35:19: 35:26
_2 = std::option::Option::<i32>::Some(const 1i32); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:35:19: 35:26
// ty::Const
// + ty: i32
// + val: Value(Scalar(0x00000001))
Expand Down
Expand Up @@ -16,27 +16,27 @@ fn main() -> () {
StorageLive(_1); // bb0[0]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:9: 6:14
StorageLive(_2); // bb0[1]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
StorageLive(_3); // bb0[2]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
_3 = Droppy(const 0usize,); // bb0[3]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
_3 = Droppy(const 0usize); // bb0[3]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
// ty::Const
// + ty: usize
// + val: Value(Scalar(0x00000000))
// mir::Constant
// + span: $DIR/packed-struct-drop-aligned.rs:6:39: 6:40
// + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) }
_2 = Aligned(move _3,); // bb0[4]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
_2 = Aligned(move _3); // bb0[4]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
StorageDead(_3); // bb0[5]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:41: 6:42
_1 = Packed(move _2,); // bb0[6]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:17: 6:43
_1 = Packed(move _2); // bb0[6]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:17: 6:43
StorageDead(_2); // bb0[7]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:42: 6:43
StorageLive(_4); // bb0[8]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
StorageLive(_5); // bb0[9]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
_5 = Droppy(const 0usize,); // bb0[10]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
_5 = Droppy(const 0usize); // bb0[10]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
// ty::Const
// + ty: usize
// + val: Value(Scalar(0x00000000))
// mir::Constant
// + span: $DIR/packed-struct-drop-aligned.rs:7:26: 7:27
// + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) }
_4 = Aligned(move _5,); // bb0[11]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
_4 = Aligned(move _5); // bb0[11]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
StorageDead(_5); // bb0[12]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:28: 7:29
StorageLive(_6); // bb0[13]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:5: 7:8
_6 = move (_1.0: Aligned); // bb0[14]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:5: 7:8
Expand Down
Expand Up @@ -16,27 +16,27 @@ fn main() -> () {
StorageLive(_1); // bb0[0]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:9: 6:14
StorageLive(_2); // bb0[1]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
StorageLive(_3); // bb0[2]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
_3 = Droppy(const 0usize,); // bb0[3]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
_3 = Droppy(const 0usize); // bb0[3]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
// ty::Const
// + ty: usize
// + val: Value(Scalar(0x0000000000000000))
// mir::Constant
// + span: $DIR/packed-struct-drop-aligned.rs:6:39: 6:40
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000000)) }
_2 = Aligned(move _3,); // bb0[4]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
_2 = Aligned(move _3); // bb0[4]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
StorageDead(_3); // bb0[5]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:41: 6:42
_1 = Packed(move _2,); // bb0[6]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:17: 6:43
_1 = Packed(move _2); // bb0[6]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:17: 6:43
StorageDead(_2); // bb0[7]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:42: 6:43
StorageLive(_4); // bb0[8]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
StorageLive(_5); // bb0[9]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
_5 = Droppy(const 0usize,); // bb0[10]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
_5 = Droppy(const 0usize); // bb0[10]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
// ty::Const
// + ty: usize
// + val: Value(Scalar(0x0000000000000000))
// mir::Constant
// + span: $DIR/packed-struct-drop-aligned.rs:7:26: 7:27
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000000)) }
_4 = Aligned(move _5,); // bb0[11]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
_4 = Aligned(move _5); // bb0[11]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
StorageDead(_5); // bb0[12]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:28: 7:29
StorageLive(_6); // bb0[13]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:5: 7:8
_6 = move (_1.0: Aligned); // bb0[14]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:5: 7:8
Expand Down

0 comments on commit aabed93

Please sign in to comment.