-
Notifications
You must be signed in to change notification settings - Fork 200
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
feat(compiler): minimal capturing from inflight methods #1682
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Analyze inflight methods to identify exactly which fields are being referenced and which operations are performed on them. TODO: - [ ] Check that referenced fields are capturable
eladb
commented
Mar 1, 2023
eladb
changed the title
feat(compiler): infer inflight field references
feat(compiler): identify operations when capturing fields from inflight methods
Mar 1, 2023
eladb
changed the title
feat(compiler): identify operations when capturing fields from inflight methods
feat(compiler): minimal capturing from inflight methods
Mar 1, 2023
Chriscbr
reviewed
Mar 1, 2023
|
||
inflight test() { | ||
let res = this.another.func(); | ||
this.another.my_queue.push("message"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment to the code? (It seems like this should be valid, no?)
Signed-off-by: mutator <[email protected]>
Signed-off-by: mutator <[email protected]>
@yoav-steinberg this is ready for another round |
eladb
commented
Mar 5, 2023
Chriscbr
reviewed
Mar 6, 2023
Chriscbr
reviewed
Mar 6, 2023
yoav-steinberg
approved these changes
Mar 6, 2023
Congrats! 🚀 This was released in Wing 0.5.100. |
mergify bot
pushed a commit
that referenced
this pull request
Mar 15, 2023
Following up on #1682 to identify cases where we cannot infer which operations are performed on a captured resource. See positive/negative tests for examples. Rewrite the algorithm which analyzes the expressions captured by inflight methods so that it is able to identify more cases and emit errors when captures cannot be qualified (i.e. a resource is captured but we cannot determine which operations are performed on it without static analysis). For each method, we identify all expressions that start with `this.xxx` and break them down into parts (using nested references). Then, we traverse the list of parts and split the expression into *preflight* and *inflight*. The preflight part is what we are capturing and the first inflight component qualifies which operations are performed on the captured object. Reorganized capture tests into `resource_captures` (both under valid and invalid). This does not address #76 but it explicitly identifies these cases. We will follow up at some point with a way to allow users to explicitly qualify the reference. *By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Analyze inflight methods to identify exactly which fields are being referenced and which operations are performed on them. Previously, we assumed all inflight methods access all fields across all their inflight operations.
Implementation notes
This is currently implemented during jsification. The function
find_inflight_references()
iterates over all methods in a resource. For each method it uses aFieldReferenceVisitor
to analyze the method and identify all references tothis.xxx
.In some cases we will only fail at runtime. For example see
inflight_ref_resource_collection.w
andinflight_ref_unknown_op.w
are both supposed to fail and require that explicit annotations are added. This will be handled as part of #1610.The
JSifier
now maintains adiagnostics
list so it will be possible to report errors (this turned it into a mutable creature).We still want to bail out before jsification if there are any errors in previous phases because otherwise, the jsifier cannot infer certain types, etc.
Tests are prefixed with
inflight_ref_*
(both valid and invalid).Co-author: @yoav-steinberg
By submitting this pull request, I confirm that my contribution is made under the terms of the Monada Contribution License.