Skip to content

partial_apply support for coroutines #71653

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 12 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ the ``@yields`` attribute. A yielded value may have a convention attribute,
taken from the set of parameter attributes and interpreted as if the yield
site were calling back to the calling function.

Currently, a coroutine may not have normal results.
In addition to yielded values a coroutine could also have normal results.

Coroutine functions may be used in many of the same ways as normal
function values. However, they cannot be called with the standard
Expand Down Expand Up @@ -6330,6 +6330,16 @@ callee function (and thus said signature). Instead:
``@inout_aliasable`` parameter convention is used when a ``@noescape``
closure captures an ``inout`` argument.

**Coroutines** ``partial_apply`` could be used to create closures over
coroutines. Overall, the ``partial_apply`` of a coroutine is straightforward: it
is another coroutine that captures arguments passed to the ``partial_apply``
instruction. This closure applies the original coroutine (similar to the
``begin_apply`` instruction) for yields (suspend) and yields the resulting
values. Then it calls the original coroutine continuation for return or unwind,
and forwards the results (if any) to the caller as well. Currently only the
autodiff transformation produces ``partial_apply`` for coroutines while
differentiating modify accessors.

**NOTE:** If the callee is generic, all of its generic parameters must be bound
by the given substitution list. The arguments are given with these generic
substitutions applied, and the resulting closure is of concrete function type
Expand Down
1 change: 1 addition & 0 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6163,6 +6163,7 @@ IRGenModule::getAddrOfContinuationPrototype(CanSILFunctionType fnType) {
llvm::Function *&entry = GlobalFuncs[entity];
if (entry) return entry;

GenericContextScope scope(*this, fnType->getInvocationGenericSignature());
auto signature = Signature::forCoroutineContinuation(*this, fnType);
LinkInfo link = LinkInfo::get(*this, entity, NotForDefinition);
entry = createFunction(*this, link, signature);
Expand Down
Loading