From 68a4b314c9027ba2a3c44bdbfe20b6b36607838b Mon Sep 17 00:00:00 2001 From: Holly Borla Date: Sun, 3 Sep 2023 12:22:42 -0700 Subject: [PATCH 1/2] [NFC][Concurrency] Add a test case for inheriting actor context within a function that uses isolated parameters. --- test/Concurrency/isolated_parameters.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/Concurrency/isolated_parameters.swift b/test/Concurrency/isolated_parameters.swift index 9cefc1aae0296..cdb587a8e15c5 100644 --- a/test/Concurrency/isolated_parameters.swift +++ b/test/Concurrency/isolated_parameters.swift @@ -319,3 +319,17 @@ func isolatedClosures() { a.f() } } + +// Test case for https://github.com/apple/swift/issues/62568 +func execute( + on isolatedActor: isolated ActorType, + task: @escaping @Sendable (isolated ActorType) -> Void) +{ + // Compiler correctly allows this task to execute synchronously. + task(isolatedActor) + // Start a task that inherits the current execution context (i.e. that of the isolatedActor) + Task { + // 'await' is not not necessary because 'task' is synchronous. + task(isolatedActor) + } +} From 511add67274c916db1b2212f1b964d0c2a94a310 Mon Sep 17 00:00:00 2001 From: Holly Borla Date: Sun, 3 Sep 2023 12:32:50 -0700 Subject: [PATCH 2/2] [NFC][Concurrency] Add a test case for non-escaping, synchronous closures used inside a function with an isolated parameter. --- test/Concurrency/isolated_parameters.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/Concurrency/isolated_parameters.swift b/test/Concurrency/isolated_parameters.swift index cdb587a8e15c5..08dc4f226577c 100644 --- a/test/Concurrency/isolated_parameters.swift +++ b/test/Concurrency/isolated_parameters.swift @@ -333,3 +333,18 @@ func execute( task(isolatedActor) } } + +actor ProtectsDictionary { + var dictionary: [String: String] = ["A": "B"] +} + +func getValues( + forKeys keys: [String], + from actor: isolated ProtectsDictionary +) -> [String?] { + // A non-escaping, synchronous closure cannot cross isolation + // boundaries; it should be isolated to 'actor'. + keys.map { key in + actor.dictionary[key] + } +}