-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[concurrency] SILGen: emit @asyncHandler functions. #34876
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
0f159f1
to
c0d5710
Compare
@swift-ci smoke test |
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.
Looking pretty good, thanks!
@@ -2870,7 +2874,7 @@ void ASTMangler::appendEntity(const ValueDecl *decl, StringRef EntityOp, | |||
appendOperator("Z"); | |||
} | |||
|
|||
void ASTMangler::appendEntity(const ValueDecl *decl) { | |||
void ASTMangler::appendEntity(const ValueDecl *decl, bool isAsyncHandlerBody) { |
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.
Should this bool
be a FunctionManglingKind
instead to make it clearer?
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.
I thought of that, but at the end decided to pass a "bool", because FunctionManglingKind has 3 cases.
We don't introduce a new mangling here. To distinguish the names of the original asyncHandler function and it's generated "body-function", we just mangle the body-function with an async attribute, i.e. as if it was declared as async. This change is mostly to pass information to the ASTMangler to mangle a not async function as "async".
It just calls Task.runDetatched. It's more efficient to have a non-generic compiler intrinsic than to let the compiler call the generic Task.runDetatched. The _runAsyncHandler doesn't have to be generic because the return value of the run function is defined to be Void.
… a non-generic closure argument. It fixes a crash in SILGen if Builtin.createAsyncTaskFuture is used in a non-generic context. I found this by experiment - we don't use it currently in the stdlib. But it doesn't harm to fix this.
An asyncHandler function is split into two functions: 1. The asyncHandler body function: it contains the body of the function, but is emitted as an async function. 2. The original function: it just contains _runAsyncHandler(operation: asyncHandlerBodyFunction) rdar://problem/71247879
c0d5710
to
8e03bd3
Compare
@swift-ci smoke test |
An asyncHandler function is split into two functions:
_runAsyncHandler(operation: asyncHandlerBodyFunction)
To distinguish the names of the original asyncHandler function and it's generated "body-function", the body-function name is mangled with an async attribute, i.e. as if it was declared as async.
rdar://problem/71247879