@@ -3595,7 +3595,9 @@ void irgen::emitTaskCancel(IRGenFunction &IGF, llvm::Value *task) {
3595
3595
3596
3596
llvm::Value *irgen::emitTaskCreate (
3597
3597
IRGenFunction &IGF, llvm::Value *flags, llvm::Value *parentTask,
3598
- llvm::Value *taskFunction, llvm::Value *localContextInfo) {
3598
+ llvm::Value *futureResultType,
3599
+ llvm::Value *taskFunction, llvm::Value *localContextInfo,
3600
+ SubstitutionMap subs) {
3599
3601
parentTask = IGF.Builder .CreateBitOrPointerCast (
3600
3602
parentTask, IGF.IGM .SwiftTaskPtrTy );
3601
3603
taskFunction = IGF.Builder .CreateBitOrPointerCast (
@@ -3604,18 +3606,34 @@ llvm::Value *irgen::emitTaskCreate(
3604
3606
// Determine the size of the async context for the closure.
3605
3607
ASTContext &ctx = IGF.IGM .IRGen .SIL .getASTContext ();
3606
3608
auto extInfo = ASTExtInfoBuilder ().withAsync ().withThrows ().build ();
3607
- auto taskFunctionType = FunctionType::get (
3608
- { }, ctx.TheEmptyTupleType , extInfo);
3609
+ AnyFunctionType *taskFunctionType;
3610
+ if (futureResultType) {
3611
+ auto genericParam = GenericTypeParamType::get (0 , 0 , ctx);
3612
+ auto genericSig = GenericSignature::get ({genericParam}, {});
3613
+ taskFunctionType = GenericFunctionType::get (
3614
+ genericSig, { }, genericParam, extInfo);
3615
+
3616
+ taskFunctionType = Type (taskFunctionType).subst (subs)->castTo <FunctionType>();
3617
+ } else {
3618
+ taskFunctionType = FunctionType::get (
3619
+ { }, ctx.TheEmptyTupleType , extInfo);
3620
+ }
3609
3621
CanSILFunctionType taskFunctionCanSILType =
3610
3622
IGF.IGM .getLoweredType (taskFunctionType).castTo <SILFunctionType>();
3611
3623
auto layout = getAsyncContextLayout (
3612
- IGF.IGM , taskFunctionCanSILType, taskFunctionCanSILType,
3613
- SubstitutionMap ());
3624
+ IGF.IGM , taskFunctionCanSILType, taskFunctionCanSILType, subs);
3614
3625
3615
3626
// Call the function.
3616
- auto *result = IGF.Builder .CreateCall (
3627
+ llvm::CallInst *result;
3628
+ if (futureResultType) {
3629
+ result = IGF.Builder .CreateCall (
3630
+ IGF.IGM .getTaskCreateFutureFuncFn (),
3631
+ { flags, parentTask, futureResultType, taskFunction });
3632
+ } else {
3633
+ result = IGF.Builder .CreateCall (
3617
3634
IGF.IGM .getTaskCreateFuncFn (),
3618
3635
{ flags, parentTask, taskFunction });
3636
+ }
3619
3637
result->setDoesNotThrow ();
3620
3638
result->setCallingConv (IGF.IGM .SwiftCC );
3621
3639
0 commit comments