1
- // RUN: %target-swift-frontend -disable-availability-checking -emit-silgen %s | %FileCheck %s
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
3
+ // RUN: %target-swift-frontend -I %t -disable-availability-checking -emit-silgen %s | %FileCheck %s
4
+
5
+ import resilient_struct
2
6
3
7
protocol P { }
4
8
protocol Q : AnyObject { }
@@ -10,39 +14,138 @@ class C: Q {}
10
14
11
15
// CHECK-LABEL: sil hidden {{.*}}11valueToAddr1xQr
12
16
func valueToAddr( x: String ) -> some P {
13
- // CHECK: [[UNDERLYING :%.*]] = unchecked_addr_cast %0
14
- // CHECK: [[VALUE_COPY:%.*]] = copy_value %1
15
- // CHECK: store [[VALUE_COPY]] to [init] [[UNDERLYING ]]
17
+ // CHECK: bb0([[ARG0 :%.*]] : $*String, [[ARG1:%.*]] : @guaranteed $String):
18
+ // CHECK: [[VALUE_COPY:%.*]] = copy_value [[ARG1]]
19
+ // CHECK: store [[VALUE_COPY]] to [init] [[ARG0 ]]
16
20
return x
17
21
}
18
22
19
23
// CHECK-LABEL: sil hidden {{.*}}10addrToAddr1xQr
20
24
func addrToAddr( x: AddrOnly ) -> some P {
21
- // CHECK: [[UNDERLYING :%.*]] = unchecked_addr_cast %0
22
- // CHECK: copy_addr %1 to [initialization] [[UNDERLYING ]]
25
+ // CHECK: bb0([[ARG0 :%.*]] : $*AddrOnly, [[ARG1:%.*]] : $*AddrOnly):
26
+ // CHECK: copy_addr [[ARG1]] to [initialization] [[ARG0 ]]
23
27
return x
24
28
}
25
29
26
30
// CHECK-LABEL: sil hidden {{.*}}13genericAddrToE01xQr
27
31
func genericAddrToAddr< T: P > ( x: T ) -> some P {
28
- // CHECK: [[UNDERLYING :%.*]] = unchecked_addr_cast %0
29
- // CHECK: copy_addr %1 to [initialization] [[UNDERLYING ]]
32
+ // CHECK: bb0([[ARG0 :%.*]] : $*T, [[ARG1:%.*]] : $*T):
33
+ // CHECK: copy_addr [[ARG1]] to [initialization] [[ARG0 ]]
30
34
return x
31
35
}
32
36
33
37
// CHECK-LABEL: sil hidden {{.*}}12valueToValue1xQr
34
38
func valueToValue( x: C ) -> some Q {
35
- // CHECK: [[VALUE_COPY :%.*]] = copy_value %0
36
- // CHECK: [[CAST_TO_OPAQUE :%.*]] = unchecked_ref_cast [[VALUE_COPY ]]
37
- // CHECK: return [[CAST_TO_OPAQUE ]]
39
+ // CHECK: bb0([[ARG :%.*]] : @guaranteed $C):
40
+ // CHECK: [[VALUE_COPY :%.*]] = copy_value [[ARG ]]
41
+ // CHECK: return [[VALUE_COPY ]]
38
42
return x
39
43
}
40
44
41
45
// CHECK-LABEL: sil hidden {{.*}}13reabstraction1xQr
42
46
func reabstraction( x: @escaping ( ) -> ( ) ) -> some Any {
43
- // CHECK: [[UNDERLYING:%.*]] = unchecked_addr_cast %0 : ${{.*}} to $*@callee_guaranteed () -> @out ()
44
- // CHECK: [[VALUE_COPY:%.*]] = copy_value %1
45
- // CHECK: [[VALUE_REABSTRACT:%.*]] = partial_apply [callee_guaranteed] {{%.*}}([[VALUE_COPY]])
46
- // CHECK: store [[VALUE_REABSTRACT]] to [init] [[UNDERLYING]]
47
+ // CHECK: bb0([[ARG0:%.*]] : $*@callee_guaranteed () -> @out (), [[ARG1:%.*]] : @guaranteed $@callee_guaranteed () -> ()):
48
+ // CHECK: [[VALUE_COPY:%.*]] = copy_value [[ARG1]]
49
+ // CHECK: [[REABSTRACT:%.*]] = function_ref @$sIeg_ytIegr_TR
50
+ // CHECK: [[THUNK:%.*]] = partial_apply [callee_guaranteed] [[REABSTRACT]]([[VALUE_COPY]])
51
+ // CHECK: store [[THUNK]] to [init] [[ARG0]]
47
52
return x
48
53
}
54
+
55
+ protocol X {
56
+ associatedtype A
57
+ func foo( ) -> A
58
+ }
59
+
60
+ extension Int : P { }
61
+
62
+ extension ResilientInt : P { }
63
+
64
+ class K : P { }
65
+
66
+ func useClosure2( _ cl: ( ) -> ( ) ) { }
67
+
68
+ func useClosure( _ cl: @escaping ( ) -> ( ) ) {
69
+ cl ( )
70
+ }
71
+
72
+ struct S : X {
73
+
74
+ func foo( ) -> some P {
75
+ return returnTrivial ( )
76
+ }
77
+
78
+ func returnTrivial( ) -> some P {
79
+ return 1
80
+ }
81
+
82
+ func returnClass( ) -> some P {
83
+ return K ( )
84
+ }
85
+
86
+ func returnResilient( ) -> some P {
87
+ return ResilientInt ( i: 1 )
88
+ }
89
+
90
+ func testCapture( ) {
91
+ var someP = returnTrivial ( )
92
+ var someK = returnClass ( )
93
+ var someR = returnResilient ( )
94
+ useClosure {
95
+ someP = self . returnTrivial ( )
96
+ someK = self . returnClass ( )
97
+ someR = self . returnResilient ( )
98
+ }
99
+ print ( someP)
100
+ print ( someK)
101
+ print ( someR)
102
+ }
103
+
104
+ func testCapture2( ) {
105
+ var someP = returnTrivial ( )
106
+ var someK = returnClass ( )
107
+ var someR = returnResilient ( )
108
+ useClosure2 {
109
+ someP = self . returnTrivial ( )
110
+ someK = self . returnClass ( )
111
+ someR = self . returnResilient ( )
112
+ }
113
+ print ( someP)
114
+ print ( someK)
115
+ print ( someR)
116
+ }
117
+
118
+ func testCapture3( ) {
119
+ let someP = returnTrivial ( )
120
+ let someK = returnClass ( )
121
+ let someR = returnResilient ( )
122
+ useClosure {
123
+ print ( someP)
124
+ print ( someK)
125
+ print ( someR)
126
+ }
127
+ }
128
+
129
+ func testCapture4( ) {
130
+ let someP = returnTrivial ( )
131
+ let someK = returnClass ( )
132
+ let someR = returnResilient ( )
133
+ useClosure {
134
+ print ( someP)
135
+ print ( someK)
136
+ print ( someR)
137
+ }
138
+ }
139
+ }
140
+
141
+ extension Optional : P { }
142
+
143
+ struct S2 : X {
144
+ func foo( ) -> some P {
145
+ let x : Optional = 1
146
+ return x
147
+ }
148
+ func returnFunctionType( ) -> ( ) -> A {
149
+ return foo
150
+ }
151
+ }
0 commit comments