-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Fix async-main crash #36201
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
[Concurrency] Fix async-main crash #36201
Conversation
@swift-ci please smoke test |
@swift-ci please smoke test macOS |
@swift-ci please smoke test windows platform |
@@ -1831,6 +1831,18 @@ synthesizeMainBody(AbstractFunctionDecl *fn, void *arg) { | |||
Expr *returnedExpr; | |||
|
|||
if (mainFunction->hasAsync()) { | |||
if (!context.LangOpts.EnableExperimentalConcurrency) { | |||
context.Diags.diagnose(mainFunction->getAsyncLoc(), |
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.
We may want a comment relating how this fixes the crash because _Concurrency
implicitly gets imported when -enable-experimental-concurrency
is passed in, but doesn't when it's not. If that changes, the crash comes back.
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.
It'll work the way it is now, but how about checking for !concurrencyModule
below instead of -enable-experimental-concurrency
? That would avoid the crash if the module doesn't get loaded for any reason.
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.
Okay, now checks against the concurrency module. Also added a test passing both -enable-experimental-concurrency
and -parse-stdlib
since that won't implicitly import _Concurrency
either.
@swift-ci please smoke test Windows |
1 similar comment
@swift-ci please smoke test Windows |
@swift-ci please smoke test windows |
1 similar comment
@swift-ci please smoke test windows |
@@ -1831,6 +1831,18 @@ synthesizeMainBody(AbstractFunctionDecl *fn, void *arg) { | |||
Expr *returnedExpr; | |||
|
|||
if (mainFunction->hasAsync()) { | |||
if (!context.LangOpts.EnableExperimentalConcurrency) { | |||
context.Diags.diagnose(mainFunction->getAsyncLoc(), |
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.
It'll work the way it is now, but how about checking for !concurrencyModule
below instead of -enable-experimental-concurrency
? That would avoid the crash if the module doesn't get loaded for any reason.
The concurrency module gets imported implicitly when `-enable-experimental-concurrency` is passed to the compiler. If the concurrency module isn't imported, we crash on th assert verifying that we were able to find it. We need the module to lookup the `_runAsyncMain` function. This patch updates the compiler to stop type-checking the async-main function and emit an error if the module isn't available instead of crashing.
This patch adds a quick test to verify that we emit a reasonable error message when trying to use async-main without enabling concurrency or parsing as stdlib instead of crashing. Under both circumstances, the _Concurrency library won't be implicitly imported.
42a5ef2
to
6d18260
Compare
@swift-ci please smoke test |
The compiler would assert/crash if someone tried to use async-main without enabling concurrency since it would fail to find the concurrency module.
import _Concurrency
in the source file would also work, but is kind of gross.I've decided to go down the route of just protecting the feature behind a check for enabling concurrency. Once we have, the concurrency module is imported implicitly, and we avoid the crash. Alternatively, we could just recommend that folks import the concurrency module.
Fixes rdar://74821680