Skip to content

[NFC][Concurrency] Add a few test cases for isolated parameters. #68303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/Concurrency/isolated_parameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,32 @@ func isolatedClosures() {
a.f()
}
}

// Test case for https://github.com/apple/swift/issues/62568
func execute<ActorType: Actor>(
on isolatedActor: isolated ActorType,
task: @escaping @Sendable (isolated ActorType) -> Void)
{
// Compiler correctly allows this task to execute synchronously.
task(isolatedActor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit confusing to call this "task" but code is good 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, but I copied the test case from #62568

// 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)
}
}

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]
}
}