@@ -3600,8 +3600,6 @@ llvm::Value *irgen::emitTaskCreate(
3600
3600
SubstitutionMap subs) {
3601
3601
parentTask = IGF.Builder .CreateBitOrPointerCast (
3602
3602
parentTask, IGF.IGM .SwiftTaskPtrTy );
3603
- taskFunction = IGF.Builder .CreateBitOrPointerCast (
3604
- taskFunction, IGF.IGM .AsyncFunctionPointerPtrTy );
3605
3603
3606
3604
// Determine the size of the async context for the closure.
3607
3605
ASTContext &ctx = IGF.IGM .IRGen .SIL .getASTContext ();
@@ -3625,29 +3623,36 @@ llvm::Value *irgen::emitTaskCreate(
3625
3623
3626
3624
// Call the function.
3627
3625
llvm::CallInst *result;
3626
+ llvm::Value *theSize, *theFunction;
3627
+ std::tie (theFunction, theSize) =
3628
+ getAsyncFunctionAndSize (IGF, SILFunctionTypeRepresentation::Thick,
3629
+ FunctionPointer::forExplosionValue (
3630
+ IGF, taskFunction, taskFunctionCanSILType),
3631
+ localContextInfo);
3632
+ theFunction = IGF.Builder .CreateBitOrPointerCast (
3633
+ theFunction, IGF.IGM .TaskContinuationFunctionPtrTy );
3634
+ theSize = IGF.Builder .CreateZExtOrBitCast (theSize, IGF.IGM .SizeTy );
3628
3635
if (futureResultType) {
3629
3636
result = IGF.Builder .CreateCall (
3630
3637
IGF.IGM .getTaskCreateFutureFuncFn (),
3631
- { flags, parentTask, futureResultType, taskFunction });
3638
+ { flags, parentTask, futureResultType, theFunction, theSize });
3632
3639
} else {
3633
- result = IGF.Builder .CreateCall (
3634
- IGF.IGM .getTaskCreateFuncFn (),
3635
- { flags, parentTask, taskFunction });
3640
+ result = IGF.Builder .CreateCall (IGF.IGM .getTaskCreateFuncFn (),
3641
+ {flags, parentTask, theFunction, theSize});
3636
3642
}
3637
3643
result->setDoesNotThrow ();
3638
3644
result->setCallingConv (IGF.IGM .SwiftCC );
3639
3645
3640
3646
// Write the local context information into the initial context for the task.
3641
- if (layout.hasLocalContext ()) {
3642
- // Dig out the initial context returned from task creation.
3643
- auto initialContext = IGF.Builder .CreateExtractValue (result, { 1 });
3644
- Address initialContextAddr = layout.emitCastTo (IGF, initialContext);
3645
-
3646
- auto localContextLayout = layout.getLocalContextLayout ();
3647
- auto localContextAddr = localContextLayout.project (
3648
- IGF, initialContextAddr, llvm::None);
3649
- IGF.Builder .CreateStore (localContextInfo, localContextAddr);
3650
- }
3647
+ assert (layout.hasLocalContext ());
3648
+ // Dig out the initial context returned from task creation.
3649
+ auto initialContext = IGF.Builder .CreateExtractValue (result, {1 });
3650
+ Address initialContextAddr = layout.emitCastTo (IGF, initialContext);
3651
+
3652
+ auto localContextLayout = layout.getLocalContextLayout ();
3653
+ auto localContextAddr =
3654
+ localContextLayout.project (IGF, initialContextAddr, llvm::None);
3655
+ IGF.Builder .CreateStore (localContextInfo, localContextAddr);
3651
3656
3652
3657
return result;
3653
3658
}
0 commit comments