Ancestors

Written by Finn Voorhees on 2025-01-10 at 22:19

Introducing the @ stfu macro, your one stop shop for fixing all your concurrency problems. See an error full of words you don't understand like sendable, non-isolated, sending, data race, shared mutable state? Simply tag your code with @ stfu and watch the errors disappear™️!

=> View attached media

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Finn Voorhees on 2025-01-11 at 15:44

the region based isolation checker isn't real it can't hurt you

=> View attached media

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Finn Voorhees on 2025-01-11 at 20:39

Don't want to pile on to the criticism too much, but concurrency just feels broken in Swift 6. Why would passing a CGFloat across threads cause a data race? Swift 6.1 tells me it's actually previewLayer that causes the issue. I wanted to at least try to avoid future concurrency issues, but that's pretty hard when the compiler is just wrong.

=> View attached media

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 02:23

@finnvoorhees This is a bug

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Finn Voorhees on 2025-01-12 at 10:19

@mattiem this is my problem, I can’t use swift 6 concurrency if, in the 4 hours I’ve used it, I’ve already run in to 2 compiler bugs (+ also the lack of annotations)

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 10:26

@finnvoorhees Yeah it can be quite hard, especially right now.

If you do want to figure these things out we totally can. But staying in 5 mode is not just valid, but a good option for many (as long as you aren’t also currently using concurrency features)

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Finn Voorhees on 2025-01-12 at 12:26

@mattiem I really want to use Swift 6 (at least in some small projects). Do you think it's at a point where putting in the time to figure everything out is worth it, or is it likely that in a few months / a year I would need to rewrite a bunch of code due to changes in how concurrency works (because that's what's happened over the past 1-2 years).

If it's a good time then I'll just bite the bullet, read through every article you've written, and try to adapt my code for Swift 6.

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 12:37

@finnvoorhees There are big changes looming. But I wouldn't be afraid to start now, especially for small projects. Fixing incorrect concurrency code (like that example) is 10x harder than starting with diagnostics on from the start.

But if you are starting from zero here, you don't have to read everything I've written! The step by step stuff I think provides a good foundation.

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Finn Voorhees on 2025-01-12 at 12:40

@mattiem Cool, I'll give it a go.

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 12:51

@finnvoorhees Don’t be shy with questions!

Dealing with missing SDK annotations is annoying but almost always easy.

90% of problems come from trying to use concurrency without isolation defined. Once you get why this is a problem and how to address it you’ll be fine.

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Finn Voorhees on 2025-01-12 at 13:02

@mattiem you already receive too many questions, but I'm not sure how else to figure any of this out 😅

Here's a common issue I've run into. How do I "send" non-sendables? The sending keyword is great for function returns, but what about cases like this?

=> View attached media

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 13:05

@finnvoorhees Remember what I said about 90% of questions?

PhotoCapturer is a class with no isolation and an async method 😉

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 13:06

@finnvoorhees This might be what you actually want but it’ll require a lot more tricks. Are you certain you want non-isolated types here?

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Finn Voorhees on 2025-01-12 at 13:08

@mattiem hmm, not really following. Sure I can make PhotoCapturer MainActor or an actor, but that doesn't fix the error in PhotoCaptureDelegate?

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 13:16

@finnvoorhees Sorry! I assumed what motivated you to use this shared continuation was to avoid isolation mismatches with that delegate protocol you need conform to.

I haven't actually used a shared continuation in exactly this way before, but if you know that it's safe to move this type to an arbitrary thread here, we can cook something up. Will probably need to use a nonisolated(unsafe) opt-out.

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Finn Voorhees on 2025-01-12 at 13:21

@mattiem Ah that's what I was looking for, I can mark the photo as nonisolated(unsafe) when I know it's no longer accessed, and that silences the error.

Would be great if the compiler knew it was fine to send, but I'm assuming this is being worked on.

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 13:23

@finnvoorhees Great!

And, hope springs eternal.

=> More informations about this toot | More toots from mattiem@mastodon.social

Written by Matt Massicotte on 2025-01-12 at 13:37

@finnvoorhees Just to elaborate slightly, this pattern of a multi-step callback delegate is probably unsupportable. But I have not really put in the effort to prove that to myself.

So the "hope" here is that AVFoundation gets new APIs. I don't think the compiler can ever know this is current mechanism is safe unless lots of types become Sendable, which I imagine cannot happen.

=> More informations about this toot | More toots from mattiem@mastodon.social

Toot

Written by Finn Voorhees on 2025-01-12 at 13:49

@mattiem It seems like the compiler should be able to figure out when non-sendables can be safely sent based on ref count + accesses (I'm sure there's a bunch of reasons why this is difficult).

In the simplest case, shouldn't the compiler know that this can't cause any data races?

=> View attached media

=> More informations about this toot | More toots from finnvoorhees@mastodon.social

Descendants

Written by Matt Massicotte on 2025-01-12 at 13:55

@finnvoorhees This is a great question actually.

I think the answer is that yes, it can (and does) know when it can see the internals of all functions.

But if those internals later changed, it would result in arbitrary non-local errors. You have to use sending to express this promise as part of your API. This is annoying for simple cases, but I think it is absolutely critical in the general case.

=> More informations about this toot | More toots from mattiem@mastodon.social

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113815702588211063
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
385.909906 milliseconds
Gemini-to-HTML Time
4.099216 milliseconds

This content has been proxied by September (3851b).