Files
swift-mirror/test/IRGen/async/partial_apply.sil
Andrew Trick 0dd90a7ffc Update old closure tests for current conventions
Fixes assert:
SIL verification failed: on-stack closures do not support owned arguments:
2023-08-10 11:17:53 -07:00

637 lines
32 KiB
Plaintext

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -g -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../../Inputs/resilient_struct.swift
// RUN: %target-swift-frontend -g -I %t -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
// REQUIRES: concurrency
import Builtin
import Swift
import resilient_struct
class SwiftClass {}
sil_vtable SwiftClass {}
sil @$s13partial_apply10SwiftClassCfD : $@async @convention(method) (SwiftClass) -> ()
sil @partially_applyable_to_class : $@async @convention(thin) (@guaranteed SwiftClass) -> () {
entry(%c : $SwiftClass):
%0 = builtin "int_trap"() : $Never
unreachable
}
sil @partially_applyable_to_two_classes : $@async @convention(thin) (@guaranteed SwiftClass, @guaranteed SwiftClass) -> () {
entry(%c : $SwiftClass, %d : $SwiftClass):
%0 = builtin "int_trap"() : $Never
unreachable
}
sil @use_closure : $@async @convention(thin) (@noescape @async @callee_guaranteed () -> ()) -> ()
// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_class(
sil @partial_apply_class : $@async @convention(thin) (SwiftClass) -> @async @callee_guaranteed () -> () {
entry(%c : $SwiftClass):
%f = function_ref @partially_applyable_to_class : $@async @convention(thin) (@guaranteed SwiftClass) -> ()
%g = partial_apply [callee_guaranteed] %f(%c) : $@async @convention(thin) (@guaranteed SwiftClass) -> ()
return %g : $@async @callee_guaranteed () -> ()
}
// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_class_on_stack(
sil @partial_apply_class_on_stack : $@async @convention(thin) (@owned SwiftClass) -> () {
entry(%a : $SwiftClass):
%f = function_ref @partially_applyable_to_class : $@async @convention(thin) (@guaranteed SwiftClass) -> ()
%c = partial_apply [callee_guaranteed] [on_stack] %f(%a) : $@async @convention(thin) (@guaranteed SwiftClass) -> ()
%use = function_ref @use_closure : $@async @convention(thin) (@noescape @async @callee_guaranteed () -> ()) -> ()
apply %use(%c) : $@async @convention(thin) (@noescape @async @callee_guaranteed () -> ()) -> ()
dealloc_stack %c : $@noescape @async @callee_guaranteed () ->()
strong_release %a : $SwiftClass
%t = tuple()
return %t : $()
}
// CHECK: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_two_classes_on_stack(
sil @partial_apply_two_classes_on_stack : $@async @convention(thin) (@owned SwiftClass, @owned SwiftClass) -> () {
entry(%a : $SwiftClass, %b: $SwiftClass):
%f = function_ref @partially_applyable_to_two_classes : $@async @convention(thin) (@guaranteed SwiftClass, @guaranteed SwiftClass) -> ()
%c = partial_apply [callee_guaranteed] [on_stack] %f(%a, %b) : $@async @convention(thin) (@guaranteed SwiftClass, @guaranteed SwiftClass) -> ()
%use = function_ref @use_closure : $@async @convention(thin) (@noescape @async @callee_guaranteed () -> ()) -> ()
apply %use(%c) : $@async @convention(thin) (@noescape @async @callee_guaranteed () -> ()) -> ()
dealloc_stack %c : $@noescape @async @callee_guaranteed () ->()
strong_release %a : $SwiftClass
strong_release %b : $SwiftClass
%t = tuple()
return %t : $()
}
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s22generic_captured_paramTA"(
sil @generic_captured_param : $@async @convention(thin) <T> (Int, @inout T) -> Int {
entry(%i : $Int, %t : $*T):
return %i : $Int
}
sil @partial_apply_generic_capture : $@async @convention(thin) (Int) -> @async @callee_guaranteed (Int) -> Int {
entry(%x : $Int):
%a = alloc_stack $Int
store %x to %a : $*Int
%f = function_ref @generic_captured_param : $@async @convention(thin) <T> (Int, @inout T) -> Int
%p = partial_apply [callee_guaranteed] %f<Int>(%a) : $@async @convention(thin) <T> (Int, @inout T) -> Int
dealloc_stack %a : $*Int
return %p : $@async @callee_guaranteed (Int) -> Int
}
sil public @generic_captured_and_open_param : $@async @convention(thin) <T> (@in T, @inout T) -> @out T {
entry(%o : $*T, %i : $*T, %io : $*T):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_open_generic_capture(
sil @partial_apply_open_generic_capture : $@async @convention(thin) <T> (@inout T) -> @async @callee_guaranteed (@in T) -> @out T {
entry(%a : $*T):
%f = function_ref @generic_captured_and_open_param : $@async @convention(thin) <U> (@in U, @inout U) -> @out U
%p = partial_apply [callee_guaranteed] %f<T>(%a) : $@async @convention(thin) <U> (@in U, @inout U) -> @out U
return %p : $@async @callee_guaranteed (@in T) -> @out T
}
/*****************************************************************************/
/* Swift-refcounted class captures. Optimizable by using the reference */
/* as the partial apply context. */
/*****************************************************************************/
sil public @guaranteed_captured_class_param : $@async @convention(thin) (Int, @guaranteed SwiftClass) -> Int {
entry(%i : $Int, %c : $SwiftClass):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_guaranteed_class_param(
sil @partial_apply_guaranteed_class_param : $@async @convention(thin) (@owned SwiftClass) -> @async @callee_guaranteed (Int) -> Int {
bb0(%x : $SwiftClass):
%f = function_ref @guaranteed_captured_class_param : $@async @convention(thin) (Int, @guaranteed SwiftClass) -> Int
%p = partial_apply [callee_guaranteed] %f(%x) : $@async @convention(thin) (Int, @guaranteed SwiftClass) -> Int
return %p : $@async @callee_guaranteed (Int) -> Int
}
sil public @indirect_guaranteed_captured_class_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClass) -> Int {
entry(%i : $Int, %c : $*SwiftClass):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_guaranteed_class_param(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s40indirect_guaranteed_captured_class_paramTA"(
sil @partial_apply_indirect_guaranteed_class_param : $@async @convention(thin) (@in SwiftClass) -> @async @callee_guaranteed (Int) -> Int {
bb0(%x : $*SwiftClass):
%f = function_ref @indirect_guaranteed_captured_class_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClass) -> Int
%p = partial_apply [callee_guaranteed] %f(%x) : $@async @convention(thin) (Int, @in_guaranteed SwiftClass) -> Int
return %p : $@async @callee_guaranteed (Int) -> Int
}
sil public @indirect_consumed_captured_class_param : $@async @convention(thin) (Int, @in SwiftClass) -> Int {
entry(%i : $Int, %c : $*SwiftClass):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_consumed_class_param(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s38indirect_consumed_captured_class_paramTA"(
sil @partial_apply_indirect_consumed_class_param : $@async @convention(thin) (@in SwiftClass) -> @async @callee_guaranteed (Int) -> Int {
bb0(%x : $*SwiftClass):
%f = function_ref @indirect_consumed_captured_class_param : $@async @convention(thin) (Int, @in SwiftClass) -> Int
%p = partial_apply [callee_guaranteed] %f(%x) : $@async @convention(thin) (Int, @in SwiftClass) -> Int
return %p : $@async @callee_guaranteed (Int) -> Int
}
/*****************************************************************************/
/* A non-trivial capture. Indirect applications can directly reference the */
/* field from the partial apply context. */
/*****************************************************************************/
struct SwiftClassPair { var x: SwiftClass, y: SwiftClass }
sil public @guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @guaranteed SwiftClassPair) -> Int {
entry(%i : $Int, %c : $SwiftClassPair):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_guaranteed_class_pair_param(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s36guaranteed_captured_class_pair_paramTA"(
sil @partial_apply_guaranteed_class_pair_param : $@async @convention(thin) (@owned SwiftClassPair) -> @async @callee_guaranteed (Int) -> Int {
bb0(%x : $SwiftClassPair):
%f = function_ref @guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @guaranteed SwiftClassPair) -> Int
%p = partial_apply [callee_guaranteed] %f(%x) : $@async @convention(thin) (Int, @guaranteed SwiftClassPair) -> Int
return %p : $@async @callee_guaranteed (Int) -> Int
}
sil public @indirect_guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int {
entry(%i : $Int, %c : $*SwiftClassPair):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_guaranteed_class_pair_param(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s45indirect_guaranteed_captured_class_pair_paramTA"(
sil @partial_apply_indirect_guaranteed_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> @async @callee_guaranteed (Int) -> Int {
bb0(%x : $*SwiftClassPair):
%f = function_ref @indirect_guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
%p = partial_apply [callee_guaranteed] %f(%x) : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
return %p : $@async @callee_guaranteed (Int) -> Int
}
sil public @indirect_consumed_captured_class_pair_param : $@async @convention(thin) (Int, @in SwiftClassPair) -> Int {
entry(%i : $Int, %c : $*SwiftClassPair):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_consumed_class_pair_param(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s43indirect_consumed_captured_class_pair_paramTA"(
sil @partial_apply_indirect_consumed_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> @async @callee_guaranteed (Int) -> Int {
bb0(%x : $*SwiftClassPair):
%f = function_ref @indirect_consumed_captured_class_pair_param : $@async @convention(thin) (Int, @in SwiftClassPair) -> Int
%p = partial_apply [callee_guaranteed] %f(%x) : $@async @convention(thin) (Int, @in SwiftClassPair) -> Int
return %p : $@async @callee_guaranteed (Int) -> Int
}
sil public @captured_fixed_and_dependent_params : $@async @convention(thin) <A> (@guaranteed SwiftClass, @in_guaranteed A, Int) -> () {
entry(%c : $SwiftClass, %a : $*A, %i : $Int):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_indirect_non_fixed_layout
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s35captured_fixed_and_dependent_paramsTA"(
sil @partial_apply_indirect_non_fixed_layout : $@async @convention(thin) <T> (@owned SwiftClass, @in T, Int) -> @async @callee_guaranteed () -> () {
bb0(%a : $SwiftClass, %b : $*T, %c : $Int):
%f = function_ref @captured_fixed_and_dependent_params : $@async @convention(thin) <B> (@guaranteed SwiftClass, @in_guaranteed B, Int) -> ()
%p = partial_apply [callee_guaranteed] %f<T>(%a, %b, %c) : $@async @convention(thin) <C> (@guaranteed SwiftClass, @in_guaranteed C, Int) -> ()
return %p : $@async @callee_guaranteed () -> ()
}
sil public @captured_dependent_out_param : $@async @convention(thin) <A> (@in A) -> @out A {
entry(%o : $*A, %i : $*A):
%0 = builtin "int_trap"() : $Never
unreachable
}
sil @partial_apply_with_out_param : $@async @convention(thin) <T> (@in T) -> @async @callee_guaranteed () -> @out T {
bb0(%x : $*T):
%f = function_ref @captured_dependent_out_param : $@async @convention(thin) <B> (@in B) -> @out B
%p = partial_apply [callee_guaranteed] %f<T>(%x) : $@async @convention(thin) <C> (@in C) -> @out C
return %p : $@async @callee_guaranteed () -> @out T
}
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s28captured_dependent_out_paramTA"(
sil @partial_apply_dynamic_with_out_param : $@async @convention(thin) <T> (Int32, @owned @async @callee_guaranteed (Int32) -> @out T) -> @async @callee_guaranteed () -> @out T {
bb0(%x : $Int32, %f : $@async @callee_guaranteed (Int32) -> @out T):
%p = partial_apply [callee_guaranteed] %f(%x) : $@async @callee_guaranteed (Int32) -> @out T
return %p : $@async @callee_guaranteed () -> @out T
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_dynamic_with_out_param(
class Base {
}
sil_vtable Base {}
class Sub : Base {
}
sil_vtable Sub {}
sil @parametric_casting_closure : $@async @convention(thin) <C where C : Base> (@guaranteed Base) -> @owned C {
bb0(%0 : $Base):
%1 = unconditional_checked_cast %0 : $Base to C
return %1 : $C
}
sil public_external @receive_closure : $@async @convention(thin) <C where C : Base> (@owned @async @callee_guaranteed () -> (@owned C)) -> ()
sil public_external @receive_closure2 : $@async @convention(thin) <C where C : Base> (@owned @async @callee_guaranteed (@guaranteed Base) -> (@owned C)) -> ()
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_partial_apply(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s26parametric_casting_closureTA"(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s26parametric_casting_closureTA.{{[0-9]+}}"(
sil @test_partial_apply : $@async @convention(thin) (@owned Base) -> () {
bb0(%0 : $Base):
%1 = function_ref @parametric_casting_closure : $@async @convention(thin) <C where C : Base> (@guaranteed Base) -> @owned C
%6 = partial_apply [callee_guaranteed] %1<Sub>() : $@async @convention(thin) <C where C : Base> (@guaranteed Base) -> @owned C
%2 = partial_apply [callee_guaranteed] %1<Sub>(%0) : $@async @convention(thin) <C where C : Base> (@guaranteed Base) -> @owned C
%3 = function_ref @receive_closure : $@async @convention(thin) <C where C : Base> (@owned @async @callee_guaranteed () -> (@owned C)) -> ()
%4 = apply %3<Sub>(%2) : $@async @convention(thin) <C where C : Base> (@owned @async @callee_guaranteed () -> (@owned C)) -> ()
%5 = function_ref @receive_closure2 : $@async @convention(thin) <C where C : Base> (@owned @async @callee_guaranteed (@guaranteed Base) -> (@owned C)) -> ()
%8 = apply %5<Sub>(%6) : $@async @convention(thin) <C where C : Base> (@owned @async @callee_guaranteed (@guaranteed Base) -> (@owned C)) -> ()
%7 = tuple ()
return %7 : $()
}
protocol P0 {}
protocol P1 { associatedtype X : P0 }
protocol P2 { associatedtype Y : P1 }
sil hidden @complex_generic_function : $@async @convention(thin) <T where T : P2, T.Y : P2> (Int) -> () {
entry(%i : $Int):
%0 = builtin "int_trap"() : $Never
unreachable
}
sil public_external @receive_closure3 : $@async @convention(thin) (@owned @async @callee_guaranteed () -> ()) -> ()
sil @partial_apply_complex_generic_function : $@async @convention(thin) <T where T : P2, T.Y : P2> (Int) -> () {
bb0(%0 : $Int):
%fn = function_ref @complex_generic_function : $@async @convention(thin) <T where T : P2, T.Y : P2> (Int) -> ()
%pa = partial_apply [callee_guaranteed] %fn <T>(%0) : $@async @convention(thin) <T where T : P2, T.Y : P1, T.Y : P2> (Int) -> ()
%fn2 = function_ref @receive_closure3 : $@async @convention(thin) (@owned @async @callee_guaranteed () -> ()) -> ()
apply %fn2(%pa) : $@async @convention(thin) (@owned @async @callee_guaranteed () -> ()) -> ()
%result = tuple ()
return %result : $()
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_complex_generic_function(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s24complex_generic_functionTA"(
struct ComplexBoundedType<T: P2> {}
// https://github.com/apple/swift/issues/43513
// Ensure that a 'partial_apply' which captures bound generic type metadata
// doesn't crash when restoring the generic context.
sil hidden @generic_function : $@async @convention(thin) <T> () -> () {
%0 = builtin "int_trap"() : $Never
unreachable
}
sil @partial_apply_with_generic_type : $@async @convention(thin) <U: P2> () -> () {
bb0:
%fn = function_ref @generic_function : $@async @convention(thin) <T> () -> ()
%pa = partial_apply [callee_guaranteed] %fn <ComplexBoundedType<U>>() : $@async @convention(thin) <T> () -> ()
%result = tuple ()
return %result : $()
}
// Crash on partial apply of witness_method without generic signature
extension Int: P0 {}
sil hidden_external @concrete_witness_method : $@async @convention(witness_method: P0) (Int, Int) -> ()
sil hidden @partial_apply_witness_method : $@async @convention(thin) (Int) -> () {
bb0(%0 : $Int):
%fn = function_ref @concrete_witness_method : $@async @convention(witness_method: P0) (Int, Int) -> ()
%pa = partial_apply [callee_guaranteed] %fn (%0) : $@async @convention(witness_method: P0) (Int, Int) -> ()
%result = tuple ()
return %result : $()
}
// Crash on partial apply of a generic enum.
enum GenericEnum<T> {
case X(String)
case Y(T, T, T, T, T)
}
sil public @generic_indirect_return : $@async @convention(thin) <T> (Int) -> @owned GenericEnum<T> {
entry(%i : $Int):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_generic_indirect_return(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s23generic_indirect_returnTA"(
sil @partial_apply_generic_indirect_return : $@async @convention(thin) (Int) -> @async @callee_guaranteed () -> @owned GenericEnum<Int> {
bb0(%0 : $Int):
%fn = function_ref @generic_indirect_return :$@async @convention(thin) <T> (Int) -> @owned GenericEnum<T>
%pa = partial_apply [callee_guaranteed] %fn<Int> (%0) : $@async @convention(thin) <T> (Int) -> @owned GenericEnum<T>
return %pa : $@async @callee_guaranteed () -> @owned GenericEnum<Int>
}
// Crash on partial apply of a generic enum.
enum GenericEnum2<T> {
case X(String)
case Y(T)
}
sil public @generic_indirect_return2 : $@async @convention(thin) <T> (Int) -> @owned GenericEnum2<T> {
entry(%i : $Int):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_generic_indirect_return2(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s24generic_indirect_return2TA"(
sil @partial_apply_generic_indirect_return2 : $@async @convention(thin) (Int) -> @async @callee_guaranteed () -> @owned GenericEnum2<Int> {
bb0(%0 : $Int):
%fn = function_ref @generic_indirect_return2 :$@async @convention(thin) <T> (Int) -> @owned GenericEnum2<T>
%pa = partial_apply [callee_guaranteed] %fn<Int> (%0) : $@async @convention(thin) <T> (Int) -> @owned GenericEnum2<T>
return %pa : $@async @callee_guaranteed () -> @owned GenericEnum2<Int>
}
struct SwiftStruct {}
sil @fun : $@async @convention(thin) (@thin SwiftStruct.Type, @guaranteed SwiftClass) -> () {
entry(%t : $@thin SwiftStruct.Type, %c : $SwiftClass):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_thin_type(
sil @partial_apply_thin_type : $@async @convention(thin) (@thin SwiftStruct.Type, @owned SwiftClass) -> @async @callee_guaranteed () -> () {
entry(%0: $@thin SwiftStruct.Type, %1: $SwiftClass):
%fun = function_ref @fun : $@async @convention(thin) (@thin SwiftStruct.Type, @guaranteed SwiftClass) -> ()
%closure = partial_apply [callee_guaranteed] %fun (%0, %1) : $@async @convention(thin) (@thin SwiftStruct.Type, @guaranteed SwiftClass) -> ()
return %closure : $@async @callee_guaranteed () -> ()
}
sil @afun : $@async @convention(thin) (Int) -> @error Error
// Check that we don't assert on a thin noescape function.
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @convert_thin_test(
sil @convert_thin_test : $@async @convention(thin) (Int) -> () {
bb(%0 : $Int):
%f = function_ref @afun : $@async @convention(thin) (Int) -> @error Error
%c = convert_function %f : $@async @convention(thin) (Int) -> @error Error to $@async @convention(thin) @noescape (Int) -> @error Error
try_apply %c(%0) : $@async @convention(thin) @noescape (Int) -> @error Error, normal bb2, error bb1
bb1(%err: $Error):
%t = tuple ()
br bb3(%t: $())
bb2(%r : $()):
br bb3(%r : $())
bb3(%v : $()):
return %v : $()
}
struct A1 {
let b: () -> ()
}
struct A2<T> {
let a: T
}
class A3 {}
sil @amethod : $@async @convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error) {
entry(%a : $*A2<A3>):
%0 = builtin "int_trap"() : $Never
unreachable
}
sil @repo : $@async @convention(thin) (@in_guaranteed A2<A3>) -> @owned @async @callee_guaranteed () -> (@owned A1, @error Error) {
bb0(%0 : $*A2<A3>):
%1 = load %0 : $*A2<A3>
%2 = alloc_stack $A2<A3>
store %1 to %2 : $*A2<A3>
%4 = function_ref @amethod : $@async @convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error)
%5 = partial_apply [callee_guaranteed] %4(%2) : $@async @convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error)
dealloc_stack %2 : $*A2<A3>
return %5 : $@async @callee_guaranteed () -> (@owned A1, @error Error)
}
//sil @capture_class : $@async @convention(thin) (@guaranteed A3) -> ()
//
//// CHECK LABEL: define{{.*}} swift{{(tail)?}}cc ptr @partial_apply_stack_in_coroutine(ptr {{.*}} %0, ptr %1)
//sil @partial_apply_stack_in_coroutine : $@async @yield_once (@owned A3) -> () {
//entry(%0: $A3):
// %f = function_ref @capture_class : $@async @convention(thin) (@guaranteed A3) -> ()
// %p = partial_apply [callee_guaranteed] [on_stack] %f(%0) : $@async @convention(thin) (@guaranteed A3) -> ()
// apply %p() : $@noescape @async @callee_guaranteed () -> ()
// dealloc_stack %p : $@noescape @async @callee_guaranteed () -> ()
// %1000 = integer_literal $Builtin.Int32, 1000
// yield (), resume resume, unwind unwind
//
//resume:
// %ret = tuple ()
// return %ret : $()
//
//unwind:
// unwind
//}
sil_vtable A3 {}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_callee_guaranteed_indirect_guaranteed_class_pair_param(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s45indirect_guaranteed_captured_class_pair_paramTA.{{[0-9]+}}"(
sil @partial_apply_callee_guaranteed_indirect_guaranteed_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> @owned @async @callee_guaranteed (Int) -> Int {
bb0(%x : $*SwiftClassPair):
%f = function_ref @indirect_guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
%p = partial_apply [callee_guaranteed] %f(%x) : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
return %p : $@async @callee_guaranteed(Int) -> (Int)
}
sil public_external @use_closure2 : $@async @convention(thin) (@noescape @async @callee_guaranteed (Int) -> Int) -> ()
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_guaranteed_class_pair_param(
sil @partial_apply_stack_callee_guaranteed_indirect_guaranteed_class_pair_param : $@async @convention(thin) (@in_guaranteed SwiftClassPair) -> () {
bb0(%x : $*SwiftClassPair):
%f = function_ref @indirect_guaranteed_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
%p = partial_apply [callee_guaranteed] [on_stack] %f(%x) : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
%u = function_ref @use_closure2 : $@async @convention(thin) (@noescape @async @callee_guaranteed (Int) -> Int) -> ()
%r = apply %u(%p) : $@async @convention(thin) (@noescape @async @callee_guaranteed (Int) -> Int) -> ()
dealloc_stack %p : $@noescape @async @callee_guaranteed (Int) ->(Int)
%t = tuple()
return %t : $()
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_in_class_pair_param(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s37indirect_in_captured_class_pair_paramTA"(
sil public @indirect_in_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int {
entry(%i : $Int, %p : $*SwiftClassPair):
%0 = builtin "int_trap"() : $Never
unreachable
}
sil @partial_apply_stack_callee_guaranteed_indirect_in_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> () {
bb0(%x : $*SwiftClassPair):
%f = function_ref @indirect_in_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
%p = partial_apply [callee_guaranteed] [on_stack] %f(%x) : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
%u = function_ref @use_closure2 : $@async @convention(thin) (@noescape @async @callee_guaranteed (Int) -> Int) -> ()
%r = apply %u(%p) : $@async @convention(thin) (@noescape @async @callee_guaranteed (Int) -> Int) -> ()
dealloc_stack %p : $@noescape @async @callee_guaranteed (Int) ->(Int)
destroy_addr %x: $*SwiftClassPair
%t = tuple()
return %t : $()
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @partial_apply_stack_callee_guaranteed_indirect_in_constant_class_pair_param(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s46indirect_in_constant_captured_class_pair_paramTA"(
sil public @indirect_in_constant_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int {
entry(%i : $Int, %ic : $*SwiftClassPair):
%0 = builtin "int_trap"() : $Never
unreachable
}
sil @partial_apply_stack_callee_guaranteed_indirect_in_constant_class_pair_param : $@async @convention(thin) (@in SwiftClassPair) -> () {
bb0(%x : $*SwiftClassPair):
%f = function_ref @indirect_in_constant_captured_class_pair_param : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
%p = partial_apply [callee_guaranteed] [on_stack] %f(%x) : $@async @convention(thin) (Int, @in_guaranteed SwiftClassPair) -> Int
%u = function_ref @use_closure2 : $@async @convention(thin) (@noescape @async @callee_guaranteed (Int) -> Int) -> ()
%r = apply %u(%p) : $@async @convention(thin) (@noescape @async @callee_guaranteed (Int) -> Int) -> ()
dealloc_stack %p : $@noescape @async @callee_guaranteed (Int) ->(Int)
destroy_addr %x: $*SwiftClassPair
%t = tuple()
return %t : $()
}
sil public @closure : $@async @convention(thin) (@in_guaranteed ResilientInt, @guaranteed SwiftClass) -> () {
entry(%i : $*ResilientInt, %c : $SwiftClass):
%0 = builtin "int_trap"() : $Never
unreachable
}
// Make sure that we use the heap header size (16) for the initial offset.
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @test_initial_offset(
sil @test_initial_offset : $@async @convention(thin) (@in ResilientInt, @guaranteed SwiftClass) -> () {
bb0(%x : $*ResilientInt, %y : $SwiftClass):
%f = function_ref @closure : $@async @convention(thin) (@in_guaranteed ResilientInt, @guaranteed SwiftClass) -> ()
%p = partial_apply [callee_guaranteed] %f(%x, %y) : $@async @convention(thin) (@in_guaranteed ResilientInt, @guaranteed SwiftClass) -> ()
release_value %p : $@async @callee_guaranteed () ->()
%t = tuple()
return %t : $()
}
protocol Proto1 {}
protocol Proto2 {}
struct EmptyType : Proto1 { }
struct SomeType : Proto2 {
var d : ResilientInt // some resilient type
var x : Int
}
sil @foo : $@async @convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Proto1, τ_0_1 : Proto2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> () {
entry(%z : $*τ_0_0, %o : $*τ_0_1):
%0 = builtin "int_trap"() : $Never
unreachable
}
// CHECK-64-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @empty_followed_by_non_fixed(
sil @empty_followed_by_non_fixed : $@async @convention(thin) (EmptyType, @in_guaranteed SomeType) -> () {
entry(%0 : $EmptyType, %1: $*SomeType):
%5 = alloc_stack $EmptyType
store %0 to %5 : $*EmptyType
%31 = function_ref @foo : $@async @convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Proto1, τ_0_1 : Proto2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> ()
%32 = alloc_stack $EmptyType
copy_addr %5 to [init] %32 : $*EmptyType
%34 = alloc_stack $SomeType
copy_addr %1 to [init] %34 : $*SomeType // id: %35
%36 = partial_apply [callee_guaranteed] %31<EmptyType, SomeType>(%32, %34) : $@async @convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Proto1, τ_0_1 : Proto2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> ()
release_value %36: $@async @callee_guaranteed () ->()
dealloc_stack %34 : $*SomeType
dealloc_stack %32 : $*EmptyType
dealloc_stack %5 : $*EmptyType
%40 = tuple()
return %40 : $()
}
struct FixedType {
var f: Int32
}
// CHECK-64-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @fixed_followed_by_empty_followed_by_non_fixed
sil @foo2 : $@async @convention(thin) <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1, @in_guaranteed τ_0_2) -> () {
entry(%z : $*τ_0_0, %o : $*τ_0_1, %t : $*τ_0_2):
%0 = builtin "int_trap"() : $Never
unreachable
}
sil @fixed_followed_by_empty_followed_by_non_fixed : $@async @convention(thin) (EmptyType, @in_guaranteed SomeType, FixedType) -> () {
entry(%0 : $EmptyType, %1: $*SomeType, %3: $FixedType):
%5 = alloc_stack $EmptyType
store %0 to %5 : $*EmptyType
%7 = alloc_stack $FixedType
store %3 to %7 : $*FixedType
%31 = function_ref @foo2 : $@async @convention(thin) <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1, @in_guaranteed τ_0_2) -> ()
%32 = alloc_stack $EmptyType
copy_addr %5 to [init] %32 : $*EmptyType
%34 = alloc_stack $SomeType
copy_addr %1 to [init] %34 : $*SomeType // id: %35
%36 = partial_apply [callee_guaranteed] %31<FixedType, EmptyType, SomeType>(%7, %32, %34) : $@async @convention(thin) <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1, @in_guaranteed τ_0_2) -> ()
release_value %36: $@async @callee_guaranteed () ->()
dealloc_stack %34 : $*SomeType
dealloc_stack %32 : $*EmptyType
dealloc_stack %7 : $*FixedType
dealloc_stack %5 : $*EmptyType
%40 = tuple()
return %40 : $()
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc { ptr, ptr } @create_pa_f2(
sil @create_pa_f2 : $@convention(thin) (@callee_guaranteed @async @convention(thick) (Int64, Int32) -> Int64, Int32) -> @owned @async @callee_guaranteed (Int64) -> Int64 {
bb0(%thick : $@callee_guaranteed @async @convention(thick) (Int64, Int32) -> Int64 , %captured : $Int32):
%pa_f = partial_apply [callee_guaranteed] %thick(%captured) : $@callee_guaranteed @async @convention(thick) (Int64, Int32) -> Int64
%pa_f2 = partial_apply [callee_guaranteed] %thick(%captured) : $@callee_guaranteed @async @convention(thick) (Int64, Int32) -> Int64
return %pa_f : $@async @callee_guaranteed (Int64) -> Int64
}
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$sTA.{{[0-9]+}}"(
sil @external_closure : $@convention(thin) @async (Int, Int) -> (Int, @error Error)
sil @dont_crash : $@convention(thin) @async (Int) -> @owned @async @callee_guaranteed (Int) -> (Int, @error Error) {
bb0(%0 : $Int):
%2 = function_ref @external_closure : $@convention(thin) @async (Int, Int) -> (Int, @error Error)
%3 = partial_apply [callee_guaranteed] %2(%0) : $@convention(thin) @async (Int, Int) -> (Int, @error Error)
return %3 : $@async @callee_guaranteed (Int) -> (Int, @error Error)
}
sil @method_with_out_return : $@convention(method) @async (SwiftClass) -> @out Int
sil @partially_apply_method_with_out_return : $@convention(thin) (SwiftClass) -> @async @callee_guaranteed () -> @out Int {
bb(%class : $SwiftClass):
%method_with_out_param = function_ref @method_with_out_return : $@convention(method) @async (SwiftClass) -> @out Int
%result = partial_apply [callee_guaranteed] %method_with_out_param(%class) : $@convention(method) @async (SwiftClass) -> @out Int
return %result : $@callee_guaranteed @async () -> @out Int
}