@@ -44,6 +44,18 @@ public enum NonTrivialEnum {
44
44
case third( NonTrivialStruct )
45
45
}
46
46
47
+ @_moveOnly
48
+ public struct AddressOnlyGeneric < T> {
49
+ var t : T
50
+ }
51
+
52
+ public protocol P { }
53
+
54
+ @_moveOnly
55
+ public struct AddressOnlyProtocol {
56
+ var t : P
57
+ }
58
+
47
59
var varGlobal = NonTrivialStruct ( )
48
60
let letGlobal = NonTrivialStruct ( )
49
61
@@ -54,6 +66,8 @@ public func borrowVal(_ k: borrowing NonTrivialCopyableStruct) {}
54
66
public func borrowVal( _ k: borrowing NonTrivialCopyableStruct2 ) { }
55
67
public func borrowVal( _ s: borrowing NonTrivialStruct ) { }
56
68
public func borrowVal( _ s: borrowing NonTrivialStruct2 ) { }
69
+ public func borrowVal< T> ( _ s: borrowing AddressOnlyGeneric < T > ) { }
70
+ public func borrowVal( _ s: borrowing AddressOnlyProtocol ) { }
57
71
58
72
public func consumeVal( _ e : __owned NonTrivialEnum) { }
59
73
public func consumeVal( _ e : __owned FD) { }
@@ -62,6 +76,8 @@ public func consumeVal(_ k: __owned NonTrivialCopyableStruct) {}
62
76
public func consumeVal( _ k: __owned NonTrivialCopyableStruct2 ) { }
63
77
public func consumeVal( _ s: __owned NonTrivialStruct) { }
64
78
public func consumeVal( _ s: __owned NonTrivialStruct2 ) { }
79
+ public func consumeVal< T> ( _ s: __owned AddressOnlyGeneric< T > ) { }
80
+ public func consumeVal( _ s: __owned AddressOnlyProtocol) { }
65
81
66
82
var bool : Bool { false }
67
83
@@ -137,6 +153,58 @@ public func useNonTrivialOwnedEnum(_ s: __owned NonTrivialEnum) {
137
153
let _ = s2
138
154
}
139
155
156
+ // CHECK-LABEL: sil [ossa] @$s8moveonly21useAddressOnlyGenericyyAA0cdE0VyxGhlF : $@convention(thin) <T> (@in_guaranteed AddressOnlyGeneric<T>) -> () {
157
+ // CHECK: bb0([[ARG:%.*]] :
158
+ // CHECK: mark_must_check [no_consume_or_assign] [[ARG]]
159
+ // CHECK: } // end sil function '$s8moveonly21useAddressOnlyGenericyyAA0cdE0VyxGhlF'
160
+ public func useAddressOnlyGeneric< T> ( _ s: __shared AddressOnlyGeneric< T > ) {
161
+ borrowVal ( s)
162
+ let s2 = s
163
+ let k = s. t
164
+ let _ = k
165
+ borrowVal ( s)
166
+ let _ = s2
167
+ }
168
+
169
+ // CHECK-LABEL: sil [ossa] @$s8moveonly26useOwnedAddressOnlyGenericyyAA0deF0VyxGnlF : $@convention(thin) <T> (@in AddressOnlyGeneric<T>) -> () {
170
+ // CHECK: bb0([[ARG:%.*]] :
171
+ // CHECK: mark_must_check [consumable_and_assignable] [[ARG]]
172
+ // CHECK: } // end sil function '$s8moveonly26useOwnedAddressOnlyGenericyyAA0deF0VyxGnlF'
173
+ public func useOwnedAddressOnlyGeneric< T> ( _ s: __owned AddressOnlyGeneric< T > ) {
174
+ borrowVal ( s)
175
+ let s2 = s
176
+ let k = s. t
177
+ let _ = k
178
+ borrowVal ( s)
179
+ let _ = s2
180
+ }
181
+
182
+ // CHECK-LABEL: sil [ossa] @$s8moveonly22useAddressOnlyProtocolyyAA0cdE0VhF : $@convention(thin) (@in_guaranteed AddressOnlyProtocol) -> () {
183
+ // CHECK: bb0([[ARG:%.*]] :
184
+ // CHECK: mark_must_check [no_consume_or_assign] [[ARG]]
185
+ // CHECK: } // end sil function '$s8moveonly22useAddressOnlyProtocolyyAA0cdE0VhF'
186
+ public func useAddressOnlyProtocol( _ s: __shared AddressOnlyProtocol) {
187
+ borrowVal ( s)
188
+ let s2 = s
189
+ let k = s. t
190
+ let _ = k
191
+ borrowVal ( s)
192
+ let _ = s2
193
+ }
194
+
195
+ // CHECK-LABEL: sil [ossa] @$s8moveonly27useOwnedAddressOnlyProtocolyyAA0deF0VnF : $@convention(thin) (@in AddressOnlyProtocol) -> () {
196
+ // CHECK: bb0([[ARG:%.*]] :
197
+ // CHECK: mark_must_check [consumable_and_assignable] [[ARG]]
198
+ // CHECK: } // end sil function '$s8moveonly27useOwnedAddressOnlyProtocolyyAA0deF0VnF'
199
+ public func useOwnedAddressOnlyProtocol( _ s: __owned AddressOnlyProtocol) {
200
+ borrowVal ( s)
201
+ let s2 = s
202
+ let k = s. t
203
+ let _ = k
204
+ borrowVal ( s)
205
+ let _ = s2
206
+ }
207
+
140
208
//===---
141
209
// Self in Init
142
210
//
@@ -169,6 +237,73 @@ extension NonTrivialEnum {
169
237
}
170
238
}
171
239
240
+ extension AddressOnlyGeneric {
241
+ // CHECK-LABEL: sil hidden [ossa] @$s8moveonly18AddressOnlyGenericV13testNoUseSelfyyF : $@convention(method) <T> (@in_guaranteed AddressOnlyGeneric<T>) -> () {
242
+ // CHECK: bb0([[ARG_IN:%.*]] :
243
+ // CHECK: [[ARG:%.*]] = mark_must_check [no_consume_or_assign] [[ARG_IN]] :
244
+ //
245
+ // CHECK: [[ALLOC_X:%.*]] = alloc_box $<τ_0_0> { let AddressOnlyGeneric<τ_0_0> } <T>, let, name "x"
246
+ // CHECK: [[X:%.*]] = begin_borrow [lexical] [[ALLOC_X]]
247
+ // CHECK: [[PROJECT_X:%.*]] = project_box [[X]]
248
+ // CHECK: copy_addr [[ARG]] to [init] [[PROJECT_X]]
249
+ // CHECK: [[MARKED_X:%.*]] = mark_must_check [no_consume_or_assign] [[PROJECT_X]]
250
+ // CHECK: [[BLACKHOLE_ADDR:%.*]] = alloc_stack $AddressOnlyGeneric<T>
251
+ // CHECK: copy_addr [[MARKED_X]] to [init] [[BLACKHOLE_ADDR]]
252
+ // CHECK: destroy_addr [[BLACKHOLE_ADDR]]
253
+ // CHECK: dealloc_stack [[BLACKHOLE_ADDR]]
254
+ //
255
+ // CHECK: [[ALLOC_Y:%.*]] = alloc_box $<τ_0_0> { let AddressOnlyGeneric<τ_0_0> } <T>, let, name "y"
256
+ // CHECK: [[Y:%.*]] = begin_borrow [lexical] [[ALLOC_Y]]
257
+ // CHECK: [[PROJECT_Y:%.*]] = project_box [[Y]]
258
+ // CHECK: copy_addr [[ARG]] to [init] [[PROJECT_Y]]
259
+ // CHECK: [[MARKED_Y:%.*]] = mark_must_check [no_consume_or_assign] [[PROJECT_Y]]
260
+ // CHECK: [[BLACKHOLE_ADDR:%.*]] = alloc_stack $AddressOnlyGeneric<T>
261
+ // CHECK: copy_addr [[MARKED_Y]] to [init] [[BLACKHOLE_ADDR]]
262
+ // CHECK: destroy_addr [[BLACKHOLE_ADDR]]
263
+ // CHECK: dealloc_stack [[BLACKHOLE_ADDR]]
264
+ //
265
+ // CHECK: } // end sil function '$s8moveonly18AddressOnlyGenericV13testNoUseSelfyyF'
266
+ func testNoUseSelf( ) {
267
+ let x = self
268
+ let _ = x
269
+ let y = self
270
+ let _ = y
271
+ }
272
+ }
273
+
274
+ extension AddressOnlyProtocol {
275
+ // CHECK-LABEL: sil hidden [ossa] @$s8moveonly19AddressOnlyProtocolV13testNoUseSelfyyF : $@convention(method) (@in_guaranteed AddressOnlyProtocol) -> () {
276
+ // CHECK: bb0([[ARG_IN:%.*]] :
277
+ // CHECK: [[ARG:%.*]] = mark_must_check [no_consume_or_assign] [[ARG_IN]] :
278
+ //
279
+ // CHECK: [[ALLOC_X:%.*]] = alloc_box ${ let AddressOnlyProtocol }, let, name "x"
280
+ // CHECK: [[X:%.*]] = begin_borrow [lexical] [[ALLOC_X]]
281
+ // CHECK: [[PROJECT_X:%.*]] = project_box [[X]]
282
+ // CHECK: copy_addr [[ARG]] to [init] [[PROJECT_X]]
283
+ // CHECK: [[MARKED_X:%.*]] = mark_must_check [no_consume_or_assign] [[PROJECT_X]]
284
+ // CHECK: [[BLACKHOLE_ADDR:%.*]] = alloc_stack $AddressOnlyProtocol
285
+ // CHECK: copy_addr [[MARKED_X]] to [init] [[BLACKHOLE_ADDR]]
286
+ // CHECK: destroy_addr [[BLACKHOLE_ADDR]]
287
+ // CHECK: dealloc_stack [[BLACKHOLE_ADDR]]
288
+ //
289
+ // CHECK: [[ALLOC_Y:%.*]] = alloc_box ${ let AddressOnlyProtocol }, let, name "y"
290
+ // CHECK: [[Y:%.*]] = begin_borrow [lexical] [[ALLOC_Y]]
291
+ // CHECK: [[PROJECT_Y:%.*]] = project_box [[Y]]
292
+ // CHECK: copy_addr [[ARG]] to [init] [[PROJECT_Y]]
293
+ // CHECK: [[MARKED_Y:%.*]] = mark_must_check [no_consume_or_assign] [[PROJECT_Y]]
294
+ // CHECK: [[BLACKHOLE_ADDR:%.*]] = alloc_stack $AddressOnlyProtocol
295
+ // CHECK: copy_addr [[MARKED_Y]] to [init] [[BLACKHOLE_ADDR]]
296
+ // CHECK: destroy_addr [[BLACKHOLE_ADDR]]
297
+ // CHECK: dealloc_stack [[BLACKHOLE_ADDR]]
298
+ // CHECK: } // end sil function '$s8moveonly19AddressOnlyProtocolV13testNoUseSelfyyF'
299
+ func testNoUseSelf( ) {
300
+ let x = self
301
+ let _ = x
302
+ let y = self
303
+ let _ = y
304
+ }
305
+ }
306
+
172
307
///////////////////////////////
173
308
// Black Hole Initialization //
174
309
///////////////////////////////
0 commit comments