|
| 1 | +// RUN: %empty-directory(%t/src) |
| 2 | +// RUN: split-file %s %t/src |
| 3 | + |
| 4 | +/// Build the library API |
| 5 | +// RUN: %target-swift-frontend -emit-module %t/src/API.swift \ |
| 6 | +// RUN: -module-name API -swift-version 5 -enable-library-evolution \ |
| 7 | +// RUN: -emit-module-path %t/API.swiftmodule \ |
| 8 | +// RUN: -emit-module-interface-path %t/API.swiftinterface |
| 9 | + |
| 10 | +// Build client with module |
| 11 | +// RUN: %target-swift-emit-silgen \ |
| 12 | +// RUN: -I %t \ |
| 13 | +// RUN: -disable-availability-checking \ |
| 14 | +// RUN: -module-name Client \ |
| 15 | +// RUN: -swift-version 6 \ |
| 16 | +// RUN: %t/src/Client.swift -verify | %FileCheck %s |
| 17 | + |
| 18 | +//--- API.swift |
| 19 | +public func compute(_: (() -> Void)?) {} |
| 20 | + |
| 21 | +public func computeSendable(_: @escaping @Sendable () -> Void) {} |
| 22 | + |
| 23 | +public func computeSending(_: sending @escaping () -> Void) {} |
| 24 | + |
| 25 | +//--- Client.swift |
| 26 | +import API |
| 27 | + |
| 28 | +func localCompute(_: (() -> Void)?) {} |
| 29 | + |
| 30 | +func forceIsolation(isolation: isolated (any Actor)?) {} |
| 31 | + |
| 32 | +// CHECK-LABEL: sil private [ossa] @$s6Client17test_global_actoryyFyycfU_ : $@convention(thin) () -> () |
| 33 | +// CHECK: [[EXPECTED_EXECUTOR:%.*]] = extract_executor {{.*}} : $MainActor |
| 34 | +// CHECK: [[CHECK_EXECUTOR_FN:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, Builtin.Word, Builtin.Executor) -> () |
| 35 | +// CHECK: %11 = apply [[CHECK_EXECUTOR_FN]]({{.*}}, [[EXPECTED_EXECUTOR]]) : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, Builtin.Word, Builtin.Executor) -> () |
| 36 | +// CHECK: } // end sil function '$s6Client17test_global_actoryyFyycfU_' |
| 37 | +@MainActor |
| 38 | +func test_global_actor() { |
| 39 | + compute { |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +// CHECK-LABEL: sil private [ossa] @$s6Client13test_isolated9isolationyScMYi_tFyycfU_ : $@convention(thin) (@sil_isolated @guaranteed MainActor) -> () |
| 44 | +// CHECK: [[EXPECTED_EXECUTOR:%.*]] = extract_executor {{.*}} : $MainActor |
| 45 | +// CHECK: [[CHECK_EXECUTOR_FN:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, Builtin.Word, Builtin.Executor) -> () |
| 46 | +// CHECK: %11 = apply [[CHECK_EXECUTOR_FN]]({{.*}}, [[EXPECTED_EXECUTOR]]) : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, Builtin.Word, Builtin.Executor) -> () |
| 47 | +// CHECK: } // end sil function '$s6Client13test_isolated9isolationyScMYi_tFyycfU_' |
| 48 | +func test_isolated(isolation: isolated MainActor) { |
| 49 | + compute { |
| 50 | + forceIsolation(isolation: isolation) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +// CHECK-LABEL: sil private [ossa] @$s6Client55test_concurrency_checked_global_isolation_has_no_checksyyFyycfU_ : $@convention(thin) () -> () |
| 55 | +// CHECK-NOT: function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF |
| 56 | +// CHECK: } // end sil function '$s6Client55test_concurrency_checked_global_isolation_has_no_checksyyFyycfU_' |
| 57 | +@MainActor |
| 58 | +func test_concurrency_checked_global_isolation_has_no_checks() { |
| 59 | + localCompute { |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +// CHECK-LABEL: sil private [ossa] @$s6Client47test_concurrency_checked_isolated_has_no_checks9isolationyScMYi_tFyycfU_ : $@convention(thin) (@sil_isolated @guaranteed MainActor) -> () |
| 64 | +// CHECK-NOT: function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF |
| 65 | +// CHECK: } // end sil function '$s6Client47test_concurrency_checked_isolated_has_no_checks9isolationyScMYi_tFyycfU_' |
| 66 | +func test_concurrency_checked_isolated_has_no_checks(isolation: isolated MainActor) { |
| 67 | + localCompute { |
| 68 | + forceIsolation(isolation: isolation) |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +// CHECK-LABEL: sil private [ossa] @$s6Client24test_direct_closure_callyyFyyXEfU_ : $@convention(thin) () -> () |
| 73 | +// CHECK-NOT: function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF |
| 74 | +// CHECK: [[INNER_CLOSURE_REF:%.*]] = function_ref @$s6Client24test_direct_closure_callyyFyyXEfU_yycfU_ : $@convention(thin) () -> () |
| 75 | +// CHECK-NEXT: [[INNER_CLOSURE:%.*]] = thin_to_thick_function [[INNER_CLOSURE_REF]] : $@convention(thin) () -> () to $@callee_guaranteed () -> () |
| 76 | +// CHECK-NEXT: [[OPT_INNER_CLOSURE:%.*]] = enum $Optional<@callee_guaranteed () -> ()>, #Optional.some!enumelt, [[INNER_CLOSURE]] : $@callee_guaranteed () -> () |
| 77 | +// CHECK: [[COMPUTE_FN:%.*]] = function_ref @$s3API7computeyyyycSgF : $@convention(thin) (@guaranteed Optional<@callee_guaranteed () -> ()>) -> () |
| 78 | +// CHECK-NEXT: apply [[COMPUTE_FN]]([[OPT_INNER_CLOSURE]]) : $@convention(thin) (@guaranteed Optional<@callee_guaranteed () -> ()>) -> () |
| 79 | +// CHECK: } // end sil function '$s6Client24test_direct_closure_callyyFyyXEfU_' |
| 80 | + |
| 81 | +// CHECK-LABEL: sil private [ossa] @$s6Client24test_direct_closure_callyyFyyXEfU_yycfU_ : $@convention(thin) () -> () |
| 82 | +// CHECK: [[EXPECTED_EXECUTOR:%.*]] = extract_executor {{.*}} : $MainActor |
| 83 | +// CHECK: [[CHECK_EXECUTOR_FN:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, Builtin.Word, Builtin.Executor) -> () |
| 84 | +// CHECK: %11 = apply [[CHECK_EXECUTOR_FN]]({{.*}}, [[EXPECTED_EXECUTOR]]) : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, Builtin.Word, Builtin.Executor) -> () |
| 85 | +// CHECK: } // end sil function '$s6Client24test_direct_closure_callyyFyyXEfU_yycfU_' |
| 86 | +@MainActor |
| 87 | +func test_direct_closure_call() { |
| 88 | + { |
| 89 | + compute { |
| 90 | + } |
| 91 | + }() |
| 92 | +} |
| 93 | + |
| 94 | +@MainActor |
| 95 | +func test_global_actor_sendable_and_sending_closures() { |
| 96 | + // CHECK-LABEL: sil private [ossa] @$s6Client47test_global_actor_sendable_and_sending_closuresyyFyyYbcfU_ : $@convention(thin) @Sendable () -> () |
| 97 | + // CHECK-NOT: function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF |
| 98 | + // CHECK: } // end sil function '$s6Client47test_global_actor_sendable_and_sending_closuresyyFyyYbcfU_' |
| 99 | + computeSendable { |
| 100 | + } |
| 101 | + |
| 102 | + // CHECK-LABEL: sil private [ossa] @$s6Client47test_global_actor_sendable_and_sending_closuresyyFyycfU0_ : $@convention(thin) () -> () |
| 103 | + // CHECK-NOT: function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF |
| 104 | + // CHECK: } // end sil function '$s6Client47test_global_actor_sendable_and_sending_closuresyyFyycfU0_' |
| 105 | + computeSending { |
| 106 | + forceIsolation(isolation: #isolation) |
| 107 | + } |
| 108 | +} |
0 commit comments