-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Sema: Make @concurrent
not imply async
on closures
#83094
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
Conversation
@swift-ci please smoke test macOS |
_ = { @concurrent () -> Int in } | ||
// expected-error@-1:9 {{cannot use @concurrent on non-async closure}}{{none}} | ||
_ = { @concurrent () async in } | ||
_ = { @concurrent in await awaitMe() } |
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.
Presence of throws
precludes effect inference from the body, might be good to add a test case where we have @concurrent
+ throws
without async, to make sure that everything works as expected.
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.
Added.
@swift-ci please smoke test |
The present approach is not prudent because `@concurrent` synchronous functions, a natural extension, are a likely-to-happen future direction, whereas the current inference rule is entirely grounded on `@concurrent` being exclusive to async functions. If we were to ship this rule, we would have to keep the promise for backwards compatibility when implementing the aforementioned future direction, replacing one inconsistency with another, and possibly introducing new bug-prone expression checking code. ```swift func foo(_: () -> Void) {} func foo(_: () async -> Void) {} // In a future without this change and `@concurrent` synchronous // functions accepted, the first call resolves to the first overload, // and the second call resolves to the second, despite `@concurrent` no // longer implying `async`. foo { } foo { @Concurrent in } ``` This change also drops the fix-it for removing `@concurrent` when used on a synchronous closure. With the inference rule gone, and the diagnosis delayed until after solution application, this error raises a fairly balanced choice between removing the attribute and being explicit about the effect, where a unilateral suggestion is quite possibly more harmful than useful.
@swift-ci please smoke test |
@swift-ci please test source compatibility |
@AnthonyLatsis if you have a spare moment, i'm curious if you could share what your current mental model for such a construct is. what would an |
Think of a synchronous actor-isolated function. Similarly, a |
The present approach is not prudent because
@concurrent
synchronous functions, a natural extension, are a likely-to-happen future direction, whereas the current inference rule is entirely grounded on@concurrent
being exclusive to async functions.If we were to ship this rule, we would have to keep the promise for backwards compatibility when implementing the aforementioned future direction, replacing one inconsistency with another, and possibly introducing new bug-prone expression checking code.
This change also drops the fix-it for removing
@concurrent
when used on a synchronous closure. With the inference rule gone, and the diagnosis delayed until after solution application, this error raises a fairly balanced choice between removing the attribute and being explicit about the effect, where a unilateral suggestion is quite possibly more harmful than useful.