[5.5][Concurrency] Improve diagnostics for missing await
#37281
Merged
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.
Cherry-pick of #37263
Explanation: Writing
await
onasync
expressions is required by the compiler. Forgetting theawait
is a very common mistake, and the compiler needs to provide proper guidance whenawait
is missing onasync
expressions. There are two issues with missingawait
diagnostics:await
inside a closure body whereasync
is inferred from a contextual type. The compiler instead complained that the closure does not support asynchronous calls even though it does, so the user has no idea what actually went wrong.call is async
, but if you look at a synchronous actor-isolated declaration, it's not at all clear why the call to it isasync
.Scope: This will affect anyone using the new concurrency features. Guidance via diagnostics is hugely important as people learn the new model.
SR Issue: SR-14074
Risk: Low risk.
async
was already propagated from contextual types to closure types in the case where the closure inherits the surrounding actor context (which I just realized when writing this justification, will remove the duplicated - but harmless - code in a follow-up PR onmain
). I believe the only reason why this wasn't done in the general case was because it should not be propagated to closures that are arguments toreasync
functions, which is the case in this implementation. Further, the diagnostics changes only affect invalid code.Testing: Updated the test suite to reflect improved missing
await
diagnostics in closure bodies and for calls to synchronous actor-isolated methods from outside the actor.Reviewer: @etcwilde and @xedin
Resolves: rdar://73460922, rdar://76650292