|
| 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-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) |
| 6 | +// RUN: %target-codesign %t/main |
| 7 | +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s |
| 8 | + |
| 9 | +// REQUIRES: executable_test |
| 10 | +// REQUIRES: swift_test_mode_optimize_none |
| 11 | +// REQUIRES: concurrency |
| 12 | +// UNSUPPORTED: use_os_stdlib |
| 13 | +// UNSUPPORTED: CPU=arm64e |
| 14 | + |
| 15 | +import Builtin |
| 16 | +import Swift |
| 17 | +import PrintShims |
| 18 | +import _Concurrency |
| 19 | + |
| 20 | +sil public_external @printGeneric : $@convention(thin) <T> (@in_guaranteed T) -> () |
| 21 | +sil public_external @printInt64 : $@convention(thin) (Int64) -> () |
| 22 | + |
| 23 | +sil hidden @createAndInvokeClosure : $@async @convention(thin) () -> () { |
| 24 | +bb0: |
| 25 | + %captured_literal = integer_literal $Builtin.Int64, 783247897 |
| 26 | + %captured = struct $Int64 (%captured_literal : $Builtin.Int64) |
| 27 | + %createPartialApply = function_ref @createPartialApply : $@async @convention(thin) (Int64) -> @owned @async @callee_guaranteed (Int64) -> (Int64, @error Error) |
| 28 | + %partialApply = apply %createPartialApply(%captured) : $@async @convention(thin) (Int64) -> @owned @async @callee_guaranteed (Int64) -> (Int64, @error Error) |
| 29 | + strong_retain %partialApply : $@async @callee_guaranteed (Int64) -> (Int64, @error Error) |
| 30 | + %applied_literal = integer_literal $Builtin.Int64, 7823478 |
| 31 | + %applied = struct $Int64 (%applied_literal : $Builtin.Int64) |
| 32 | + try_apply %partialApply(%applied) : $@async @callee_guaranteed (Int64) -> (Int64, @error Error), normal success, error failure |
| 33 | + |
| 34 | +success(%sum : $Int64): |
| 35 | + %printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> () |
| 36 | + %result = apply %printInt64(%sum) : $@convention(thin) (Int64) -> () // CHECK: 791071375 |
| 37 | + br exit |
| 38 | + |
| 39 | +failure(%error : $Error): |
| 40 | + br exit |
| 41 | + |
| 42 | +exit: |
| 43 | + strong_release %partialApply : $@async @callee_guaranteed (Int64) -> (Int64, @error Error) |
| 44 | + strong_release %partialApply : $@async @callee_guaranteed (Int64) -> (Int64, @error Error) |
| 45 | + %out = tuple () |
| 46 | + return %out : $() |
| 47 | +} |
| 48 | + |
| 49 | +// CHECK-LL: @closureAD = |
| 50 | +// CHECK-LL: define internal swiftcc void @closure(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}}) {{#[0-9]*}} |
| 51 | +// CHECK-LL: define internal swiftcc void @"$s7closureTA"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}}) {{#[0-9]*}} |
| 52 | +sil hidden @createPartialApply : $@async @convention(thin) (Int64) -> @owned @async @callee_guaranteed (Int64) -> (Int64, @error Error) { |
| 53 | +bb0(%captured : $Int64): |
| 54 | + %closure = function_ref @closure : $@async @convention(thin) (Int64, Int64) -> (Int64, @error Error) |
| 55 | + %partialApply = partial_apply [callee_guaranteed] %closure(%captured) : $@async @convention(thin) (Int64, Int64) -> (Int64, @error Error) |
| 56 | + return %partialApply : $@async @callee_guaranteed (Int64) -> (Int64, @error Error) |
| 57 | +} |
| 58 | + |
| 59 | +sil private @closure : $@async @convention(thin) (Int64, Int64) -> (Int64, @error Error) { |
| 60 | +bb0(%one : $Int64, %two : $Int64): |
| 61 | + %printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> () |
| 62 | + %printInt64_1 = apply %printInt64(%one) : $@convention(thin) (Int64) -> () |
| 63 | + %printInt64_2 = apply %printInt64(%two) : $@convention(thin) (Int64) -> () |
| 64 | + %one_builtin = struct_extract %one : $Int64, #Int64._value |
| 65 | + %two_builtin = struct_extract %two : $Int64, #Int64._value |
| 66 | + %flag = integer_literal $Builtin.Int1, -1 |
| 67 | + %sumAndOverflowed = builtin "sadd_with_overflow_Int64"(%one_builtin : $Builtin.Int64, %two_builtin : $Builtin.Int64, %flag : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) |
| 68 | + %sum_builtin = tuple_extract %sumAndOverflowed : $(Builtin.Int64, Builtin.Int1), 0 |
| 69 | + %overflowed = tuple_extract %sumAndOverflowed : $(Builtin.Int64, Builtin.Int1), 1 |
| 70 | + cond_fail %overflowed : $Builtin.Int1, "arithmetic overflow" |
| 71 | + %sum = struct $Int64 (%sum_builtin : $Builtin.Int64) |
| 72 | + return %sum : $Int64 |
| 73 | +} |
| 74 | +// Defined in _Concurrency |
| 75 | +sil public_external @$s12_Concurrency8runAsyncyyyyYcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> () |
| 76 | + |
| 77 | +sil @test_case : $@convention(thin) @async () -> () { |
| 78 | + %createAndInvokeClosure = function_ref @createAndInvokeClosure : $@async @convention(thin) () -> () |
| 79 | + %createAndInvokeClosure_result = apply %createAndInvokeClosure() : $@async @convention(thin) () -> () |
| 80 | + |
| 81 | + %void = tuple() |
| 82 | + return %void : $() |
| 83 | +} |
| 84 | + |
| 85 | +sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { |
| 86 | +bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): |
| 87 | + |
| 88 | + %2 = function_ref @test_case : $@convention(thin) @async () -> () |
| 89 | + %3 = thin_to_thick_function %2 : $@convention(thin) @async () -> () to $@async @callee_guaranteed () -> () |
| 90 | + %4 = function_ref @$s12_Concurrency8runAsyncyyyyYcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> () |
| 91 | + %5 = apply %4(%3) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> () |
| 92 | + |
| 93 | + %6 = integer_literal $Builtin.Int32, 0 |
| 94 | + %7 = struct $Int32 (%6 : $Builtin.Int32) |
| 95 | + return %7 : $Int32 |
| 96 | +} |
| 97 | + |
0 commit comments