Skip to content
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

Closures need to be isolated wrt a stack frame #602

Open
jclark opened this issue Sep 21, 2020 · 1 comment
Open

Closures need to be isolated wrt a stack frame #602

jclark opened this issue Sep 21, 2020 · 1 comment
Assignees
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Milestone

Comments

@jclark
Copy link
Collaborator

jclark commented Sep 21, 2020

There is a complication with closures and isolated. Consider this:

isolated function arrayInc(int[] v, int k) returns int[] {
  return v.map(n => n + k);
}

This ought to work, but the closure passed to map is not isolated, because it accesses state outside its (the closure’s) parameters, namely k. From a type-checking point of the concept needs to be isolated wrt a specific stack frame. Declaring a function isolated means that is isolated wrt its own stack frame. The closure passed to map is isolated with respect to arrayInc’s stack frame. So the call to map is isolated with respect to arrayInc’s stack frame, so it’s OK for arrayInc to call it.

This also means we ought to infer the isolatedness of anoymous functions values within a function.

Originally posted by @jclark in #145 (comment)

@jclark jclark self-assigned this Sep 21, 2020
@jclark jclark added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Sep 21, 2020
@jclark jclark added this to the Swan Lake + 1 milestone Sep 26, 2020
@jclark
Copy link
Collaborator Author

jclark commented Apr 1, 2021

How does this interact with the following from the spec?

Captured variables are restricted as follows: if the body is part of an anonymous-function-expr, then any captured variable references must refer to variables that are both final (either explicitly or implicitly) and have a static type that is a subtype of readonly|isolated object {}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

1 participant