Skip to content

Commit 180bfb4

Browse files
authored
Add a list of field types to struct type metadata (#82)
This adds the field types of the single variant of a `struct` `RigidTy::Adt` to the type metadata, similar to the `types` field of `TupleType` Closes #81
1 parent f452197 commit 180bfb4

27 files changed

+97
-4
lines changed

src/printer.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ pub enum TypeMetadata {
987987
StructType {
988988
name: String,
989989
adt_def: AdtDef,
990+
fields: Vec<stable_mir::ty::Ty>,
990991
},
991992
UnionType {
992993
name: String,
@@ -1029,10 +1030,22 @@ fn mk_type_metadata(
10291030
},
10301031
))
10311032
}
1032-
// for structs, we record the name for information purposes
1033+
// for structs, we record the name for information purposes and the field types
10331034
T(Adt(adt_def, _)) if t.is_struct() => {
10341035
let name = adt_def.name();
1035-
Some((k, StructType { name, adt_def }))
1036+
let fields = rustc_internal::internal(tcx, adt_def)
1037+
.all_fields() // is_struct, so only one variant
1038+
.map(move |field| tcx.type_of(field.did).instantiate_identity())
1039+
.map(rustc_internal::stable)
1040+
.collect();
1041+
Some((
1042+
k,
1043+
StructType {
1044+
name,
1045+
adt_def,
1046+
fields,
1047+
},
1048+
))
10361049
}
10371050
// for unions, we only record the name
10381051
T(Adt(adt_def, _)) if t.is_union() => {

tests/integration/normalise-filter.jq

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
types: ( [
1414
# sort by constructors and remove unstable IDs within each
1515
( .types | map(select(.[0].PrimitiveType)) | sort ),
16-
# delete unstable adt_ref IDs
16+
# delete unstable adt_ref IDs and struct field Ty IDs
1717
( .types | map(select(.[0].EnumType) | del(.[0].EnumType.adt_def)) | sort ),
18-
( .types | map(select(.[0].StructType) | del(.[0].StructType.adt_def)) | sort ),
18+
( .types | map(select(.[0].StructType) | del(.[0].StructType.adt_def) | .[0].StructType.fields = "elided" ) | sort ),
1919
( .types | map(select(.[0].UnionType) | del(.[0].UnionType.adt_def)) | sort ),
2020
# delete unstable Ty IDs for arrays and tuples
2121
( .types | map(select(.[0].ArrayType) | del(.[0].ArrayType[0]) | del(.[0].ArrayType[0].id)) | sort ),

tests/integration/programs/assert_eq.smir.json.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,41 +3227,47 @@
32273227
[
32283228
{
32293229
"StructType": {
3230+
"fields": "elided",
32303231
"name": "std::fmt::Arguments"
32313232
}
32323233
}
32333234
],
32343235
[
32353236
{
32363237
"StructType": {
3238+
"fields": "elided",
32373239
"name": "std::fmt::Error"
32383240
}
32393241
}
32403242
],
32413243
[
32423244
{
32433245
"StructType": {
3246+
"fields": "elided",
32443247
"name": "std::fmt::Formatter"
32453248
}
32463249
}
32473250
],
32483251
[
32493252
{
32503253
"StructType": {
3254+
"fields": "elided",
32513255
"name": "std::panic::Location"
32523256
}
32533257
}
32543258
],
32553259
[
32563260
{
32573261
"StructType": {
3262+
"fields": "elided",
32583263
"name": "std::process::ExitCode"
32593264
}
32603265
}
32613266
],
32623267
[
32633268
{
32643269
"StructType": {
3270+
"fields": "elided",
32653271
"name": "std::sys::pal::unix::process::process_common::ExitCode"
32663272
}
32673273
}

tests/integration/programs/binop.smir.json.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9770,20 +9770,23 @@
97709770
[
97719771
{
97729772
"StructType": {
9773+
"fields": "elided",
97739774
"name": "std::panic::Location"
97749775
}
97759776
}
97769777
],
97779778
[
97789779
{
97799780
"StructType": {
9781+
"fields": "elided",
97809782
"name": "std::process::ExitCode"
97819783
}
97829784
}
97839785
],
97849786
[
97859787
{
97869788
"StructType": {
9789+
"fields": "elided",
97879790
"name": "std::sys::pal::unix::process::process_common::ExitCode"
97889791
}
97899792
}

tests/integration/programs/char-trivial.smir.json.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,20 +1689,23 @@
16891689
[
16901690
{
16911691
"StructType": {
1692+
"fields": "elided",
16921693
"name": "std::panic::Location"
16931694
}
16941695
}
16951696
],
16961697
[
16971698
{
16981699
"StructType": {
1700+
"fields": "elided",
16991701
"name": "std::process::ExitCode"
17001702
}
17011703
}
17021704
],
17031705
[
17041706
{
17051707
"StructType": {
1708+
"fields": "elided",
17061709
"name": "std::sys::pal::unix::process::process_common::ExitCode"
17071710
}
17081711
}

tests/integration/programs/closure-args.smir.json.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,20 +1980,23 @@
19801980
[
19811981
{
19821982
"StructType": {
1983+
"fields": "elided",
19831984
"name": "std::panic::Location"
19841985
}
19851986
}
19861987
],
19871988
[
19881989
{
19891990
"StructType": {
1991+
"fields": "elided",
19901992
"name": "std::process::ExitCode"
19911993
}
19921994
}
19931995
],
19941996
[
19951997
{
19961998
"StructType": {
1999+
"fields": "elided",
19972000
"name": "std::sys::pal::unix::process::process_common::ExitCode"
19982001
}
19992002
}

tests/integration/programs/closure-no-args.smir.json.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,20 +1802,23 @@
18021802
[
18031803
{
18041804
"StructType": {
1805+
"fields": "elided",
18051806
"name": "std::panic::Location"
18061807
}
18071808
}
18081809
],
18091810
[
18101811
{
18111812
"StructType": {
1813+
"fields": "elided",
18121814
"name": "std::process::ExitCode"
18131815
}
18141816
}
18151817
],
18161818
[
18171819
{
18181820
"StructType": {
1821+
"fields": "elided",
18191822
"name": "std::sys::pal::unix::process::process_common::ExitCode"
18201823
}
18211824
}

tests/integration/programs/const-arithm-simple.smir.json.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,20 +1950,23 @@
19501950
[
19511951
{
19521952
"StructType": {
1953+
"fields": "elided",
19531954
"name": "std::panic::Location"
19541955
}
19551956
}
19561957
],
19571958
[
19581959
{
19591960
"StructType": {
1961+
"fields": "elided",
19601962
"name": "std::process::ExitCode"
19611963
}
19621964
}
19631965
],
19641966
[
19651967
{
19661968
"StructType": {
1969+
"fields": "elided",
19671970
"name": "std::sys::pal::unix::process::process_common::ExitCode"
19681971
}
19691972
}

tests/integration/programs/div.smir.json.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,20 +2056,23 @@
20562056
[
20572057
{
20582058
"StructType": {
2059+
"fields": "elided",
20592060
"name": "std::panic::Location"
20602061
}
20612062
}
20622063
],
20632064
[
20642065
{
20652066
"StructType": {
2067+
"fields": "elided",
20662068
"name": "std::process::ExitCode"
20672069
}
20682070
}
20692071
],
20702072
[
20712073
{
20722074
"StructType": {
2075+
"fields": "elided",
20732076
"name": "std::sys::pal::unix::process::process_common::ExitCode"
20742077
}
20752078
}

tests/integration/programs/double-ref-deref.smir.json.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,20 +1802,23 @@
18021802
[
18031803
{
18041804
"StructType": {
1805+
"fields": "elided",
18051806
"name": "std::panic::Location"
18061807
}
18071808
}
18081809
],
18091810
[
18101811
{
18111812
"StructType": {
1813+
"fields": "elided",
18121814
"name": "std::process::ExitCode"
18131815
}
18141816
}
18151817
],
18161818
[
18171819
{
18181820
"StructType": {
1821+
"fields": "elided",
18191822
"name": "std::sys::pal::unix::process::process_common::ExitCode"
18201823
}
18211824
}

0 commit comments

Comments
 (0)