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