Skip to content

Commit f24ddb0

Browse files
Merge pull request #34444 from nate-chandler/concurrency/irgen/add-remaining-async-args-as-null
[Async CC] Add task and executor arguments.
2 parents 0991d8d + b74052c commit f24ddb0

File tree

39 files changed

+120
-101
lines changed

39 files changed

+120
-101
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,12 @@ void SignatureExpansion::expandCoroutineContinuationParameters() {
690690
}
691691

692692
void SignatureExpansion::addAsyncParameters() {
693+
// using TaskContinuationFunction =
694+
// SWIFT_CC(swift)
695+
// void (AsyncTask *, ExecutorRef, AsyncContext *);
696+
ParamIRTypes.push_back(IGM.SwiftTaskPtrTy);
697+
ParamIRTypes.push_back(IGM.SwiftExecutorPtrTy);
693698
ParamIRTypes.push_back(IGM.SwiftContextPtrTy);
694-
// TODO: Add actor.
695-
// TODO: Add task.
696699
if (FnType->getRepresentation() == SILFunctionTypeRepresentation::Thick) {
697700
IGM.addSwiftSelfAttributes(Attrs, ParamIRTypes.size());
698701
ParamIRTypes.push_back(IGM.RefCountedPtrTy);
@@ -2141,6 +2144,9 @@ class AsyncCallEmission final : public CallEmission {
21412144
void setArgs(Explosion &llArgs, bool isOutlined,
21422145
WitnessMetadata *witnessMetadata) override {
21432146
Explosion asyncExplosion;
2147+
asyncExplosion.add(llvm::Constant::getNullValue(IGF.IGM.SwiftTaskPtrTy));
2148+
asyncExplosion.add(
2149+
llvm::Constant::getNullValue(IGF.IGM.SwiftExecutorPtrTy));
21442150
asyncExplosion.add(contextBuffer.getAddress());
21452151
if (getCallee().getRepresentation() ==
21462152
SILFunctionTypeRepresentation::Thick) {

lib/IRGen/GenFunc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,8 @@ class AsyncPartialApplicationForwarderEmission
10141014
: public PartialApplicationForwarderEmission {
10151015
using super = PartialApplicationForwarderEmission;
10161016
AsyncContextLayout layout;
1017+
llvm::Value *task;
1018+
llvm::Value *executor;
10171019
llvm::Value *contextBuffer;
10181020
Size contextSize;
10191021
Address context;
@@ -1067,6 +1069,8 @@ class AsyncPartialApplicationForwarderEmission
10671069
substType, outType, subs, layout, conventions),
10681070
layout(getAsyncContextLayout(subIGF, origType, substType, subs)),
10691071
currentArgumentIndex(outType->getNumParameters()) {
1072+
task = origParams.claimNext();
1073+
executor = origParams.claimNext();
10701074
contextBuffer = origParams.claimNext();
10711075
heapContextBuffer = origParams.claimNext();
10721076
}
@@ -1223,6 +1227,9 @@ class AsyncPartialApplicationForwarderEmission
12231227
}
12241228
llvm::CallInst *createCall(FunctionPointer &fnPtr) override {
12251229
Explosion asyncExplosion;
1230+
asyncExplosion.add(llvm::Constant::getNullValue(subIGF.IGM.SwiftTaskPtrTy));
1231+
asyncExplosion.add(
1232+
llvm::Constant::getNullValue(subIGF.IGM.SwiftExecutorPtrTy));
12261233
asyncExplosion.add(contextBuffer);
12271234
if (dynamicFunction &&
12281235
dynamicFunction->kind == DynamicFunction::Kind::PartialApply) {

lib/IRGen/IRGenModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,10 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
589589

590590
SwiftContextTy = createStructType(*this, "swift.context", {});
591591
SwiftTaskTy = createStructType(*this, "swift.task", {});
592+
SwiftExecutorTy = createStructType(*this, "swift.executor", {});
592593
SwiftContextPtrTy = SwiftContextTy->getPointerTo(DefaultAS);
593594
SwiftTaskPtrTy = SwiftTaskTy->getPointerTo(DefaultAS);
595+
SwiftExecutorPtrTy = SwiftExecutorTy->getPointerTo(DefaultAS);
594596

595597
DifferentiabilityWitnessTy = createStructType(
596598
*this, "swift.differentiability_witness", {Int8PtrTy, Int8PtrTy});

lib/IRGen/IRGenModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,10 @@ class IRGenModule {
725725

726726
llvm::StructType *SwiftContextTy;
727727
llvm::StructType *SwiftTaskTy;
728+
llvm::StructType *SwiftExecutorTy;
728729
llvm::PointerType *SwiftContextPtrTy;
729730
llvm::PointerType *SwiftTaskPtrTy;
731+
llvm::PointerType *SwiftExecutorPtrTy;
730732

731733
llvm::StructType *DifferentiabilityWitnessTy; // { i8*, i8* }
732734

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,8 @@ class SyncNativeCCEntryPointArgumentEmission final
12311231
class AsyncNativeCCEntryPointArgumentEmission final
12321232
: public NativeCCEntryPointArgumentEmission,
12331233
public AsyncEntryPointArgumentEmission {
1234+
llvm::Value *task;
1235+
llvm::Value *executor;
12341236
llvm::Value *context;
12351237
/*const*/ AsyncContextLayout layout;
12361238
const Address dataAddr;
@@ -1253,6 +1255,7 @@ class AsyncNativeCCEntryPointArgumentEmission final
12531255
SILBasicBlock &entry,
12541256
Explosion &allParamValues)
12551257
: AsyncEntryPointArgumentEmission(IGF, entry, allParamValues),
1258+
task(allParamValues.claimNext()), executor(allParamValues.claimNext()),
12561259
context(allParamValues.claimNext()), layout(getAsyncContextLayout(IGF)),
12571260
dataAddr(layout.emitCastTo(IGF, context)){};
12581261

@@ -3176,8 +3179,7 @@ static void emitReturnInst(IRGenSILFunction &IGF,
31763179
assert(!IGF.IndirectReturn.isValid() &&
31773180
"Formally direct results should stay direct results for async "
31783181
"functions");
3179-
Explosion parameters = IGF.collectParameters();
3180-
llvm::Value *context = parameters.claimNext();
3182+
llvm::Value *context = IGF.CurFn->getArg(2);
31813183
auto layout = getAsyncContextLayout(IGF);
31823184

31833185
Address dataAddr = layout.emitCastTo(IGF, context);

0 commit comments

Comments
 (0)