Skip to content

Commit 6721626

Browse files
asavonicasl
authored andcommitted
Partial apply for coroutines
The patch adds lowering of partial_apply instructions for coroutines. This pattern seems to trigger a lot of type mismatch errors in IRGen, because coroutine functions are not substituted in the same way as regular functions (see the patch 07f03bd "Use pattern substitutions to consistently abstract yields" for more details). The odd type conversions in the patch are related to this issue, and these should be checked carefully. Perhaps it is better to enable substitutions for coroutine functions instead (at least for some cases). Other than that, lowering of partial_apply for coroutines is straightforward: we generate another coroutine that captures arguments passed to the partial_apply instructions. It calls the original coroutine for yields (first return) and yields the resulting values. Then it calls the original function's continuation for return or unwind, and forwards them to the caller as well. After IRGen, LLVM's Coroutine pass transforms the generated coroutine (along with all other coroutines) and eliminates llvm.coro.* intrinsics. LIT tests check LLVM IR after this transformation.
1 parent 1d13493 commit 6721626

File tree

6 files changed

+2461
-17
lines changed

6 files changed

+2461
-17
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3424,7 +3424,8 @@ void CallEmission::emitYieldsToExplosion(Explosion &out) {
34243424

34253425
// If it's formally indirect, then we should just add that pointer
34263426
// to the output.
3427-
if (schema.isFormalIndirect()) {
3427+
if (schema.isFormalIndirect() ||
3428+
!isa<LoadableTypeInfo>(schema.getTypeInfo())) {
34283429
out.add(pointer);
34293430
continue;
34303431
}
@@ -4166,6 +4167,12 @@ bool irgen::addNativeArgument(IRGenFunction &IGF,
41664167
}
41674168
auto paramType = IGF.IGM.silConv.getSILType(
41684169
origParamInfo, fnTy, IGF.IGM.getMaximalTypeExpansionContext());
4170+
4171+
if (!isa<LoadableTypeInfo>(IGF.getTypeInfo(paramType))) {
4172+
out.add(in.claimNext());
4173+
return false;
4174+
}
4175+
41694176
auto &ti = cast<LoadableTypeInfo>(IGF.getTypeInfo(paramType));
41704177
auto schema = ti.getSchema();
41714178
auto &nativeSchema = ti.nativeParameterValueSchema(IGF.IGM);

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6241,6 +6241,7 @@ IRGenModule::getAddrOfContinuationPrototype(CanSILFunctionType fnType) {
62416241
llvm::Function *&entry = GlobalFuncs[entity];
62426242
if (entry) return entry;
62436243

6244+
GenericContextScope scope(*this, fnType->getInvocationGenericSignature());
62446245
auto signature = Signature::forCoroutineContinuation(*this, fnType);
62456246
LinkInfo link = LinkInfo::get(*this, entity, NotForDefinition);
62466247
entry = createFunction(*this, link, signature);

0 commit comments

Comments
 (0)