-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blending readonly
and isolated
#1244
Comments
This will also affect the definition of Cloneable. |
I am going to call the current readonly semantics true-readonly and the readonly semantics that allows isolated objects effectively-readonly. I think the right direction is to loosen
In other words, I think the spec should have one concept of readonly and that concept should be effectively readonly and thus allow isolated objects. |
If we try to make Also if we define |
Let's explore the other approach, where the meaning of More flexibility in declaring immutability of typesAllow
|
@MaryamZi Please see if you can find any holes in the above proposal. |
The main purpose of
readonly
in Ballerina is concurrency safety. This is the reason whyreadonly
in Ballerina is strictly transitive. Areadonly
value cannot directly or indirectly reference an value that is not readonly. This restriction ensures that passing a readonly value to another strand is always safe: it cannot create a data race.Historically, the
isolated
feature was developed after thereadonly
feature. With the introduction ofisolated
, this restriction is stronger than needed. Specifically, if areadonly
only object was allowed to refer to an isolated object, it would still be safe to pass areadonly
value to another strand.Let's use the term effectively readonly to mean like readonly but also allowing isolated objects. More precisely, we can define an effectively readonly value to be any of:
where an effectively readonly list, map or table is one where the cell of every member
An effectively readonly value would then be safe to pass to another strand.
We also need clone to work on effectively readonly values as it does on readonly values: clone(x) would return x if x is effectively readonly.
An important question is whether we need to have both readonly and effectively readonly. It would be nice if we didn't since this is all too complicated already. One place where we might need true readonly (as opposed to effectively readonly) is annotations.
This would be quite a deep and complicated change
The text was updated successfully, but these errors were encountered: