-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Fix await fix-it placement #37056
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
Merged
Merged
Conversation
This file contains hidden or 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
Adding an expression pre-visit to the EffectHandling walker, allowing sub-classes visit all expressions.
We need to be able to traverse back to the top of expressions in order to emit the diagnostic to the right place. This patch records the parent map of the highest expression in the tree that the checker was constructed with. This will record the mapping for all sub-expressions as well.
@swift-ci please smoke test |
This patch restructures how we emit the effect errors for missing awaits. As we're traversing the expressions, we collect all of the locations where a missing await is, and metadata about the reason for the error, as well as the "anchor". The anchor is where the await should actually be placed in the expression to fix things. The error is emitted for the whole sub-expression instead of for the exact synchronization/call-site of the async function. This avoids the erroneous message for ``` _ = 32 + asyncFunc() ``` The old behaviour was to put the `await` between the `+` operator and the call to `asyncFunc()`, but this is not a valid place to put effects. Note; this issue is also present in the fix-it for `try` insertions and also needs to be fixed. Instead, the anchor points between the assignment expression and 32, labelling the whole right-side of the assignment as being the asynchronous function. We emit notes for each uncovered async point in the entire expression though, so that someone can see why the expression is async.
This patch updates all the tests to accept the new error messages. *Gack* so many things needed cleaning up.
This fixes the placement of the await fix-it inside of interpolated strings. We were putting the effect between the `\` and `(`, which doesn't exactly work out very well. I'm intentionally being relatively gentle with the casting when grabbing the body of the interpolated string. I can't think of a valid expression that doesn't result in that structure, so it's probably safe to do a straight cast, and probably should switch it over eventually. In the current state-of-affairs, it will put the fix-it placement in the wrong place if my assumptions are broken about the structure of the code.
b1c3e0a
to
e9baa3f
Compare
@swift-ci please smoke test |
@swift-ci please smoke test macOS |
ktoso
approved these changes
Apr 26, 2021
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.
Nice, looks good to me
I'm going to go ahead and merge this because updating the tests is a pain. If we need something changed, I can do that in a separate PR. |
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.
This PR does some work around the diagnostics on
await
. The first issue is that the fix-it for await put the await in the wrong place. The issue also exists for the placement oftry
. The fix-it would put theawait
immediately before the call or access, but this doesn't work if that point is immediately after a binary operation.e.g.
fails to compile, despite that being where the fix-it suggests putting it.
That gets fixed in this PR. We do this by walking up the parent to an anchor point where we want to emit the await to. By keeping those in a map, we can effectively de-dupe them and map all of the warnings back to a given anchor.
I did run into some difficulties with finding a decent anchor in string interpolated expressions (see
CheckEffectsCoverage::walkToAnchor
). If we're in a string interpolation, I've found that we make it to the top of the expression and parent becomes anullptr
. The top of the expression for a string interpolation appears to always be aCallExpr
, which you then pull out the args from to get aParenExpr
. The subExpr of that appears to be thing thing we're looking for. If this always holds true, we can remove the cascade ofif
's and just make those the appropriate casts. My concern with being too forceful is getting this assumption wrong and leading to a crashing compiler. As implemented now, it will just suggest that the await goes in a weird spot. e.g.instead of
Additionally, instead of repeatedly emitting errors for every part of the expression, we emit one error with the necessary fix-it, and emit notes for each part that is the cause for needing to put the await in the right place.
e.g.
will now emit:
Will need to eventually fix the fix-it for
try
, but given that this is new syntax, it's a bit more important to get right. Folks are probably more familiar with where a try goes by now. Maybe.Fixes: rdar://76245239