I've updated the proposal to fix this sentence, thank you!
I think "methods" is accurate here, since we're inside an actor. Is there some case you're thinking of that isn't covered?
I don't think there is a good way to provide synchronous access to isolated state. You need to get onto the actor somehow, and that bit has to be asynchronous.
The way I wrote this is indeed confusing, because it does sound like there's a magic await. The await that indicates we might have a suspension point is the one required to call this async closure. The actual suspension point is at the beginning of the async function implementation, where it ensures that it's running on the right actor. I updated the wording to sound less magical:
Such closures are like async functions on the actor itself, and will switch to the actor at the beginning of the closure body to ensure that are running on the actor, then execute the rest of the body.
No, it doesn't break this, because it isn't general. It's explicitly capturing an isolated parameter in a closure. This happens implicitly all the time with self when you form a (non-Sendable) closure within an actor function, and this is the proposed syntax for allowing it to be explicit.
Yes, that's true. I'd worry about that if these features spanned multiple Swift releases, but that doesn't look likely to happen.
Yes, that's essentially what we're thinking. Let's start with the safe model, and when we hit the limitations we'll have a better understanding of what kind of unsafe backdoors we actually need.
The isolated is part of the parameter, not its type, and the proposal talks about the requirement that one interact asynchronously if you're passing a non-isolated value to an isolated parameter. Your example above is similar to what's in the section on multiple isolated parameters. Your x(a:) has two isolated parameters, self and a, and the erroneous call site is trying to provide different values to those isolated parameters. The section in the proposal implies such a thing would be erroneous
Therefore, the only way to safely call f is to pass the same actor twice:
but isn't clear what happens if you don't do that. I've extended the example there to show a similar erroneous case where you pass two different actors to isolated parameters.
This is part of the reason why this proposal started out banning multiple isolated parameters, because it's easier to explain than the above.
We found that we needed essentially this API on the main actor as well, where it looks like this:
extension MainActor {
static func run<T>(operation: @Sendable @MainActor () throws -> T) async rethrows -> T {
return try await operation()
}
}
It's essentially API sugar for writing an extension of the actor type. I'm not opposed to having it on Actor.
I think your contention is that we should have this API instead of allowing isolated parameters explicitly in capture lists, as in [isolated self]? Do you still feel that way even with the explanation above that [isolated self] is only an explicit way to spell something that happens implicitly?
For everyone: where I said I've clarified something, it's in the now-merged pull request at [SE-0313] Clarifications by DougGregor ¡ Pull Request #1351 ¡ apple/swift-evolution ¡ GitHub
Doug