@@ -1524,7 +1524,8 @@ ManagedValue emitBuiltinCreateAsyncTask(SILGenFunction &SGF, SILLocation loc,
15241524 SubstitutionMap subs,
15251525 ArrayRef<ManagedValue> args,
15261526 SGFContext C, BuiltinValueKind kind,
1527- bool inGroup, bool withExecutor) {
1527+ bool inGroup, bool withExecutor,
1528+ bool isDiscarding) {
15281529 ASTContext &ctx = SGF.getASTContext ();
15291530
15301531 SmallVector<SILValue, 4 > builtinArgs;
@@ -1538,14 +1539,22 @@ ManagedValue emitBuiltinCreateAsyncTask(SILGenFunction &SGF, SILLocation loc,
15381539 builtinArgs.push_back (args[nextArgIdx++].forward (SGF)); // executor
15391540 }
15401541
1542+ CanType futureResultType;
15411543 // Form the metatype of the result type.
1542- CanType futureResultType =
1543- Type (MetatypeType::get (GenericTypeParamType::get (
1544- /* isParameterPack*/ false ,
1545- /* depth*/ 0 , /* index*/ 0 , SGF.getASTContext ()),
1546- MetatypeRepresentation::Thick))
1547- .subst (subs)
1548- ->getCanonicalType ();
1544+ if (isDiscarding) {
1545+ futureResultType =
1546+ Type (MetatypeType::get (TupleType::getEmpty (ctx)->getCanonicalType (),
1547+ MetatypeRepresentation::Thick))
1548+ ->getCanonicalType ();
1549+ } else {
1550+ futureResultType = Type (MetatypeType::get (GenericTypeParamType::get (
1551+ /* isParameterPack*/ false ,
1552+ /* depth*/ 0 , /* index*/ 0 ,
1553+ SGF.getASTContext ()),
1554+ MetatypeRepresentation::Thick))
1555+ .subst (subs)
1556+ ->getCanonicalType ();
1557+ }
15491558 CanType anyTypeType =
15501559 ExistentialMetatypeType::get (ctx.TheAnyType )->getCanonicalType ();
15511560 auto &anyTypeTL = SGF.getTypeLowering (anyTypeType);
@@ -1569,21 +1578,27 @@ ManagedValue emitBuiltinCreateAsyncTask(SILGenFunction &SGF, SILLocation loc,
15691578 .withThrows ()
15701579 .withRepresentation (GenericFunctionType::Representation::Swift)
15711580 .build ();
1572- auto genericSig = subs.getGenericSignature ().getCanonicalSignature ();
1573- auto genericResult =
1574- GenericTypeParamType::get (/* isParameterPack*/ false ,
1575- /* depth*/ 0 , /* index*/ 0 , SGF.getASTContext ());
1576- // <T> () async throws -> T
1577- CanType functionTy =
1578- GenericFunctionType::get (genericSig, {}, genericResult, extInfo)
1579- ->getCanonicalType ();
1580- AbstractionPattern origParam (genericSig, functionTy);
1581- CanType substParamType = functionTy.subst (subs)->getCanonicalType ();
1582- auto reabstractedFun = SGF.emitSubstToOrigValue (loc, args[nextArgIdx],
1583- origParam, substParamType);
1581+
1582+ ManagedValue entryPointFun;
1583+ if (isDiscarding) {
1584+ entryPointFun = args[nextArgIdx];
1585+ } else {
1586+ auto genericSig = subs.getGenericSignature ().getCanonicalSignature ();
1587+ auto genericResult = GenericTypeParamType::get (/* isParameterPack*/ false ,
1588+ /* depth*/ 0 , /* index*/ 0 ,
1589+ SGF.getASTContext ());
1590+ // <T> () async throws -> T
1591+ CanType functionTy =
1592+ GenericFunctionType::get (genericSig, {}, genericResult, extInfo)
1593+ ->getCanonicalType ();
1594+ AbstractionPattern origParam (genericSig, functionTy);
1595+ CanType substParamType = functionTy.subst (subs)->getCanonicalType ();
1596+ entryPointFun = SGF.emitSubstToOrigValue (loc, args[nextArgIdx], origParam,
1597+ substParamType);
1598+ }
15841599
15851600 auto function = emitFunctionArgumentForAsyncTaskEntryPoint (
1586- SGF, loc, reabstractedFun , futureResultType);
1601+ SGF, loc, entryPointFun , futureResultType);
15871602 builtinArgs.push_back (function.forward (SGF));
15881603
15891604 auto apply = SGF.B .createBuiltin (
@@ -1596,9 +1611,19 @@ ManagedValue emitBuiltinCreateAsyncTask(SILGenFunction &SGF, SILLocation loc,
15961611static ManagedValue emitBuiltinCreateAsyncTaskInGroup (
15971612 SILGenFunction &SGF, SILLocation loc, SubstitutionMap subs,
15981613 ArrayRef<ManagedValue> args, SGFContext C) {
1599- return emitBuiltinCreateAsyncTask (SGF, loc, subs, args, C,
1600- BuiltinValueKind::CreateAsyncTaskInGroup,
1601- /* inGroup=*/ true , /* withExecutor=*/ false );
1614+ return emitBuiltinCreateAsyncTask (
1615+ SGF, loc, subs, args, C, BuiltinValueKind::CreateAsyncTaskInGroup,
1616+ /* inGroup=*/ true , /* withExecutor=*/ false , /* isDiscarding=*/ false );
1617+ }
1618+
1619+ // Emit SIL for the named builtin: createAsyncDiscardingTaskInGroup.
1620+ static ManagedValue emitBuiltinCreateAsyncDiscardingTaskInGroup (
1621+ SILGenFunction &SGF, SILLocation loc, SubstitutionMap subs,
1622+ ArrayRef<ManagedValue> args, SGFContext C) {
1623+ return emitBuiltinCreateAsyncTask (
1624+ SGF, loc, subs, args, C,
1625+ BuiltinValueKind::CreateAsyncDiscardingTaskInGroup,
1626+ /* inGroup=*/ true , /* withExecutor=*/ false , /* isDiscarding=*/ true );
16021627}
16031628
16041629// Emit SIL for the named builtin: createAsyncTaskWithExecutor.
@@ -1607,7 +1632,7 @@ static ManagedValue emitBuiltinCreateAsyncTaskWithExecutor(
16071632 ArrayRef<ManagedValue> args, SGFContext C) {
16081633 return emitBuiltinCreateAsyncTask (
16091634 SGF, loc, subs, args, C, BuiltinValueKind::CreateAsyncTaskWithExecutor,
1610- /* inGroup=*/ false , /* withExecutor=*/ true );
1635+ /* inGroup=*/ false , /* withExecutor=*/ true , /* isDiscarding= */ false );
16111636}
16121637// Emit SIL for the named builtin: createAsyncTaskInGroupWithExecutor.
16131638static ManagedValue emitBuiltinCreateAsyncTaskInGroupWithExecutor (
@@ -1616,17 +1641,27 @@ static ManagedValue emitBuiltinCreateAsyncTaskInGroupWithExecutor(
16161641 return emitBuiltinCreateAsyncTask (
16171642 SGF, loc, subs, args, C,
16181643 BuiltinValueKind::CreateAsyncTaskInGroupWithExecutor,
1619- /* inGroup=*/ true , /* withExecutor=*/ true );
1644+ /* inGroup=*/ true , /* withExecutor=*/ true , /* isDiscarding=*/ false );
1645+ }
1646+
1647+ // Emit SIL for the named builtin: createAsyncTaskInGroupWithExecutor.
1648+ static ManagedValue emitBuiltinCreateAsyncDiscardingTaskInGroupWithExecutor (
1649+ SILGenFunction &SGF, SILLocation loc, SubstitutionMap subs,
1650+ ArrayRef<ManagedValue> args, SGFContext C) {
1651+ return emitBuiltinCreateAsyncTask (
1652+ SGF, loc, subs, args, C,
1653+ BuiltinValueKind::CreateAsyncTaskInGroupWithExecutor,
1654+ /* inGroup=*/ true , /* withExecutor=*/ true , /* isDiscarding=*/ true );
16201655}
16211656
16221657// Emit SIL for the named builtin: createAsyncTask.
16231658ManagedValue emitBuiltinCreateAsyncTask (SILGenFunction &SGF, SILLocation loc,
16241659 SubstitutionMap subs,
16251660 ArrayRef<ManagedValue> args,
16261661 SGFContext C) {
1627- return emitBuiltinCreateAsyncTask (SGF, loc, subs, args, C,
1628- BuiltinValueKind::CreateAsyncTask,
1629- /* inGroup=*/ false , /* withExecutor=*/ false );
1662+ return emitBuiltinCreateAsyncTask (
1663+ SGF, loc, subs, args, C, BuiltinValueKind::CreateAsyncTask,
1664+ /* inGroup=*/ false , /* withExecutor= */ false , /* isDiscarding =*/ false );
16301665}
16311666
16321667// Shared implementation of withUnsafeContinuation and
0 commit comments