I wrote up a pitch for importing Objective-C completion handler parameters as @Sendable by default. The idea is pretty straightforward - the Objective-C interoperability heuristic that identifies completion handler parameters for importing async functions will also include @Sendable annotations by default on the completion handler parameter.
I'm sure this will add a bunch of warnings to everyone's code, but probably mostly genuine ones, and I don't see a better option...
Perhaps a hole should be carved out where @MainActor methods' completion handlers are presumed @MainActor, rather than @Sendable? It's not always true, but maybe true enough to consider?
+1 Makes sense. This change is the right default for when the objc interface isn't annotated. We really shouldn't assume non-sendable behavior in this case. The current situation causes a good number of crashes in real world code migrating to Swift 6 so definitely a welcome change.
I think this is a great idea for a carve out. I suspect this will avoid a significant number of false positive warnings. And because this will only apply in cases where the closure parameter is non-@Sendable today, it's not going to add any new dynamic assertions anyway. In the worse case, if we find that actually most @MainActor-isolated methods with completion handlers in practice should take @Sendable closures (which I doubt is the case), we can later extend the rule in this proposal to those methods as well.
No, but this happens to be true in many cases because of the rule that non-@Sendable closures are isolated to whatever context they're formed in. For @MainActor-isolated completion handlers, they're nearly always called in a @MainActor-isolated context (because if you were not in a @MainActor-isolated context, the call would have to be async and you're better off just using the async variant), so the closure is isolated to the main actor due to the non-@Sendable rule.
Should we broaden the rule to any global actor, not just @MainActor? I realize the use of other global actors in Objective-C probably isn't expected to be common, but with custom serial executors it may well be more common than we realize.