@@ -3767,86 +3767,24 @@ llvm::Value *irgen::emitTaskCreate(
3767
3767
parentTask = IGF.Builder .CreateBitOrPointerCast (
3768
3768
parentTask, IGF.IGM .SwiftTaskPtrTy );
3769
3769
3770
- // Determine the size of the async context for the closure.
3771
- ASTContext &ctx = IGF.IGM .IRGen .SIL .getASTContext ();
3772
- auto extInfo = ASTExtInfoBuilder ().withAsync ().withThrows ().build ();
3773
- CanSILFunctionType taskFunctionType;
3774
- CanSILFunctionType substTaskFunctionType;
3775
- if (futureResultType) {
3776
- auto genericParam = GenericTypeParamType::get (0 , 0 , ctx);
3777
- auto genericSig = GenericSignature::get ({genericParam}, {});
3778
- auto *ty = GenericFunctionType::get (genericSig, { }, genericParam, extInfo);
3779
-
3780
- taskFunctionType = IGF.IGM .getLoweredType (ty).castTo <SILFunctionType>();
3781
- substTaskFunctionType = taskFunctionType->withInvocationSubstitutions (subs);
3782
- } else {
3783
- auto *ty = FunctionType::get ({ }, ctx.TheEmptyTupleType , extInfo);
3784
- taskFunctionType = IGF.IGM .getLoweredType (ty).castTo <SILFunctionType>();
3785
- substTaskFunctionType = taskFunctionType;
3786
- }
3787
- auto layout = getAsyncContextLayout (
3788
- IGF.IGM , taskFunctionType, substTaskFunctionType, subs,
3789
- /* suppress generics*/ false );
3790
-
3791
- CanSILFunctionType taskContinuationFunctionTy = [&]() {
3792
- ASTContext &ctx = IGF.IGM .IRGen .SIL .getASTContext ();
3793
- auto extInfo =
3794
- ASTExtInfoBuilder ()
3795
- .withRepresentation (FunctionTypeRepresentation::CFunctionPointer)
3796
- .build ();
3797
- // FIXME: Use the appropriate signature for TaskContinuationFunction:
3798
- //
3799
- // using TaskContinuationFunction =
3800
- // SWIFT_CC(swift)
3801
- // void (AsyncTask *, ExecutorRef, AsyncContext *);
3802
- auto ty = FunctionType::get ({}, ctx.TheEmptyTupleType , extInfo);
3803
- return IGF.IGM .getLoweredType (ty).castTo <SILFunctionType>();
3804
- }();
3805
-
3806
- // Call the function.
3807
3770
llvm::CallInst *result;
3808
- llvm::Value *theSize, *theFunction;
3809
- auto taskFunctionPointer = FunctionPointer::forExplosionValue (
3810
- IGF, taskFunction, substTaskFunctionType);
3811
- std::tie (theFunction, theSize) =
3812
- getAsyncFunctionAndSize (IGF, SILFunctionTypeRepresentation::Thick,
3813
- taskFunctionPointer, localContextInfo);
3814
- if (auto authInfo = PointerAuthInfo::forFunctionPointer (
3815
- IGF.IGM , taskContinuationFunctionTy)) {
3816
- theFunction = emitPointerAuthResign (
3817
- IGF, theFunction, taskFunctionPointer.getAuthInfo (), authInfo);
3818
- }
3819
- theFunction = IGF.Builder .CreateBitOrPointerCast (
3820
- theFunction, IGF.IGM .TaskContinuationFunctionPtrTy );
3821
- theSize = IGF.Builder .CreateZExtOrBitCast (theSize, IGF.IGM .SizeTy );
3822
3771
if (taskGroup && futureResultType) {
3823
3772
taskGroup = IGF.Builder .CreateBitOrPointerCast (
3824
3773
taskGroup, IGF.IGM .SwiftTaskGroupPtrTy );
3825
3774
result = IGF.Builder .CreateCall (
3826
- IGF.IGM .getTaskCreateGroupFutureFuncFn (),
3827
- {flags, parentTask, taskGroup, futureResultType, theFunction, theSize});
3775
+ IGF.IGM .getTaskCreateGroupFutureFn (),
3776
+ {flags, parentTask, taskGroup, futureResultType,
3777
+ taskFunction, localContextInfo});
3828
3778
} else if (futureResultType) {
3829
3779
result = IGF.Builder .CreateCall (
3830
- IGF.IGM .getTaskCreateFutureFuncFn (),
3831
- { flags, parentTask, futureResultType, theFunction, theSize });
3780
+ IGF.IGM .getTaskCreateFutureFn (),
3781
+ {flags, parentTask, futureResultType, taskFunction, localContextInfo });
3832
3782
} else {
3833
- result = IGF.Builder .CreateCall (IGF.IGM .getTaskCreateFuncFn (),
3834
- {flags, parentTask, theFunction, theSize});
3783
+ llvm_unreachable (" no future?!" );
3835
3784
}
3836
3785
result->setDoesNotThrow ();
3837
3786
result->setCallingConv (IGF.IGM .SwiftCC );
3838
3787
3839
- // Write the local context information into the initial context for the task.
3840
- assert (layout.hasLocalContext ());
3841
- // Dig out the initial context returned from task creation.
3842
- auto initialContext = IGF.Builder .CreateExtractValue (result, {1 });
3843
- Address initialContextAddr = layout.emitCastTo (IGF, initialContext);
3844
-
3845
- auto localContextLayout = layout.getLocalContextLayout ();
3846
- auto localContextAddr =
3847
- localContextLayout.project (IGF, initialContextAddr, llvm::None);
3848
- IGF.Builder .CreateStore (localContextInfo, localContextAddr);
3849
-
3850
3788
return result;
3851
3789
}
3852
3790
0 commit comments