nitro icon indicating copy to clipboard operation
nitro copied to clipboard

feat: Mark all callbacks as `@Sendable`

Open mrousavy opened this issue 5 months ago • 2 comments

In Swift 6, Swift enforces Swift concurrency even more. Which is stupid imo if you think about interop with other languages (like JS or C++, which have different concurrency modules).

So either we mark all Swift callbacks as @Sendable, or we mark all as @preconcurrency.

  • @preconcurrency seems like it would mark an API as legacy, which I don't think makes sense.
  • @Sendable sounds like it just marks the function as callable from any Thread, which is what it essentially is.

That's at least the way I understood those concepts - it's not very well explained in low-level terminology imo, but let's just try if this works.

mrousavy avatar Jul 08 '25 18:07 mrousavy

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
nitro-docs ⬜️ Skipped (Inspect) Jul 8, 2025 6:08pm

vercel[bot] avatar Jul 08 '25 18:07 vercel[bot]

My understanding is that @preconcurrency would essentially tell the compiler to not enforce the strict concurrency rules that require Sendable in that particular closure's nested closures to make it compatible with previous versions of Swift, which is probably not an ideal thing to disable. I think that you are generally correct in what @Sendable does. I believe it is doing something to enforce thread concurrency safety. It may be doing something like an atomically referenced counted mutex behind the hood, but I believe it is the generally proposed method by Swift 6 for promoting something like memory locking in closures to prevent race conditions, though I'd love more explanation from those that know.

TimGass avatar Jul 08 '25 18:07 TimGass