Isolation Assumptions

Going through the thread, I’ve got one more idea, which is related, but probably deserves a separate proposal.

So far, discussion have reached a stage where original problem is solved by passing isolating actor as a parameter.

But what if that is not possible. What if we want to infer the isolating actor from self. If reference is isolated to a connected region from the moment of allocation, it should be possible.

And it can be expressed using an initializer isolated to an actor parameter.

But we somehow need to pass that isolated actor parameter from initializer to the instance method.

My idea is to allow isolated keyword to be applied to stored read-only properties:

class NonSendableType {
    private var internalState = 0
    private let actor: isolated (any Actor)

    init(actor: isolated (any Actor)) { = actor

    init(another: (any Actor)) { = another // Error: isolated stored property is initialized by a non-isolated value
    func doSomeStuff() {
        // self is known to be isolated to
        // so current method must be isolated to too
	Task {
	    let value = await otherType.getAValue()

	    // hop back to
	    self.internalState += value // ok
1 Like