-
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
Transferring in/out a structure of isolated objects #855
Comments
Also wondering if spread fields/expressions can help to a certain extent. Using a spread field in a mapping constructor as an example (since we don't have list spread yet), if the following is allowed, I guess we can use this in the mapping case? isolated class Bar {
private map<Foo> m = {};
function getMap() returns map<Foo> {
lock {
return {...self.m};
}
}
} The implementation does not seem to allow this at the moment though. |
Relates to #52. |
There's also a related scenario when the structure has a combination of isolated objects and values that belong to I guess we can still use the spread operator if the values that belong to type Config record {|
int[] & readonly a;
IsolatedClass b;
|}; But this would not be possible if the types of the rest of the fields are not subtypes of type Config record {|
int[] a;
IsolatedClass b;
map<boolean> c;
|};
isolated class Foo {
private Config c;
isolated function init(Config con) {
self.c = con; // ERROR: RHS is not an isolated expression and cannot use `clone`/`cloneReadOnly`.
// `self.c = {...con};` can't be used because `a` and `c` are mutable.
}
} Although we can get this to work by separating out the isolated objects and the values that belong to isolated class Foo {
private Config c;
isolated function init(Config con) {
var {b, ...rest} = con;
self.c = {b, ...rest.clone()};
}
} Could be related to #784 |
Please make #855 (comment) a separate issue. |
Can we make a query expression work?
|
Created #856
The implementation seems to have inadvertently allowed this already for transferring out. If the iterable value used in the from-clause is not an invalid transfer in and |
This is allowed at the moment when we transfer out (to an array using member access) one isolated object at a time. isolated class Bar {
private Foo[] arr = [];
function getArr() returns Foo[] {
Foo[] copy = [];
lock {
foreach [int, Foo] [index, foo] in self.arr.enumerate() {
copy[index] = foo; // transfer out
}
}
return copy;
}
}
isolated class Foo {
private int i = 1;
function get() returns int {
lock {
return self.i;
}
}
function increment() {
lock {
self.i += 1;
}
}
} |
Description:
Please consider the following example.
I don't think it is currently possible to do what's required in
getArr
.Both the following are invalid.
Case I
Case II
In Case I,
clone
orcloneReadOnly
cannot be used either, sinceFoo
is not a subtype ofvalue:Cloneable
.There were some scenarios where the standard library had a similar requirement too, but they were generally able to use read-only classes. But in cases where only a field would change previously they now have to create a new object since the original value cannot be updated.
The text was updated successfully, but these errors were encountered: