[Pitch #2] Actors

It doesn't work completely safely because of escaping closures.

My opinion is based on porting code to the new model, and escaping closures that attempt to access actor state came up fairly often where the compiler caught me. Some of it is porting detritus, e.g., a myQueue.async { ... } in a class that's getting ported to an actor. The more persistent issues come up when setting a callback somewhere that calls back into the actor, e.g., wiring up a subscriber into a reactive streams library, setting up an event handler in a UI or in reaction to some other external event. All of those common patterns will continue to use @escaping, and relying on folks to go back and ensure that those places gain a @concurrent to prevent data races on actors undercuts the whole model. I consider this problem to be an order of magnitude worse than the one solved by ConcurrentValue.

I doubt it will be that different, so long as it's not trying to solve both problems at once and can reference a definition of a concurrent closure/local function elsewhere, the rule is: if the place where self is captured is concurrent or escaping, it's independent of the actor.

As I've noted repeatedly, this is not what I'm proposing.

Yes, I know, but you're arguing against a position I haven't ever held. I described the reasons for each cell in the escaping/concurrent matrix specifically over here.... 23 days ago.

There are very interesting questions about @concurrent functions and closures to resolve that are getting drowned out by this. Fortunately, most of the implementation is straightforward, including how mutating checking ties in with the "may execute concurrently with" checks from the "Preventing Data Races" document. But these are better dealt with in the other thread.

Right now, if you declare an @objc class, it must inherit from NSObject. That's also the only way to conform to NSObjectProtocol. And the latter brings in most of the legacy methods, so I don't know that we'll fix much by making actors different from classes in this regard.

You can declare @objc members without inheriting from NSObject, of course. I think that's what you're remembering.

Doug

3 Likes