Skip to content

Commit 2a59732

Browse files
committed
Merge branch 'master' into guy/ty_visitor
2 parents 293f1d8 + 304e0eb commit 2a59732

29 files changed

+2153
-323
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ jobs:
6666
6767
- name: 'Run smir integration tests'
6868
run: |
69+
which jq
70+
jq --version
6971
make integration-test
7072
7173
ui-tests:

src/printer.rs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,19 +954,32 @@ pub enum TypeMetadata {
954954
name: String,
955955
adt_def: AdtDef,
956956
},
957+
UnionType {
958+
name: String,
959+
adt_def: AdtDef,
960+
},
961+
ArrayType(stable_mir::ty::Ty, Option<stable_mir::ty::TyConst>),
962+
PtrType(stable_mir::ty::Ty),
963+
RefType(stable_mir::ty::Ty),
964+
TupleType {
965+
types: Vec<stable_mir::ty::Ty>,
966+
},
967+
FunType(String),
957968
}
958969

959970
fn mk_type_metadata(
960971
tcx: TyCtxt<'_>,
961972
k: stable_mir::ty::Ty,
962973
t: TyKind,
963974
) -> Option<(stable_mir::ty::Ty, TypeMetadata)> {
975+
use stable_mir::ty::RigidTy::*;
976+
use TyKind::RigidTy as T;
964977
use TypeMetadata::*;
965978
match t {
966-
TyKind::RigidTy(prim_type) if t.is_primitive() => Some((k, PrimitiveType(prim_type))),
979+
T(prim_type) if t.is_primitive() => Some((k, PrimitiveType(prim_type))),
967980
// for enums, we need a mapping of variantIdx to discriminant
968981
// this requires access to the internals and is not provided as an interface function at the moment
969-
TyKind::RigidTy(RigidTy::Adt(adt_def, _)) if t.is_enum() => {
982+
T(Adt(adt_def, _)) if t.is_enum() => {
970983
let adt_internal = rustc_internal::internal(tcx, adt_def);
971984
let discriminants = adt_internal
972985
.discriminants(tcx)
@@ -983,11 +996,35 @@ fn mk_type_metadata(
983996
))
984997
}
985998
// for structs, we record the name for information purposes
986-
TyKind::RigidTy(RigidTy::Adt(adt_def, _)) if t.is_struct() => {
999+
T(Adt(adt_def, _)) if t.is_struct() => {
9871000
let name = adt_def.name();
9881001
Some((k, StructType { name, adt_def }))
9891002
}
990-
_ => None,
1003+
// for unions, we only record the name
1004+
T(Adt(adt_def, _)) if t.is_union() => {
1005+
let name = adt_def.name();
1006+
Some((k, UnionType { name, adt_def }))
1007+
}
1008+
// encode str together with primitive types
1009+
T(Str) => Some((k, PrimitiveType(Str))),
1010+
// for arrays and slices, record element type and optional size
1011+
T(Array(ty, ty_const)) => Some((k, ArrayType(ty, Some(ty_const)))),
1012+
T(Slice(ty)) => Some((k, ArrayType(ty, None))),
1013+
// for raw pointers and references store the pointee type
1014+
T(RawPtr(ty, _)) => Some((k, PtrType(ty))),
1015+
T(Ref(_, ty, _)) => Some((k, RefType(ty))),
1016+
// for tuples the element types are provided
1017+
T(Tuple(tys)) => Some((k, TupleType { types: tys })),
1018+
// opaque function types (fun ptrs, closures, FnDef) are only provided to avoid dangling ty references
1019+
T(FnDef(_, _)) | T(FnPtr(_)) | T(Closure(_, _)) => Some((k, FunType(format!("{}", k)))),
1020+
// other types are not provided either
1021+
T(Foreign(_))
1022+
| T(Pat(_, _))
1023+
| T(Coroutine(_, _, _))
1024+
| T(Dynamic(_, _, _))
1025+
| T(CoroutineWitness(_, _)) => None,
1026+
TyKind::Alias(_, _) | TyKind::Param(_) | TyKind::Bound(_, _) => None,
1027+
_ => None, // redundant because of first 4 cases, but rustc does not understand that
9911028
}
9921029
}
9931030

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
# Remove the hashes at the end of mangled names
22
.functions = ( [ .functions[] | if .[1].NormalSym then .[1].NormalSym = .[1].NormalSym[:-17] else . end ] )
33
| .items = ( [ .items[] | if .symbol_name then .symbol_name = .symbol_name[:-17] else . end ] )
4+
# delete unstable alloc, function, and type IDs
5+
| .allocs = ( [ .allocs[] ] | map(del(.[0])) )
6+
| .functions = ( [ .functions[] ] | map(del(.[0])) )
7+
| .types = ( [ .types[] ] | map(del(.[0])) )
48
|
59
# Apply the normalisation filter
6-
{ allocs:
7-
( [ .allocs[] ]
8-
# delete unstable alloc ID
9-
| map(del(.[0]))
10-
),
11-
functions:
12-
( [ .functions[] ]
13-
# delete unstable function ID
14-
| map(del(.[0]))
15-
),
16-
items:
17-
( [ .items[] ]
18-
),
19-
types:
20-
( [ .types[] ]
21-
# delete unstable Ty ID (int, first in list)
22-
| map(del(.[0]))
23-
# delete unstable adt_def from Struct and Enum
24-
| map(del(.[0].StructType.adt_def))
25-
| map(del(.[0].EnumType.adt_def))
26-
)
10+
{ allocs: .allocs,
11+
functions: .functions,
12+
items: .items,
13+
types: ( [
14+
# sort by constructors and remove unstable IDs within each
15+
( .types | map(select(.[0].PrimitiveType)) ),
16+
# delete unstable adt_ref IDs
17+
( .types | map(select(.[0].EnumType) | del(.[0].EnumType.adt_def)) ),
18+
( .types | map(select(.[0].StructType) | del(.[0].StructType.adt_def)) ),
19+
( .types | map(select(.[0].UnionType) | del(.[0].UnionType.adt_def)) ),
20+
# delete unstable Ty IDs for arrays and tuples
21+
( .types | map(select(.[0].ArrayType) | del(.[0].ArrayType[0])) ),
22+
( .types | map(select(.[0].TupleType) | .[0].TupleType.types = "elided") ),
23+
# replace unstable Ty IDs for references by zero
24+
( .types | map(select(.[0].PtrType) | .[0].PtrType = "elided") ),
25+
( .types | map(select(.[0].RefType) | .[0].RefType = "elided") ),
26+
# keep function type strings
27+
( .types | map(select(.[0].FunType) | .[0].FunType = "elided") )
28+
] | flatten(1) )
2729
}

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

Lines changed: 124 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,24 +3122,36 @@
31223122
[
31233123
{
31243124
"PrimitiveType": {
3125-
"Int": "I8"
3125+
"Int": "Isize"
31263126
}
31273127
}
31283128
],
31293129
[
31303130
{
31313131
"PrimitiveType": {
3132-
"Int": "Isize"
3132+
"Uint": "U8"
31333133
}
31343134
}
31353135
],
31363136
[
31373137
{
31383138
"PrimitiveType": {
3139-
"Uint": "U8"
3139+
"Int": "I32"
31403140
}
31413141
}
31423142
],
3143+
[
3144+
{
3145+
"PrimitiveType": {
3146+
"Uint": "U32"
3147+
}
3148+
}
3149+
],
3150+
[
3151+
{
3152+
"PrimitiveType": "Bool"
3153+
}
3154+
],
31433155
[
31443156
{
31453157
"EnumType": {
@@ -3157,27 +3169,6 @@
31573169
}
31583170
}
31593171
],
3160-
[
3161-
{
3162-
"StructType": {
3163-
"name": "std::sys::pal::unix::process::process_common::ExitCode"
3164-
}
3165-
}
3166-
],
3167-
[
3168-
{
3169-
"PrimitiveType": {
3170-
"Int": "I32"
3171-
}
3172-
}
3173-
],
3174-
[
3175-
{
3176-
"StructType": {
3177-
"name": "std::process::ExitCode"
3178-
}
3179-
}
3180-
],
31813172
[
31823173
{
31833174
"EnumType": {
@@ -3195,13 +3186,6 @@
31953186
}
31963187
}
31973188
],
3198-
[
3199-
{
3200-
"PrimitiveType": {
3201-
"Uint": "U32"
3202-
}
3203-
}
3204-
],
32053189
[
32063190
{
32073191
"EnumType": {
@@ -3242,7 +3226,16 @@
32423226
],
32433227
[
32443228
{
3245-
"PrimitiveType": "Bool"
3229+
"StructType": {
3230+
"name": "std::sys::pal::unix::process::process_common::ExitCode"
3231+
}
3232+
}
3233+
],
3234+
[
3235+
{
3236+
"StructType": {
3237+
"name": "std::process::ExitCode"
3238+
}
32463239
}
32473240
],
32483241
[
@@ -3252,6 +3245,13 @@
32523245
}
32533246
}
32543247
],
3248+
[
3249+
{
3250+
"StructType": {
3251+
"name": "std::fmt::Formatter"
3252+
}
3253+
}
3254+
],
32553255
[
32563256
{
32573257
"StructType": {
@@ -3262,9 +3262,100 @@
32623262
[
32633263
{
32643264
"StructType": {
3265-
"name": "std::fmt::Formatter"
3265+
"name": "std::panic::Location"
32663266
}
32673267
}
3268+
],
3269+
[
3270+
{
3271+
"TupleType": {
3272+
"types": "elided"
3273+
}
3274+
}
3275+
],
3276+
[
3277+
{
3278+
"TupleType": {
3279+
"types": "elided"
3280+
}
3281+
}
3282+
],
3283+
[
3284+
{
3285+
"TupleType": {
3286+
"types": "elided"
3287+
}
3288+
}
3289+
],
3290+
[
3291+
{
3292+
"PtrType": "elided"
3293+
}
3294+
],
3295+
[
3296+
{
3297+
"PtrType": "elided"
3298+
}
3299+
],
3300+
[
3301+
{
3302+
"PtrType": "elided"
3303+
}
3304+
],
3305+
[
3306+
{
3307+
"PtrType": "elided"
3308+
}
3309+
],
3310+
[
3311+
{
3312+
"RefType": "elided"
3313+
}
3314+
],
3315+
[
3316+
{
3317+
"RefType": "elided"
3318+
}
3319+
],
3320+
[
3321+
{
3322+
"RefType": "elided"
3323+
}
3324+
],
3325+
[
3326+
{
3327+
"RefType": "elided"
3328+
}
3329+
],
3330+
[
3331+
{
3332+
"RefType": "elided"
3333+
}
3334+
],
3335+
[
3336+
{
3337+
"RefType": "elided"
3338+
}
3339+
],
3340+
[
3341+
{
3342+
"RefType": "elided"
3343+
}
3344+
],
3345+
[
3346+
{
3347+
"RefType": "elided"
3348+
}
3349+
],
3350+
[
3351+
{
3352+
"RefType": "elided"
3353+
}
3354+
],
3355+
[
3356+
{
3357+
"FunType": "elided"
3358+
}
32683359
]
32693360
]
32703361
}

0 commit comments

Comments
 (0)