-
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
Isolated module level variables and objects #599
Comments
This is required to support service concurrency #116 |
When we do this, remove "concurrency safety" from future functionality appendix. |
Regarding copying out values, the proposal says
Consider the following example: isolated class Foo {
private map<int> m = {};
isolated function baz() {
map<int> x = {};
map<int>[] y = [x];
Bar bar = new;
lock {
x = self.m; // Case I - error, OK
// Also errors?
y[1] = self.m; // Case II
y.push(self.m); // Case III
bar.setMap(self.m); // Case IV
}
}
}
class Bar {
int i = 1;
private map<int> m = {};
isolated function setMap(map<int> m) {
self.m = m;
}
} While Case I is an error (since it is "writing to a variable defined outside the lock statement"), I assume the rest should also result in errors? Would appreciate clarification regarding the condition that would make them errors?
|
Case I is an error because you are writing to variable x and the type of x is not readonly/cloned/isolated. In case II and III you are reading the value of variable y and so transferring it in. This is an error because it is not readonly/cloned/isolated. Similarly case IV is an error because you are reading variable bar. |
Yes, missed that. Thank you. |
Follow up question regarding using Since |
This would be OK:
So the answer to your last question is no. |
Noted, will allow this. |
@MaryamZi I think I gave the wrong answer to you in #145 (comment) as regards |
Part of #599. In the proposal these were called unique expressions.
Still need to figure out when a query-expr or object-constructor-expr should be treated as isolated; can probably push till later. I haven't yet made variables that are only referenced once be isolated; it's better just to rely on let expressions (where we can allow multiple references). |
Things still to do:
|
I wonder if clone and Cloneable should treat isolated objects like immutable values. So inter-worker message send could send an isolated object between workers. |
Noted, we will allow these. |
Since the module variable declaration section says "The keyword isolated occurring immediately before the typed-binding-pattern is parsed as part of isolated-final-quals rather than as part of typed-binding-pattern.", is it correct for the following to result in an error, since it would mean duplicate e.g., isolated isolated object {} x = new Foo();
isolated class Foo {
} |
That sentence is only to address the ambiguity in
The grammar would allow
|
Noted, thank you. Would also appreciate clarification regarding the following, for isolated expressions. The spec says
Does this mean that for one of these explicitly mentioned expressions, or for one of the expression kinds where there are additional rules, we do not have to check the sub-expressions if the static type is a subtype of For example, in the following scenarios the static type of the expression is a subtype of
or
|
The point of an isolated expression is to ensure that the result of the expression is a guaranteed to be an isolated root and unaliased. For a result that is a subtype of So if an expression satisfies the condition in the first para (its static type is immutable, i.e. a subtype of readonly, or an isolated object, i.e. a subtype of isolated object {}), no further checking is needed: it's guaranteed to be an isolated expression. The next paragraph is giving another way in which particular expressions can be isolated. For example:
is isolated, because all the sub-expressions are (trivially) isolated. Both these examples are fine:
because an int or a string is immutable and so is automatically an isolated root. Please have a careful look at the definition of isolated root here: https://ballerina.io/spec/lang/master/#section_5.1.3 . It's the key to the whole design. |
Noted, this is clear now. |
This builds on #145 and adds
as described in the proposal.
The text was updated successfully, but these errors were encountered: