Has Swift's concurrency model gone too far?

Here's the original signature, including the underscored attribute that is omitted from generated documentation:

@discardableResult
public init(
    priority: TaskPriority? = nil,
    @_inheritActorContext operation: sending @escaping @isolated(any) () async -> Success
)

I'd love to apply three simplifications:

  1. Make @_inheritActorContext the default behavior for an @isolated(any) function
  2. Make use of the ideas that the proposal which added @isolated(any) notes and have it imply sending
  3. Exploit the fact that I cannot think of a way that a synchronous function could do useful work with an asynchronous closure argument unless it is allowed to escape

2 might be cheating, and 3 could just be impossible and/or a bad idea. I haven't thought about either too hard. But, regardless, it's interesting to imagine.

@discardableResult
public init(
    priority: TaskPriority? = nil,
    operation: @isolated(any) () async -> Success
)
5 Likes