Skip to content

[Concurrency] Improve diagnostics for missing await #37263

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 5, 2021

Conversation

hborla
Copy link
Member

@hborla hborla commented May 5, 2021

  • Propagate async from contextual types to closure expression types in CSApply instead of using a function conversion. This allows effects checking to correctly diagnose missing await instead of incorrectly complaining that the closure doesn't support async calls.
  • Emit a tailored note when a call with a missing await is implicitly async because the declaration is isolated to an actor.

Resolves: SR-14074, rdar://73460922

@hborla hborla requested review from xedin and etcwilde May 5, 2021 00:32
@hborla
Copy link
Member Author

hborla commented May 5, 2021

@swift-ci please smoke test

@@ -207,26 +207,28 @@ extension BankAccount {
func totalBalance(including other: BankAccount) async -> Int {
//expected-error@+1{{expression is 'async' but is not marked with 'await'}}{{12-12=await }}
return balance()
+ other.balance() // expected-note{{call is 'async'}}
+ other.balance() // expected-note{{calls to instance method 'balance()' from outside of its actor context are implicitly asynchronous}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Beautiful!

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank!

// expected-error@+1{{expression is 'async' but is not marked with 'await'}}{{7-7=await }}
_ = f2() //expected-note{{call is 'async'}}
_ = f2() //expected-note{{calls to let 'f2' from outside of its actor context are implicitly asynchronous}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: calls to let ‘f2’ reads a little odd, could it be something like “calls of closure ‘f2’…”?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that let isn't great. I'm wondering if closure might be unexpected though. Do people think of unapplied function references as closures?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, hmm...I wonder if changing let to constant and var to variable would make this read nicer. calls of constant 'f2'...

Copy link
Contributor

@harlanhaskins harlanhaskins May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if there's no prior art in the diagnostics for constant to refer to lets, then maybe it's not worth introducing that...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like closure reference or a function reference depending on what we're referencing?

e.g calls to function reference 'f1' from outside...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to keep thinking about this. There are other diagnostics (even near this line in the same file, basically anything that uses DescriptiveDeclKind) that use let and it's strange to read, so it's worth updating all of them together.

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I have left a couple of comments inline.

hborla added 2 commits May 5, 2021 11:35
… the closure

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

asynchronous due to actor isolation.
@hborla hborla force-pushed the async-closure-diagnostics branch from e63d50b to b6a3434 Compare May 5, 2021 18:35
@hborla
Copy link
Member Author

hborla commented May 5, 2021

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented May 5, 2021

@swift-ci please test Windows platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants