|
1 | | -// RUN: %target-swift-frontend %s -parse-as-library -module-name=test -emit-sil | %FileCheck %s |
2 | | -// RUN: %target-swift-frontend %s -parse-as-library -O -module-name=test -emit-sil | %FileCheck %s |
| 1 | +// RUN: %target-swift-frontend %s -parse-as-library -module-name=test -emit-sil | %FileCheck --check-prefix=SIL %s |
| 2 | +// RUN: %target-swift-frontend %s -parse-as-library -O -module-name=test -emit-sil | %FileCheck --check-prefix=SIL %s |
3 | 3 |
|
4 | | -struct S: Hashable, Sendable {} |
| 4 | +// RUN: %target-swift-frontend %s -parse-as-library -module-name=test -emit-ir | %FileCheck --check-prefix=IR %s |
| 5 | +// RUN: %target-swift-frontend %s -parse-as-library -O -module-name=test -emit-ir | %FileCheck --check-prefix=IR %s |
5 | 6 |
|
6 | | -public let metatype1 = Int.self |
7 | | -public let metatype2: Any.Type = Int.self |
8 | | -public let metatype3: Any.Type = S.self |
9 | | -public let metatype4: any (Hashable & Sendable).Type = Int.self |
10 | | -public let metatype5: any (Hashable & Sendable).Type = S.self |
11 | | -public let metatype6: Any.Type = Array<Int>.self |
12 | | -public let metatype7: any (Hashable & Sendable).Type = Array<Int>.self |
13 | | - |
14 | | -// CHECK: sil_global [let] @$s4test9metatype1Simvp : $@thin Int.Type = { |
15 | | -// CHECK-NEXT: %initval = metatype $@thin Int.Type |
16 | | -// CHECK-NEXT: } |
17 | | - |
18 | | -// CHECK: sil_global [let] @$s4test9metatype2ypXpvp : $@thick any Any.Type = { |
19 | | -// CHECK-NEXT: %0 = metatype $@thick Int.Type |
20 | | -// CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type |
21 | | -// CHECK-NEXT: } |
22 | | - |
23 | | -// CHECK: sil_global [let] @$s4test9metatype3ypXpvp : $@thick any Any.Type = { |
24 | | -// CHECK-NEXT: %0 = metatype $@thick S.Type |
25 | | -// CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type |
26 | | -// CHECK-NEXT: } |
| 7 | +public protocol MyProtocol {} |
| 8 | +public protocol MyProtocol2 {} |
27 | 9 |
|
28 | | -// CHECK: sil_global [let] @$s4test9metatype4SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type = { |
29 | | -// CHECK-NEXT: %0 = metatype $@thick Int.Type |
30 | | -// CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any (Hashable & Sendable).Type |
31 | | -// CHECK-NEXT: } |
| 10 | +public struct S: Hashable, Sendable, MyProtocol, MyProtocol2 {} |
| 11 | +extension Int: MyProtocol, MyProtocol2 {} |
32 | 12 |
|
33 | | -// CHECK: sil_global [let] @$s4test9metatype5SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type = { |
34 | | -// CHECK-NEXT: %0 = metatype $@thick S.Type |
35 | | -// CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any (Hashable & Sendable).Type |
36 | | -// CHECK-NEXT: } |
37 | | - |
38 | | -// CHECK: sil_global [let] @$s4test9metatype6ypXpvp : $@thick any Any.Type = { |
39 | | -// CHECK-NEXT: %0 = metatype $@thick Array<Int>.Type |
40 | | -// CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type |
41 | | -// CHECK-NEXT: } |
42 | | - |
43 | | -// CHECK: sil_global [let] @$s4test9metatype7SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type = { |
44 | | -// CHECK-NEXT: %0 = metatype $@thick Array<Int>.Type |
45 | | -// CHECK-NEXT: %initval = init_existential_metatype %0, $@thick any (Hashable & Sendable).Type |
46 | | -// CHECK-NEXT: } |
47 | | - |
48 | | -// These are not constant folded and stay as lazily-initialized |
49 | | -public let metatypeA: Any.Type = (Bool.random() ? Array<Int>.self : Array<Bool>.self).self |
50 | | -public let metatypeB: Any.Type = Mirror.self // resilient |
| 13 | +public let metatype1 = Int.self |
| 14 | +// SIL: sil_global [let] @$s4test9metatype1Simvp : $@thin Int.Type = { |
| 15 | +// SIL-NEXT: %initval = metatype $@thin Int.Type |
| 16 | +// SIL-NEXT: } |
| 17 | +public let metatype2 = S.self |
| 18 | +// SIL: sil_global [let] @$s4test9metatype2AA1SVmvp : $@thin S.Type = { |
| 19 | +// SIL-NEXT: %initval = metatype $@thin S.Type |
| 20 | +// SIL-NEXT: } |
| 21 | +public let metatype3: Any.Type = Int.self |
| 22 | +// SIL: sil_global [let] @$s4test9metatype3ypXpvp : $@thick any Any.Type = { |
| 23 | +// SIL-NEXT: %0 = metatype $@thick Int.Type // user: %1 |
| 24 | +// SIL-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type |
| 25 | +// SIL-NEXT: } |
| 26 | +public let metatype4: Any.Type = S.self |
| 27 | +// SIL: sil_global [let] @$s4test9metatype4ypXpvp : $@thick any Any.Type = { |
| 28 | +// SIL-NEXT: %0 = metatype $@thick S.Type // user: %1 |
| 29 | +// SIL-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type |
| 30 | +// SIL-NEXT: } |
| 31 | +public let metatype5: any MyProtocol.Type = Int.self |
| 32 | +// SIL: sil_global [let] @$s4test9metatype5AA10MyProtocol_pXpvp : $@thick any MyProtocol.Type = { |
| 33 | +// SIL-NEXT: %0 = metatype $@thick Int.Type // user: %1 |
| 34 | +// SIL-NEXT: %initval = init_existential_metatype %0, $@thick any MyProtocol.Type |
| 35 | +// SIL-NEXT: } |
| 36 | +public let metatype6: any MyProtocol.Type = S.self |
| 37 | +// SIL: sil_global [let] @$s4test9metatype6AA10MyProtocol_pXpvp : $@thick any MyProtocol.Type = { |
| 38 | +// SIL-NEXT: %0 = metatype $@thick S.Type // user: %1 |
| 39 | +// SIL-NEXT: %initval = init_existential_metatype %0, $@thick any MyProtocol.Type |
| 40 | +// SIL-NEXT: } |
| 41 | +public let metatype7: any (MyProtocol & MyProtocol2).Type = Int.self |
| 42 | +// SIL: sil_global [let] @$s4test9metatype7AA10MyProtocol_AA0C9Protocol2pXpvp : $@thick any (MyProtocol & MyProtocol2).Type = { |
| 43 | +// SIL-NEXT: %0 = metatype $@thick Int.Type // user: %1 |
| 44 | +// SIL-NEXT: %initval = init_existential_metatype %0, $@thick any (MyProtocol & MyProtocol2).Type |
| 45 | +// SIL-NEXT: } |
| 46 | +public let metatype8: any (MyProtocol & MyProtocol2).Type = S.self |
| 47 | +// SIL: sil_global [let] @$s4test9metatype8AA10MyProtocol_AA0C9Protocol2pXpvp : $@thick any (MyProtocol & MyProtocol2).Type = { |
| 48 | +// SIL-NEXT: %0 = metatype $@thick S.Type // user: %1 |
| 49 | +// SIL-NEXT: %initval = init_existential_metatype %0, $@thick any (MyProtocol & MyProtocol2).Type |
| 50 | +// SIL-NEXT: } |
| 51 | +public let metatype9: any Hashable.Type = Int.self |
| 52 | +// SIL: sil_global [let] @$s4test9metatype9SH_pXpvp : $@thick any Hashable.Type |
| 53 | +// SIL-EMPTY: |
| 54 | +public let metatype10: any Hashable.Type = S.self |
| 55 | +// SIL: sil_global [let] @$s4test10metatype10SH_pXpvp : $@thick any Hashable.Type |
| 56 | +// SIL-EMPTY: |
| 57 | +public let metatype11: any (Hashable & Sendable).Type = Int.self |
| 58 | +// SIL: sil_global [let] @$s4test10metatype11SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type |
| 59 | +// SIL-EMPTY: |
| 60 | +public let metatype12: any (Hashable & Sendable).Type = S.self |
| 61 | +// SIL: sil_global [let] @$s4test10metatype12SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type |
| 62 | +// SIL-EMPTY: |
| 63 | +public let metatype13: any (Hashable & MyProtocol).Type = Int.self |
| 64 | +// SIL: sil_global [let] @$s4test10metatype13SH_AA10MyProtocolpXpvp : $@thick any (Hashable & MyProtocol).Type |
| 65 | +// SIL-EMPTY: |
| 66 | +public let metatype14: any (Hashable & MyProtocol).Type = S.self |
| 67 | +// SIL: sil_global [let] @$s4test10metatype14SH_AA10MyProtocolpXpvp : $@thick any (Hashable & MyProtocol).Type |
| 68 | +// SIL-EMPTY: |
| 69 | +public let metatype15: Any.Type = Array<Int>.self |
| 70 | +// SIL: sil_global [let] @$s4test10metatype15ypXpvp : $@thick any Any.Type = { |
| 71 | +// SIL-NEXT: %0 = metatype $@thick Array<Int>.Type // user: %1 |
| 72 | +// SIL-NEXT: %initval = init_existential_metatype %0, $@thick any Any.Type |
| 73 | +// SIL-NEXT: } |
| 74 | +public let metatype16: any (Hashable & Sendable).Type = Array<Int>.self |
| 75 | +// SIL: sil_global [let] @$s4test10metatype16SH_s8SendablepXpvp : $@thick any (Hashable & Sendable).Type |
| 76 | +// SIL-EMPTY: |
| 77 | +public let metatype17: Any.Type = (Bool.random() ? Array<Int>.self : Array<Bool>.self).self |
| 78 | +// SIL: sil_global [let] @$s4test10metatype17ypXpvp : $@thick any Any.Type |
| 79 | +// SIL-EMPTY: |
| 80 | +public let metatype18: Any.Type = Mirror.self // resilient |
| 81 | +// SIL: sil_global [let] @$s4test10metatype18ypXpvp : $@thick any Any.Type |
| 82 | +// SIL-EMPTY: |
51 | 83 |
|
52 | | -// CHECK: sil_global private @$s4test9metatypeA_Wz : $Builtin.Word |
53 | | -// CHECK: sil_global [let] @$s4test9metatypeAypXpvp : $@thick any Any.Type |
54 | | -// CHECK: sil_global private @$s4test9metatypeB_Wz : $Builtin.Word |
55 | | -// CHECK: sil_global [let] @$s4test9metatypeBypXpvp : $@thick any Any.Type |
56 | | -// CHECK: sil private [global_init_once_fn] @$s4test9metatypeA_WZ : $@convention(c) (Builtin.RawPointer) -> () { |
57 | | -// CHECK: sil private [global_init_once_fn] @$s4test9metatypeB_WZ : $@convention(c) (Builtin.RawPointer) -> () { |
| 84 | +// IR: @"$s4test9metatype3ypXpvp" = {{.*}}constant ptr @"$sSiN" |
| 85 | +// IR: @"$s4test9metatype4ypXpvp" = {{.*}}constant ptr getelementptr inbounds{{.*}} ({{.*}}, ptr @"$s4test1SVMf", {{.*}}) |
| 86 | +// IR: @"$s4test9metatype5AA10MyProtocol_pXpvp" = {{.*}}constant <{ ptr, ptr }> <{ ptr @"$sSiN", ptr @"$sSi4test10MyProtocolAAWP" }> |
| 87 | +// IR: @"$s4test9metatype6AA10MyProtocol_pXpvp" = {{.*}}constant <{ ptr, ptr }> <{ ptr getelementptr inbounds{{.*}} ({{.*}}, ptr @"$s4test1SVMf", {{.*}}), ptr @"$s4test1SVAA10MyProtocolAAWP" }> |
| 88 | +// IR: @"$s4test9metatype7AA10MyProtocol_AA0C9Protocol2pXpvp" = {{.*}}constant <{ ptr, ptr, ptr }> <{ ptr @"$sSiN", ptr @"$sSi4test10MyProtocolAAWP", ptr @"$sSi4test11MyProtocol2AAWP" }> |
| 89 | +// IR: @"$s4test9metatype8AA10MyProtocol_AA0C9Protocol2pXpvp" = {{.*}}constant <{ ptr, ptr, ptr }> <{ ptr getelementptr inbounds{{.*}} ({{.*}}, ptr @"$s4test1SVMf", {{.*}}), ptr @"$s4test1SVAA10MyProtocolAAWP", ptr @"$s4test1SVAA11MyProtocol2AAWP" }> |
| 90 | +// IR: @"$s4test10metatype15ypXpvp" = {{.*}}constant ptr getelementptr inbounds{{.*}} ({{.*}}, ptr @"$sSaySiGMf", {{.*}}) |
0 commit comments