Skip to content

[5.5][Concurrency] Improve diagnostics for missing await #37281

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 2 commits into from
May 6, 2021

Conversation

hborla
Copy link
Member

@hborla hborla commented May 6, 2021

Cherry-pick of #37263

  • Explanation: Writing await on async expressions is required by the compiler. Forgetting the await is a very common mistake, and the compiler needs to provide proper guidance when await is missing on async expressions. There are two issues with missing await diagnostics:

    1. The error message was incorrect if there's a missing await inside a closure body where async 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.
    2. The compiler notes are not descriptive enough when a call is implicitly asynchronous because it's a call to an actor-isolated declaration outside the actor context. The note simply said call is async, but if you look at a synchronous actor-isolated declaration, it's not at all clear why the call to it is async.
  • 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 on main). 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 to reasync 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

hborla added 2 commits May 5, 2021 16:46
… the closure

is an argument to a 'reasync' function.
… implicitly

asynchronous due to actor isolation.
@hborla hborla requested a review from a team as a code owner May 6, 2021 01:27
@hborla
Copy link
Member Author

hborla commented May 6, 2021

@swift-ci please test

@hborla hborla added the r5.5 label May 6, 2021
@hborla hborla merged commit 4edf85a into swiftlang:release/5.5 May 6, 2021
@hborla hborla deleted the 5.5-async-closure-diagnostics branch May 6, 2021 15:23
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.5 labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants