[Proposal Idea] Error: Sendable, AnySendable

Two Concurrency proposals:

  1. Enforce Error to inherit Sendable.
  2. Add AnySendable type. Mainly for property-list data applications, to replace what's now [String: Any] with [String: AnySendable]. For example in WCSessionDelegate.

Can you provide more info here about your proposal? Error already inherits Sendable:

protocol Error : Sendable

Can you flesh out your idea with some examples of where AnySendable would be required over any Sendable?

1 Like

There is already any Sendable, and you can already write [String: any Sendable].

1 Like

And unfortunately, Any and any Sendable are not compatible with each other, so this is a breaking change for all existing users of any API that makes that change.

I do think there's an opportunity to special case any Hashable: Hashable the way any Error: Error (and any Sendable: Sendable). While AnyHashable has filled a gap in Swift for a long time, it does not compose with other protocols, so if you have a type that relies on AnyHashable for hashability and then need sendability, you're forced to make a decision and you may make an incorrect one.

2 Likes

Exhibit A: Making AnyHashable Sendable

Strangely I got some errors while was trying to send an error, so I assumed it's not sendable. Can't reproduce anymore, probably compiler errors were caused by other types.

So yes, it would be good to update all the APIs to support concurrency. Both any Sendable and AnySendable should be equally good I think.