Sugar for isolated parameters?

Thanks to nonisolated(nonsending) functions, isolated parameters are much less-needed than ever. But, they still do come up, particularly when working with non-Sendable types. And my experience is that people, in general, find the syntax quite intimidating. But beyond that, it also sometimes feels like an internal detail of the system. I think nonisolated(nonsending) really highlights this, because in that case the parameter has actually been made an internal detail.

So now, I find myself wondering if that's something that could be useful to expand like this:

class NonSendable {
	func explicitParam(actor: isolated any Actor) {
	}

	// hypothetical syntax
	isolated func implicitParam() {
	}
}

Now, on the one hand, I think that nonisolated(nonsending) has gone so far to help here, it could be this is mostly just not an issue worth spending more energy on. But then again, using isolated (any Actor)? with a non-Sendable is unsafe, and I find that pretty non-obvious (despite it just being a bug). That's a real pain, because then you cannot use #isolation to hide the bookkeeping at call-sites. And then there's the whole thing about how unusual the special parameter thing in the first place. These reasons alone feel fairly compelling to me.

It is true that you'd be giving up explicit control over the actor type. But my experience is that is very rarely required, and isn't possible with nonisolated(nonsending) functions anyways, so there's a nice symmetry here. I think this could be pretty much identical internally, including resolving the #isolation expression inside the function body.

So, the question. Is sugar like this worth it? I've gone back and forth on this topic a number of times, but I finally decided it could be worth getting other opinions.

2 Likes

I don’t think adding yet another way to spell the same thing is going to be helpful here. (insert xkcd standards comic here)

isolated without anything attached to it is also very confusing, because it is very unclear isolated “to what” that is trying to say. It does make sense in actors, because it’s just the opposite of nonisolated.

Well, then we could say isolated(caller) which was a spelling of nonisolated(nonsending) which for better or worse was rejected during SE review.

Given that, I’m not sure what the actual proposal stand to win here.

3 Likes

I think you are 100% right that it would be unclear what you would be isolated to. Thanks so much for coming up with that reasoning, just what I was looking for.