From e7229e62df6386f2ff1df83bd462d5aa37e3b2e5 Mon Sep 17 00:00:00 2001 From: Jost Berthold Date: Thu, 15 May 2025 11:07:37 +1000 Subject: [PATCH] Add a list of field types to struct type metadata This adds the field types of the single variant of a `struct` `RigidTy::Adt` to the type metadata. --- src/printer.rs | 17 +++++++++++++++-- tests/integration/normalise-filter.jq | 4 ++-- .../programs/assert_eq.smir.json.expected | 6 ++++++ .../programs/binop.smir.json.expected | 3 +++ .../programs/char-trivial.smir.json.expected | 3 +++ .../programs/closure-args.smir.json.expected | 3 +++ .../programs/closure-no-args.smir.json.expected | 3 +++ .../const-arithm-simple.smir.json.expected | 3 +++ .../integration/programs/div.smir.json.expected | 3 +++ .../double-ref-deref.smir.json.expected | 3 +++ .../programs/enum.smir.json.expected | 2 ++ .../programs/fibonacci.smir.json.expected | 3 +++ .../programs/float.smir.json.expected | 3 +++ .../programs/modulo.smir.json.expected | 3 +++ .../mutual_recursion.smir.json.expected | 3 +++ .../option-construction.smir.json.expected | 3 +++ .../primitive-type-bounds.smir.json.expected | 3 +++ .../recursion-simple-match.smir.json.expected | 3 +++ .../recursion-simple.smir.json.expected | 3 +++ .../programs/ref-deref.smir.json.expected | 3 +++ .../programs/shl_min.smir.json.expected | 3 +++ .../programs/slice.smir.json.expected | 5 +++++ .../strange-ref-deref.smir.json.expected | 3 +++ .../programs/struct.smir.json.expected | 4 ++++ .../programs/sum-to-n.smir.json.expected | 3 +++ .../programs/tuple-eq.smir.json.expected | 3 +++ .../programs/tuples-simple.smir.json.expected | 3 +++ 27 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 2b67b26..bcecd44 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -987,6 +987,7 @@ pub enum TypeMetadata { StructType { name: String, adt_def: AdtDef, + fields: Vec, }, UnionType { name: String, @@ -1029,10 +1030,22 @@ fn mk_type_metadata( }, )) } - // for structs, we record the name for information purposes + // for structs, we record the name for information purposes and the field types T(Adt(adt_def, _)) if t.is_struct() => { let name = adt_def.name(); - Some((k, StructType { name, adt_def })) + let fields = rustc_internal::internal(tcx, adt_def) + .all_fields() // is_struct, so only one variant + .map(move |field| tcx.type_of(field.did).instantiate_identity()) + .map(rustc_internal::stable) + .collect(); + Some(( + k, + StructType { + name, + adt_def, + fields, + }, + )) } // for unions, we only record the name T(Adt(adt_def, _)) if t.is_union() => { diff --git a/tests/integration/normalise-filter.jq b/tests/integration/normalise-filter.jq index cf64f2d..8ef194a 100644 --- a/tests/integration/normalise-filter.jq +++ b/tests/integration/normalise-filter.jq @@ -13,9 +13,9 @@ types: ( [ # sort by constructors and remove unstable IDs within each ( .types | map(select(.[0].PrimitiveType)) | sort ), - # delete unstable adt_ref IDs + # delete unstable adt_ref IDs and struct field Ty IDs ( .types | map(select(.[0].EnumType) | del(.[0].EnumType.adt_def)) | sort ), - ( .types | map(select(.[0].StructType) | del(.[0].StructType.adt_def)) | sort ), + ( .types | map(select(.[0].StructType) | del(.[0].StructType.adt_def) | .[0].StructType.fields = "elided" ) | sort ), ( .types | map(select(.[0].UnionType) | del(.[0].UnionType.adt_def)) | sort ), # delete unstable Ty IDs for arrays and tuples ( .types | map(select(.[0].ArrayType) | del(.[0].ArrayType[0]) | del(.[0].ArrayType[0].id)) | sort ), diff --git a/tests/integration/programs/assert_eq.smir.json.expected b/tests/integration/programs/assert_eq.smir.json.expected index d7fe06d..b1b9e52 100644 --- a/tests/integration/programs/assert_eq.smir.json.expected +++ b/tests/integration/programs/assert_eq.smir.json.expected @@ -3227,6 +3227,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::fmt::Arguments" } } @@ -3234,6 +3235,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::fmt::Error" } } @@ -3241,6 +3243,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::fmt::Formatter" } } @@ -3248,6 +3251,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -3255,6 +3259,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -3262,6 +3267,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/binop.smir.json.expected b/tests/integration/programs/binop.smir.json.expected index e37d11b..2edfbc7 100644 --- a/tests/integration/programs/binop.smir.json.expected +++ b/tests/integration/programs/binop.smir.json.expected @@ -9770,6 +9770,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -9777,6 +9778,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -9784,6 +9786,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/char-trivial.smir.json.expected b/tests/integration/programs/char-trivial.smir.json.expected index 88dd560..04ca180 100644 --- a/tests/integration/programs/char-trivial.smir.json.expected +++ b/tests/integration/programs/char-trivial.smir.json.expected @@ -1689,6 +1689,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1696,6 +1697,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1703,6 +1705,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/closure-args.smir.json.expected b/tests/integration/programs/closure-args.smir.json.expected index 66dbb0a..9c34168 100644 --- a/tests/integration/programs/closure-args.smir.json.expected +++ b/tests/integration/programs/closure-args.smir.json.expected @@ -1980,6 +1980,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1987,6 +1988,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1994,6 +1996,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/closure-no-args.smir.json.expected b/tests/integration/programs/closure-no-args.smir.json.expected index 1d41e4a..642f5af 100644 --- a/tests/integration/programs/closure-no-args.smir.json.expected +++ b/tests/integration/programs/closure-no-args.smir.json.expected @@ -1802,6 +1802,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1809,6 +1810,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1816,6 +1818,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/const-arithm-simple.smir.json.expected b/tests/integration/programs/const-arithm-simple.smir.json.expected index 516cd98..4017f61 100644 --- a/tests/integration/programs/const-arithm-simple.smir.json.expected +++ b/tests/integration/programs/const-arithm-simple.smir.json.expected @@ -1950,6 +1950,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1957,6 +1958,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1964,6 +1966,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/div.smir.json.expected b/tests/integration/programs/div.smir.json.expected index 88f5d8a..0378460 100644 --- a/tests/integration/programs/div.smir.json.expected +++ b/tests/integration/programs/div.smir.json.expected @@ -2056,6 +2056,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2063,6 +2064,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2070,6 +2072,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/double-ref-deref.smir.json.expected b/tests/integration/programs/double-ref-deref.smir.json.expected index e84e0d2..5d7f7fc 100644 --- a/tests/integration/programs/double-ref-deref.smir.json.expected +++ b/tests/integration/programs/double-ref-deref.smir.json.expected @@ -1802,6 +1802,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1809,6 +1810,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1816,6 +1818,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/enum.smir.json.expected b/tests/integration/programs/enum.smir.json.expected index 99e5795..9e42375 100644 --- a/tests/integration/programs/enum.smir.json.expected +++ b/tests/integration/programs/enum.smir.json.expected @@ -1518,6 +1518,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1525,6 +1526,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/fibonacci.smir.json.expected b/tests/integration/programs/fibonacci.smir.json.expected index f2d492f..4dadef9 100644 --- a/tests/integration/programs/fibonacci.smir.json.expected +++ b/tests/integration/programs/fibonacci.smir.json.expected @@ -2368,6 +2368,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2375,6 +2376,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2382,6 +2384,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/float.smir.json.expected b/tests/integration/programs/float.smir.json.expected index 5f90c5c..a47af87 100644 --- a/tests/integration/programs/float.smir.json.expected +++ b/tests/integration/programs/float.smir.json.expected @@ -2273,6 +2273,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2280,6 +2281,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2287,6 +2289,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/modulo.smir.json.expected b/tests/integration/programs/modulo.smir.json.expected index fee6c93..27f0fde 100644 --- a/tests/integration/programs/modulo.smir.json.expected +++ b/tests/integration/programs/modulo.smir.json.expected @@ -2054,6 +2054,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2061,6 +2062,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2068,6 +2070,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/mutual_recursion.smir.json.expected b/tests/integration/programs/mutual_recursion.smir.json.expected index cd2dfe0..a8616e2 100644 --- a/tests/integration/programs/mutual_recursion.smir.json.expected +++ b/tests/integration/programs/mutual_recursion.smir.json.expected @@ -2319,6 +2319,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2326,6 +2327,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2333,6 +2335,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/option-construction.smir.json.expected b/tests/integration/programs/option-construction.smir.json.expected index 2d78415..117471f 100644 --- a/tests/integration/programs/option-construction.smir.json.expected +++ b/tests/integration/programs/option-construction.smir.json.expected @@ -1859,6 +1859,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1866,6 +1867,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1873,6 +1875,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/primitive-type-bounds.smir.json.expected b/tests/integration/programs/primitive-type-bounds.smir.json.expected index 117c8c1..c3bd408 100644 --- a/tests/integration/programs/primitive-type-bounds.smir.json.expected +++ b/tests/integration/programs/primitive-type-bounds.smir.json.expected @@ -1926,6 +1926,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1933,6 +1934,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1940,6 +1942,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/recursion-simple-match.smir.json.expected b/tests/integration/programs/recursion-simple-match.smir.json.expected index 733e85c..b867356 100644 --- a/tests/integration/programs/recursion-simple-match.smir.json.expected +++ b/tests/integration/programs/recursion-simple-match.smir.json.expected @@ -2128,6 +2128,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2135,6 +2136,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2142,6 +2144,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/recursion-simple.smir.json.expected b/tests/integration/programs/recursion-simple.smir.json.expected index 6afdbc0..82c7323 100644 --- a/tests/integration/programs/recursion-simple.smir.json.expected +++ b/tests/integration/programs/recursion-simple.smir.json.expected @@ -2128,6 +2128,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2135,6 +2136,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2142,6 +2144,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/ref-deref.smir.json.expected b/tests/integration/programs/ref-deref.smir.json.expected index 11f103e..e3f520e 100644 --- a/tests/integration/programs/ref-deref.smir.json.expected +++ b/tests/integration/programs/ref-deref.smir.json.expected @@ -1748,6 +1748,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1755,6 +1756,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1762,6 +1764,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/shl_min.smir.json.expected b/tests/integration/programs/shl_min.smir.json.expected index 2eeb432..2e37932 100644 --- a/tests/integration/programs/shl_min.smir.json.expected +++ b/tests/integration/programs/shl_min.smir.json.expected @@ -3568,6 +3568,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -3575,6 +3576,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -3582,6 +3584,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/slice.smir.json.expected b/tests/integration/programs/slice.smir.json.expected index 5c5fe47..052ee0e 100644 --- a/tests/integration/programs/slice.smir.json.expected +++ b/tests/integration/programs/slice.smir.json.expected @@ -4593,6 +4593,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::array::TryFromSliceError" } } @@ -4600,6 +4601,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::ops::Range" } } @@ -4607,6 +4609,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -4614,6 +4617,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -4621,6 +4625,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/strange-ref-deref.smir.json.expected b/tests/integration/programs/strange-ref-deref.smir.json.expected index c7beccf..9e0e99a 100644 --- a/tests/integration/programs/strange-ref-deref.smir.json.expected +++ b/tests/integration/programs/strange-ref-deref.smir.json.expected @@ -1805,6 +1805,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1812,6 +1813,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1819,6 +1821,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/struct.smir.json.expected b/tests/integration/programs/struct.smir.json.expected index 5a6c32a..fd1ec2c 100644 --- a/tests/integration/programs/struct.smir.json.expected +++ b/tests/integration/programs/struct.smir.json.expected @@ -1962,6 +1962,7 @@ [ { "StructType": { + "fields": "elided", "name": "St" } } @@ -1969,6 +1970,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1976,6 +1978,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1983,6 +1986,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/sum-to-n.smir.json.expected b/tests/integration/programs/sum-to-n.smir.json.expected index ab55b9b..b52b5d9 100644 --- a/tests/integration/programs/sum-to-n.smir.json.expected +++ b/tests/integration/programs/sum-to-n.smir.json.expected @@ -2555,6 +2555,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2562,6 +2563,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2569,6 +2571,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/tuple-eq.smir.json.expected b/tests/integration/programs/tuple-eq.smir.json.expected index 896aba5..ba0c1e3 100644 --- a/tests/integration/programs/tuple-eq.smir.json.expected +++ b/tests/integration/programs/tuple-eq.smir.json.expected @@ -2505,6 +2505,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -2512,6 +2513,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -2519,6 +2521,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } } diff --git a/tests/integration/programs/tuples-simple.smir.json.expected b/tests/integration/programs/tuples-simple.smir.json.expected index 7dfc447..55ffc13 100644 --- a/tests/integration/programs/tuples-simple.smir.json.expected +++ b/tests/integration/programs/tuples-simple.smir.json.expected @@ -1801,6 +1801,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::panic::Location" } } @@ -1808,6 +1809,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::process::ExitCode" } } @@ -1815,6 +1817,7 @@ [ { "StructType": { + "fields": "elided", "name": "std::sys::pal::unix::process::process_common::ExitCode" } }