@@ -3595,7 +3595,9 @@ void irgen::emitTaskCancel(IRGenFunction &IGF, llvm::Value *task) {
35953595
35963596llvm::Value *irgen::emitTaskCreate (
35973597 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) {
35993601 parentTask = IGF.Builder .CreateBitOrPointerCast (
36003602 parentTask, IGF.IGM .SwiftTaskPtrTy );
36013603 taskFunction = IGF.Builder .CreateBitOrPointerCast (
@@ -3604,18 +3606,34 @@ llvm::Value *irgen::emitTaskCreate(
36043606 // Determine the size of the async context for the closure.
36053607 ASTContext &ctx = IGF.IGM .IRGen .SIL .getASTContext ();
36063608 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+ }
36093621 CanSILFunctionType taskFunctionCanSILType =
36103622 IGF.IGM .getLoweredType (taskFunctionType).castTo <SILFunctionType>();
36113623 auto layout = getAsyncContextLayout (
3612- IGF.IGM , taskFunctionCanSILType, taskFunctionCanSILType,
3613- SubstitutionMap ());
3624+ IGF.IGM , taskFunctionCanSILType, taskFunctionCanSILType, subs);
36143625
36153626 // 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 (
36173634 IGF.IGM .getTaskCreateFuncFn (),
36183635 { flags, parentTask, taskFunction });
3636+ }
36193637 result->setDoesNotThrow ();
36203638 result->setCallingConv (IGF.IGM .SwiftCC );
36213639
0 commit comments