Swift concurrency nOOb question: if you're using Approachable Concurrency and you get warnings about using Sendable structs in non-main-actor contexts, is the recommended workaround to mark them as nonisolated?

Also, it seems odd to me that marking a struct as Sendable doesn't already exempt it from default MainActor isolation. Is there a good reason why you'd want to limit Sendable types to MainActor?

@nicklockwood the following are my thoughts wrt this question, I‘m not sure any qualify as „answer“.

MainActor-isolated should already imply Sendable, so I‘m not sure why you had to add Sendable conformance. Am I missing something?

My understanding of Approachable Concurrency is that the idea is that most people don‘t actually need as much concurrency as you get by default and „do everything on the main thread (except for explicit exceptions)“ makes your code much easier to understand without significant performance issues in the majority of cases. Based on that it makes sense to make all your structs MainActor-isolated so keep this simplicity independent of whether it‘s needed for Sendability.

@nicklockwood I just realized I misread the error message you talked about. I thought it was about using non-sendable structs in a non-main-actor context.

Why does using *Sendable* structs in a different context generate warnings at all? Like, why would this be an issue?

@cocoafrog that is the essence of my confusion, yes 😅

But it seems that if a struct is marked s MainActor isolated (either explicitly or implicitly via the compiler default MainActor isolation setting) then the fact that is also marked as Sendable is of no consequence.

@nicklockwood right. On the one hand marking it as Sendable being of no consequence makes sense, because it‘s already sendable due to MainActor-isolation. On the other hand that is also kinda confusing. 😄
@cocoafrog @nicklockwood I think Nick essentially wants that if the compiler is in mainactor-default mode, an explicit Sendable conformance also makes the type non isolated.
The problem seems specific to the default main actor mode, because w/o it you wouldn’t isolate a type *and* mark it Sendable (except for ABI, I think you have to do it there, not sure).