Skip to content

Commit 7adb119

Browse files
committed
[Test] Added for part_ap of async @conv(method).
1 parent 8d96f94 commit 7adb119

File tree

1 file changed

+295
-0
lines changed

1 file changed

+295
-0
lines changed
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule
3+
// RUN: %target-codesign %t/%target-library-name(PrintShims)
4+
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL
5+
// RUN: %target-sil-opt -sil-inline-generics -enable-sil-verify-all -inline -partial-apply-lowering %s | %FileCheck %s --check-prefix=CHECK-SIL
6+
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t)
7+
// RUN: %target-codesign %t/main
8+
// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s
9+
10+
// REQUIRES: executable_test
11+
// REQUIRES: swift_test_mode_optimize_none
12+
// REQUIRES: concurrency
13+
// UNSUPPORTED: use_os_stdlib
14+
15+
import Builtin
16+
import Swift
17+
import _Concurrency
18+
19+
// CHECK-LL: @Super_runTu =
20+
// CHECK-LL: @Sub_runTu =
21+
// CHECK-LL: @"$s20partial_apply_methodTwTu" =
22+
23+
protocol Q {
24+
func testU() -> String
25+
}
26+
27+
sil public_external @printGeneric : $@convention(thin) <T> (@in_guaranteed T) -> ()
28+
29+
class Super {
30+
init(_ t: String)
31+
@_hasStorage private final let t: String { get }
32+
func run<U>(on u: U, at i: Int64) async -> String where U : Q
33+
deinit
34+
}
35+
36+
@_inheritsConvenienceInitializers class Sub : Super {
37+
@_hasStorage @_hasInitialValue var t2: String? { get set }
38+
override func run<U>(on u: U, at i: Int64) async -> String where U : Q
39+
override init(_ t: String)
40+
deinit
41+
}
42+
43+
struct QImpl : Q {
44+
func testU() -> String
45+
init()
46+
}
47+
48+
sil hidden [exact_self_class] @Super_allocating_init : $@convention(method) (@owned String, @thick Super.Type) -> @owned Super {
49+
bb0(%value : $String, %super_type : $@thick Super.Type):
50+
%uninitialized = alloc_ref $Super
51+
%Super_init = function_ref @Super_init : $@convention(method) (@owned String, @owned Super) -> @owned Super
52+
%result = apply %Super_init(%value, %uninitialized) : $@convention(method) (@owned String, @owned Super) -> @owned Super
53+
return %result : $Super
54+
}
55+
56+
sil hidden @Super_init : $@convention(method) (@owned String, @owned Super) -> @owned Super {
57+
bb0(%value : $String, %instance : $Super):
58+
retain_value %value : $String
59+
%field_addr = ref_element_addr %instance : $Super, #Super.t
60+
store %value to %field_addr : $*String
61+
release_value %value : $String
62+
return %instance : $Super
63+
}
64+
65+
// CHECK-LL: define hidden swift{{(tail)?}}cc void @Super_run(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) #0 {
66+
sil hidden @Super_run : $@convention(method) @async <U where U : Q> (@in_guaranteed U, Int64, @guaranteed Super) -> @owned String {
67+
bb0(%generic_addr : $*U, %int_arg : $Int64, %int : $Super):
68+
%printGeneric = function_ref @printGeneric : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
69+
// CHECK: QImpl()
70+
%printGeneric_result = apply %printGeneric<U>(%generic_addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
71+
%testU = witness_method $U, #Q.testU : <Self where Self : Q> (Self) -> () -> String : $@convention(witness_method: Q) <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0) -> @owned String
72+
%testU_result = apply %testU<U>(%generic_addr) : $@convention(witness_method: Q) <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0) -> @owned String
73+
%testU_result_addr = alloc_stack $String
74+
store %testU_result to %testU_result_addr : $*String
75+
// CHECK: QImpl.testU
76+
%printGeneric_result2 = apply %printGeneric<String>(%testU_result_addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
77+
destroy_addr %testU_result_addr : $*String
78+
dealloc_stack %testU_result_addr : $*String
79+
%int_arg_addr = alloc_stack $Int64
80+
store %int_arg to %int_arg_addr : $*Int64
81+
// CHECK: 42
82+
%printGeneric_result3 = apply %printGeneric<Int64>(%int_arg_addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
83+
dealloc_stack %int_arg_addr : $*Int64
84+
%field_addr = ref_element_addr %int : $Super, #Super.t
85+
%field = load %field_addr : $*String
86+
retain_value %field : $String
87+
return %field : $String
88+
}
89+
90+
sil hidden @Super_deinit : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject {
91+
bb0(%instance : $Super):
92+
%field_addr = ref_element_addr %instance : $Super, #Super.t
93+
%field = begin_access [deinit] [static] %field_addr : $*String
94+
destroy_addr %field : $*String
95+
end_access %field : $*String
96+
%uninitialized = unchecked_ref_cast %instance : $Super to $Builtin.NativeObject
97+
return %uninitialized : $Builtin.NativeObject
98+
}
99+
100+
sil hidden @Super_deallocating_deinit : $@convention(method) (@owned Super) -> () {
101+
bb0(%instance : $Super):
102+
%Super_deinit = function_ref @Super_deinit : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject
103+
%uninitialized = apply %Super_deinit(%instance) : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject
104+
%uninitailized_super = unchecked_ref_cast %uninitialized : $Builtin.NativeObject to $Super
105+
dealloc_ref %uninitailized_super : $Super
106+
%out = tuple ()
107+
return %out : $()
108+
}
109+
110+
// CHECK-LL: define hidden swift{{(tail)?}}cc void @Sub_run(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) #0 {
111+
sil hidden @Sub_run : $@convention(method) @async <U where U : Q> (@in_guaranteed U, Int64, @guaranteed Sub) -> @owned String {
112+
bb0(%U_addr : $*U, %int : $Int64, %sub : $Sub):
113+
strong_retain %sub : $Sub
114+
%super = upcast %sub : $Sub to $Super
115+
%Super_run = function_ref @Super_run : $@convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String
116+
%result = apply %Super_run<U>(%U_addr, %int, %super) : $@convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String
117+
strong_release %super : $Super
118+
return %result : $String
119+
}
120+
121+
sil hidden [exact_self_class] @Sub_allocating_init : $@convention(method) (@owned String, @thick Sub.Type) -> @owned Sub {
122+
bb0(%value : $String, %type : $@thick Sub.Type):
123+
%uninitialized = alloc_ref $Sub
124+
%Sub_init = function_ref @Sub_init : $@convention(method) (@owned String, @owned Sub) -> @owned Sub
125+
%result = apply %Sub_init(%value, %uninitialized) : $@convention(method) (@owned String, @owned Sub) -> @owned Sub
126+
return %result : $Sub
127+
}
128+
129+
sil hidden @Sub_init : $@convention(method) (@owned String, @owned Sub) -> @owned Sub {
130+
bb0(%value : $String, %uninitialized : $Sub):
131+
%field_addr = ref_element_addr %uninitialized : $Sub, #Sub.t2
132+
%none = enum $Optional<String>, #Optional.none!enumelt
133+
store %none to %field_addr : $*Optional<String>
134+
%uninitialized_super = upcast %uninitialized : $Sub to $Super
135+
retain_value %value : $String
136+
%Super_init = function_ref @Super_init : $@convention(method) (@owned String, @owned Super) -> @owned Super
137+
%result_super = apply %Super_init(%value, %uninitialized_super) : $@convention(method) (@owned String, @owned Super) -> @owned Super
138+
%result = unchecked_ref_cast %result_super : $Super to $Sub
139+
strong_retain %result : $Sub
140+
release_value %value : $String
141+
return %result : $Sub
142+
}
143+
144+
sil hidden @Sub_deinit : $@convention(method) (@guaranteed Sub) -> @owned Builtin.NativeObject {
145+
bb0(%initialized : $Sub):
146+
%initialized_super = upcast %initialized : $Sub to $Super
147+
%Super_deinit = function_ref @Super_deinit : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject
148+
%uninitialized = apply %Super_deinit(%initialized_super) : $@convention(method) (@guaranteed Super) -> @owned Builtin.NativeObject
149+
%uninitialized_super = unchecked_ref_cast %uninitialized : $Builtin.NativeObject to $Sub
150+
%field_addr = ref_element_addr %uninitialized_super : $Sub, #Sub.t2
151+
%field = begin_access [deinit] [static] %field_addr : $*Optional<String>
152+
destroy_addr %field : $*Optional<String>
153+
end_access %field : $*Optional<String>
154+
return %uninitialized : $Builtin.NativeObject
155+
}
156+
157+
sil hidden @Sub_deallocating_deinit : $@convention(method) (@owned Sub) -> () {
158+
bb0(%initialized : $Sub):
159+
%Sub_deinit = function_ref @Sub_deinit : $@convention(method) (@guaranteed Sub) -> @owned Builtin.NativeObject
160+
%uninitialized = apply %Sub_deinit(%initialized) : $@convention(method) (@guaranteed Sub) -> @owned Builtin.NativeObject
161+
%uninitialized_sub = unchecked_ref_cast %uninitialized : $Builtin.NativeObject to $Sub
162+
dealloc_ref %uninitialized_sub : $Sub
163+
%out = tuple ()
164+
return %out : $()
165+
}
166+
167+
// CHECK-SIL-LABEL: sil hidden @partial_apply_method
168+
// CHECK-SIL-SAME: : $@convention(thin) <U where U : Q> (
169+
// CHECK-SIL-SAME: @guaranteed Super,
170+
// CHECK-SIL-SAME: @convention(method) @async <U where U : Q> (@in_guaranteed U, Int64, @guaranteed Super) -> @owned String
171+
// CHECK-SIL-SAME: ) ->
172+
// CHECK-SIL-SAME: @async @callee_guaranteed (@in_guaranteed U, Int64) -> @owned String {
173+
// CHECK-SIL: bb0(
174+
// CHECK-SIL-SAME: [[INSTANCE:%[^,]+]] : $Super,
175+
// CHECK-SIL-SAME: [[DYNAMIC_METHOD:%[^,]+]] : $@convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String
176+
// CHECK-SIL-SAME: ):
177+
// CHECK-SIL: [[THUNK:%[^,]+]] = function_ref @$s20partial_apply_methodTw : $@convention(thin) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super, @convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String) -> @owned String
178+
// CHECK-SIL: [[RESULT:%[^,]+]] = partial_apply [callee_guaranteed] [[THUNK]]<U>([[INSTANCE]], [[DYNAMIC_METHOD]]) : $@convention(thin) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super, @convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String) -> @owned String
179+
// CHECK-SIL: return [[RESULT]] : $@async @callee_guaranteed (@in_guaranteed U, Int64) -> @owned String
180+
// CHECK-SIL-LABEL: } // end sil function 'partial_apply_method'
181+
182+
// CHECK-SIL-LABEL: sil private [thunk] [ossa] @$s20partial_apply_methodTw : $@convention(thin) @async <U where U : Q> (
183+
// CHECK-SIL-SAME: @in_guaranteed U,
184+
// CHECK-SIL-SAME: Int64,
185+
// CHECK-SIL-SAME: @guaranteed Super,
186+
// CHECK-SIL-SAME: @convention(method) @async <U where U : Q> (@in_guaranteed U, Int64, @guaranteed Super) -> @owned String) -> @owned String
187+
// CHECK-SIL-SAME: {
188+
// CHECK-SIL: bb0(
189+
// CHECK-SIL-SAME: [[GENERIC_ADDR:%[^,]+]] : $*U,
190+
// CHECK-SIL-SAME: [[INT:%[^,]+]] : $Int64,
191+
// CHECK-SIL-SAME: [[INSTANCE:%[^,]+]] : @guaranteed $Super,
192+
// CHECK-SIL-SAME: [[METHOD:%[^,]+]] : $@convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String
193+
// CHECK-SIL-SAME: ):
194+
// CHECK-SIL: [[RESULT:%[^,]+]] = apply [[METHOD]]<U>(
195+
// CHECK-SIL-SAME: [[GENERIC_ADDR]],
196+
// CHECK-SIL-SAME: [[INT]],
197+
// CHECK-SIL-SAME: [[INSTANCE]]
198+
// CHECK-SIL-SAME: ) : $@convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String
199+
// CHECK-SIL: return [[RESULT]] : $String
200+
// CHECK-SIL-LABEL: } // end sil function '$s20partial_apply_methodTw'
201+
202+
// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s20partial_apply_methodTwTA"(%swift.task* %0, %swift.executor* %1, %swift.context* swiftasync %2) #0 {
203+
sil hidden @partial_apply_method : $@convention(thin) <U where U : Q> (@guaranteed Super, @convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String) -> @callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String {
204+
entry(%int : $Super, %fn : $@convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String):
205+
%pa = partial_apply [callee_guaranteed] %fn<U>(%int) : $@convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String
206+
return %pa : $@callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String
207+
}
208+
209+
sil hidden @doit : $@convention(thin) @async <U where U : Q> (Int64, @in_guaranteed U, @guaranteed Super) -> @owned String {
210+
bb0(%int : $Int64, %generic_addr : $*U, %instance : $Super):
211+
%run_method = class_method %instance : $Super, #Super.run : <U where U : Q> (Super) -> (U, Int64) async -> String, $@convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String
212+
%partial_apply_method = function_ref @partial_apply_method : $@convention(thin) <U where U : Q> (@guaranteed Super, @convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String) -> @callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String
213+
%partially_applied_method = apply %partial_apply_method<U>(%instance, %run_method) : $@convention(thin) <U where U : Q> (@guaranteed Super, @convention(method) @async <τ_0_0 where τ_0_0 : Q> (@in_guaranteed τ_0_0, Int64, @guaranteed Super) -> @owned String) -> @callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String
214+
%result = apply %partially_applied_method(%generic_addr, %int) : $@callee_guaranteed @async (@in_guaranteed U, Int64) -> @owned String
215+
return %result : $String
216+
}
217+
218+
sil hidden @QImpl_testU : $@convention(method) (QImpl) -> @owned String {
219+
bb0(%instance : $QImpl):
220+
%string_literal = string_literal utf8 "QImpl.testU"
221+
%utf8CodeUnitCount = integer_literal $Builtin.Word, 11
222+
%isASCII = integer_literal $Builtin.Int1, -1
223+
%string_type = metatype $@thin String.Type
224+
%String_init = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String
225+
%result = apply %String_init(%string_literal, %utf8CodeUnitCount, %isASCII, %string_type) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String
226+
return %result : $String
227+
}
228+
229+
sil [serialized] [always_inline] [readonly] [_semantics "string.makeUTF8"] @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String
230+
231+
sil private [transparent] [thunk] @QImpl_testU_conformance_thunk : $@convention(witness_method: Q) (@in_guaranteed QImpl) -> @owned String {
232+
bb0(%qimpl_addr : $*QImpl):
233+
%qimpl = load %qimpl_addr : $*QImpl
234+
%QImpl_testU = function_ref @QImpl_testU : $@convention(method) (QImpl) -> @owned String
235+
%result = apply %QImpl_testU(%qimpl) : $@convention(method) (QImpl) -> @owned String
236+
return %result : $String
237+
}
238+
239+
sil @test_case : $@convention(thin) @async () -> () {
240+
%sub_type = metatype $@thick Sub.Type
241+
%string_literal = string_literal utf8 "42"
242+
%utf8CodeUnitCount = integer_literal $Builtin.Word, 2
243+
%isASCII = integer_literal $Builtin.Int1, -1
244+
%string_type = metatype $@thin String.Type
245+
%string_init = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String
246+
%string = apply %string_init(%string_literal, %utf8CodeUnitCount, %isASCII, %string_type) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String
247+
%Sub_allocating_init = function_ref @Sub_allocating_init : $@convention(method) (@owned String, @thick Sub.Type) -> @owned Sub
248+
%instance_sub = apply %Sub_allocating_init(%string, %sub_type) : $@convention(method) (@owned String, @thick Sub.Type) -> @owned Sub
249+
%int_literal = integer_literal $Builtin.Int64, 42
250+
%int = struct $Int64 (%int_literal : $Builtin.Int64)
251+
%qimpl = struct $QImpl ()
252+
%qimpl_addr = alloc_stack $QImpl
253+
store %qimpl to %qimpl_addr : $*QImpl
254+
%instance_super = upcast %instance_sub : $Sub to $Super
255+
%doit = function_ref @doit : $@convention(thin) @async <τ_0_0 where τ_0_0 : Q> (Int64, @in_guaranteed τ_0_0, @guaranteed Super) -> @owned String
256+
%doit_result = apply %doit<QImpl>(%int, %qimpl_addr, %instance_super) : $@convention(thin) @async <τ_0_0 where τ_0_0 : Q> (Int64, @in_guaranteed τ_0_0, @guaranteed Super) -> @owned String
257+
dealloc_stack %qimpl_addr : $*QImpl
258+
strong_release %instance_sub : $Sub
259+
260+
%void = tuple()
261+
return %void : $()
262+
}
263+
264+
// Defined in _Concurrency
265+
sil @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> ()
266+
267+
// main
268+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
269+
bb0(%argc : $Int32, %argv : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
270+
%test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> ()
271+
%test_case = convert_function %test_case_nothrow : $@convention(thin) @async () -> () to $@convention(thin) @async () -> @error Error
272+
%thick_test_case = thin_to_thick_function %test_case : $@convention(thin) @async () -> @error Error to $@callee_guaranteed @async () -> @error Error
273+
%runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> ()
274+
%result = apply %runAsyncMain(%thick_test_case) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> ()
275+
276+
%out_literal = integer_literal $Builtin.Int32, 0
277+
%out = struct $Int32 (%out_literal : $Builtin.Int32)
278+
return %out : $Int32
279+
}
280+
281+
sil_vtable Super {
282+
#Super.init!allocator: (Super.Type) -> (String) -> Super : @Super_allocating_init
283+
#Super.run: <U where U : Q> (Super) -> (U, Int64) async -> String : @Super_run
284+
#Super.deinit!deallocator: @Super_deallocating_deinit
285+
}
286+
287+
sil_vtable Sub {
288+
#Super.init!allocator: (Super.Type) -> (String) -> Super : @Sub_allocating_init [override]
289+
#Super.run: <U where U : Q> (Super) -> (U, Int64) async -> String : @Sub_run [override]
290+
#Sub.deinit!deallocator: @Sub_deallocating_deinit
291+
}
292+
293+
sil_witness_table hidden QImpl: Q module main {
294+
method #Q.testU: <Self where Self : Q> (Self) -> () -> String : @QImpl_testU_conformance_thunk
295+
}

0 commit comments

Comments
 (0)