|
| 1 | +// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s --dump-input=always |
| 2 | + |
| 3 | +// REQUIRES: concurrency |
| 4 | +// REQUIRES: executable_test |
| 5 | +// REQUIRES: concurrency_runtime |
| 6 | + |
| 7 | +// rdar://78109470 |
| 8 | +// UNSUPPORTED: back_deployment_runtime |
| 9 | +// UNSUPPORTED: freestanding |
| 10 | + |
| 11 | +import _Concurrency |
| 12 | +import StdlibUnittest |
| 13 | + |
| 14 | +@main struct Main { |
| 15 | + static func main() async { |
| 16 | + await explicitIsolatedParam() |
| 17 | + // CHECK: go - explicitIsolatedParam |
| 18 | + // CHECK: outerIsolation = #isolation = Optional(Swift.MainActor) |
| 19 | + // CHECK: Task{} #isolation = nil |
| 20 | + // CHECK: Task{ [outerIsolation] } outerIsolation = Optional(Swift.MainActor), #iso = Optional(Swift.MainActor) |
| 21 | + // CHECK: done - explicitIsolatedParam |
| 22 | + |
| 23 | + print() |
| 24 | + await nonisolatedNonsending() |
| 25 | + // CHECK: go - nonisolatedNonsending |
| 26 | + // CHECK: outerIsolation = #isolation = Optional(Swift.MainActor) |
| 27 | + // CHECK: Task{} #isolation = nil |
| 28 | + // CHECK: Task{ [outerIsolation] } outerIsolation = Optional(Swift.MainActor), #iso = nil |
| 29 | + // CHECK: done - nonisolatedNonsending |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +func explicitIsolatedParam(isolation: isolated (any Actor)? = #isolation) async { |
| 34 | + print("go - \(#function)") |
| 35 | + MainActor.assertIsolated() |
| 36 | + |
| 37 | + let outerIsolation = #isolation |
| 38 | + print("outerIsolation = #isolation = \(String(describing: outerIsolation))") |
| 39 | + |
| 40 | + await Task { |
| 41 | + let iso = #isolation |
| 42 | + print("Task{} #isolation = \(String(describing: iso))") |
| 43 | + }.value |
| 44 | + |
| 45 | + await Task { |
| 46 | + let iso = #isolation |
| 47 | + print("Task{ [outerIsolation] } outerIsolation = \(String(describing: isolation)), #iso = \(String(describing: iso))") |
| 48 | + }.value |
| 49 | + |
| 50 | + print("done - \(#function)") |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +nonisolated(nonsending) func nonisolatedNonsending() async { |
| 55 | + print("go - \(#function)") |
| 56 | + MainActor.assertIsolated() |
| 57 | + |
| 58 | + let outerIsolation = #isolation |
| 59 | + print("outerIsolation = #isolation = \(String(describing: outerIsolation))") // WRONG; this is nil today |
| 60 | + |
| 61 | + await Task { |
| 62 | + let iso = #isolation |
| 63 | + print("Task{} #isolation = \(String(describing: iso))") |
| 64 | + }.value |
| 65 | + |
| 66 | + await Task { |
| 67 | + let iso = #isolation |
| 68 | + print("Task{ [outerIsolation] } outerIsolation = \(String(describing: outerIsolation)), #iso = \(String(describing: iso))") |
| 69 | + }.value |
| 70 | + |
| 71 | + print("done - \(#function)") |
| 72 | +} |
0 commit comments