Skip to content

Commit 37c4c9e

Browse files
committed
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 26bbc75 commit 37c4c9e

File tree

6 files changed

+2473
-17
lines changed

6 files changed

+2473
-17
lines changed

lib/IRGen/GenCall.cpp

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

33883388
// If it's formally indirect, then we should just add that pointer
33893389
// to the output.
3390-
if (schema.isFormalIndirect()) {
3390+
if (schema.isFormalIndirect() ||
3391+
!isa<LoadableTypeInfo>(schema.getTypeInfo())) {
33913392
out.add(pointer);
33923393
continue;
33933394
}
@@ -4127,6 +4128,12 @@ bool irgen::addNativeArgument(IRGenFunction &IGF,
41274128
}
41284129
auto paramType = IGF.IGM.silConv.getSILType(
41294130
origParamInfo, fnTy, IGF.IGM.getMaximalTypeExpansionContext());
4131+
4132+
if (!isa<LoadableTypeInfo>(IGF.getTypeInfo(paramType))) {
4133+
out.add(in.claimNext());
4134+
return false;
4135+
}
4136+
41304137
auto &ti = cast<LoadableTypeInfo>(IGF.getTypeInfo(paramType));
41314138
auto schema = ti.getSchema();
41324139
auto &nativeSchema = ti.nativeParameterValueSchema(IGF.IGM);

lib/IRGen/GenDecl.cpp

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

6267+
GenericContextScope scope(*this, fnType->getInvocationGenericSignature());
62676268
auto signature = Signature::forCoroutineContinuation(*this, fnType);
62686269
LinkInfo link = LinkInfo::get(*this, entity, NotForDefinition);
62696270
entry = createFunction(*this, link, signature);

0 commit comments

Comments
 (0)