|
| 1 | +// RUN: %empty-directory(%t/src) |
| 2 | +// RUN: split-file %s %t/src |
| 3 | + |
| 4 | +/// Build the library A |
| 5 | +// RUN: %target-swift-frontend -emit-module %t/src/Preconcurrency.swift \ |
| 6 | +// RUN: -module-name Preconcurrency -swift-version 5 -enable-library-evolution \ |
| 7 | +// RUN: -emit-module-path %t/Preconcurrency.swiftmodule |
| 8 | + |
| 9 | +// RUN: %target-swift-emit-silgen -swift-version 6 -disable-availability-checking -I %t %t/src/test.swift -o - -verify | %FileCheck %s |
| 10 | + |
| 11 | +// REQUIRES: concurrency |
| 12 | + |
| 13 | +//--- Preconcurrency.swift |
| 14 | + |
| 15 | +public func takeNonSendableClosure_preconcurrency(_ fn: @escaping () -> Int) {} |
| 16 | +public func takeNonSendableClosure_preconcurrency_generic<T>(_ fn: @escaping () -> T) {} |
| 17 | + |
| 18 | +//--- test.swift |
| 19 | + |
| 20 | +import Preconcurrency |
| 21 | + |
| 22 | +func takeNonSendableClosure_strict(_ fn: @escaping () -> Int) { } |
| 23 | +@preconcurrency |
| 24 | + |
| 25 | +actor MyActor { |
| 26 | + var counter = 0 |
| 27 | +} |
| 28 | +func forceIsolation(isolation: isolated MyActor?) {} |
| 29 | + |
| 30 | +// rdar://132478429 |
| 31 | +// |
| 32 | +// We were trying to emit dynamic isolation checks in functions that are |
| 33 | +// isolated to optional actor references by just passing that reference |
| 34 | +// directly to extract_executor, which is incorrect --- we need to skip |
| 35 | +// the check when the reference is nil. |
| 36 | + |
| 37 | +// CHECK-LABEL: sil private [ossa] @$s4test0A25OptionalIsolation_checked9isolationyAA7MyActorCSgYi_tFSiycfU_ : |
| 38 | +// CHECK: [[T0:%.*]] = copy_value %0 : $Optional<MyActor> |
| 39 | +// CHECK-NEXT: [[BORROW:%.*]] = begin_borrow [[T0]] : |
| 40 | +// CHECK-NEXT: switch_enum [[BORROW]] : $Optional<MyActor>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2 |
| 41 | +// CHECK: bb1([[T0:%.*]] : @guaranteed $MyActor): |
| 42 | +// CHECK-NEXT: extract_executor [[T0]] : $MyActor |
| 43 | +// CHECK: // function_ref _checkExpectedExecutor |
| 44 | +// CHECK: br bb3 |
| 45 | +// CHECK: bb2: |
| 46 | +// CHECK-NEXT: br bb3 |
| 47 | +func testOptionalIsolation_checked(isolation: isolated MyActor?) { |
| 48 | + takeNonSendableClosure_preconcurrency { |
| 49 | + // This closure inherits isolation because it's non-Sendable, and |
| 50 | + // it requires a dynamic check because we're passing it to a |
| 51 | + // preconcurrency function. |
| 52 | + forceIsolation(isolation: isolation) |
| 53 | + return 0 |
| 54 | + } |
| 55 | +} |
0 commit comments