Skip to content

Add a list of field types to struct type metadata #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ pub enum TypeMetadata {
StructType {
name: String,
adt_def: AdtDef,
fields: Vec<stable_mir::ty::Ty>,
},
UnionType {
name: String,
Expand Down Expand Up @@ -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() => {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/normalise-filter.jq
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/programs/assert_eq.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3227,41 +3227,47 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::fmt::Arguments"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::fmt::Error"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::fmt::Formatter"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/programs/binop.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -9770,20 +9770,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/programs/char-trivial.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1689,20 +1689,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/programs/closure-args.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1980,20 +1980,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/programs/closure-no-args.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1802,20 +1802,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1950,20 +1950,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/programs/div.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2056,20 +2056,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1802,20 +1802,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/programs/enum.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1518,13 +1518,15 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/programs/fibonacci.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2368,20 +2368,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/programs/float.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2273,20 +2273,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/programs/modulo.smir.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2054,20 +2054,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2319,20 +2319,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1859,20 +1859,23 @@
[
{
"StructType": {
"fields": "elided",
"name": "std::panic::Location"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::process::ExitCode"
}
}
],
[
{
"StructType": {
"fields": "elided",
"name": "std::sys::pal::unix::process::process_common::ExitCode"
}
}
Expand Down
Loading