The issue raised here is very critical, but I suggest we first have SE-0313 (SE-0313: Improved control over actor isolation) finalized and accepted, then we can look back at how to solve the synchronous accessing of nonisolated let
issue.
The main reason is that currently we have two approaches towards actor isolation:
- Using
nonisolated let
as value-directed way (which is described in the main body of SE-0313). - Using
@sync MyActor
and@async MyActor
as a type-directed way (which is mentioned in the alternatives considered section of SE-0313, see Exploration: Type System Considerations for Actor Proposal).
While I have replied in SE-0313 that we should discuss more about the pros and cons of these two approaches, I find it quite easy to solve the problem raised in this proposal with the type-directed way (@sync MyActor
and @async MyActor
):
This is the free function that mentioned in this proposal
Which is equivalent to the following definition using type-directed way:
func displayAccount(account: @sync BankAccount) {
// Same synchronous accessing to BackAccount actors
}
So with the type-directed approach, no matter how we change between the let
and var
for property declarations, we can always access these from an actor, as long as it is a @sync BackAccount
.
Actually the issue raised in this proposal convinced me that the type-directed approach (@sync MyActor
and @async MyActor
) is a better way to solve those issues related to actor isolation, because we use the type system to handle the cases in a uniformed way instead of creating complex syntax rules just for fixing holes.