Skip to content

Commit a17de09

Browse files
committed
SILGen: Fix emitBuiltinCreateAsyncTaskFuture
We need to re-abstract the function argument. I think this should fix rdar://74957357.
1 parent 4c7059f commit a17de09

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,9 +1397,11 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture(
13971397

13981398
// Form the metatype of the result type.
13991399
CanType futureResultType =
1400-
Type(
1401-
MetatypeType::get(GenericTypeParamType::get(0, 0, SGF.getASTContext()), MetatypeRepresentation::Thick))
1402-
.subst(subs)->getCanonicalType();
1400+
Type(MetatypeType::get(
1401+
GenericTypeParamType::get(0, 0, SGF.getASTContext()),
1402+
MetatypeRepresentation::Thick))
1403+
.subst(subs)
1404+
->getCanonicalType();
14031405
CanType anyTypeType = ExistentialMetatypeType::get(
14041406
ProtocolCompositionType::get(ctx, { }, false))->getCanonicalType();
14051407
auto &anyTypeTL = SGF.getTypeLowering(anyTypeType);
@@ -1411,8 +1413,27 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture(
14111413
SGF.B.createMetatype(loc, SGF.getLoweredType(futureResultType)));
14121414
}).borrow(SGF, loc).forward(SGF);
14131415

1414-
auto function = emitFunctionArgumentForAsyncTaskEntryPoint(SGF, loc, args[2],
1415-
futureResultType);
1416+
// Ensure that the closure has the appropriate type.
1417+
auto extInfo =
1418+
ASTExtInfoBuilder()
1419+
.withAsync()
1420+
.withThrows()
1421+
.withRepresentation(GenericFunctionType::Representation::Swift)
1422+
.build();
1423+
auto genericSig = subs.getGenericSignature().getCanonicalSignature();
1424+
auto genericResult = GenericTypeParamType::get(0, 0, ctx);
1425+
// <T> () async throws -> T
1426+
CanType functionTy =
1427+
GenericFunctionType::get(genericSig, {}, genericResult, extInfo)
1428+
->getCanonicalType();
1429+
AbstractionPattern origParam(genericSig, functionTy);
1430+
CanType substParamType = functionTy.subst(subs)->getCanonicalType();
1431+
auto reabstractedFun =
1432+
SGF.emitSubstToOrigValue(loc, args[2], origParam, substParamType);
1433+
1434+
auto function = emitFunctionArgumentForAsyncTaskEntryPoint(
1435+
SGF, loc, reabstractedFun, futureResultType);
1436+
14161437
auto apply = SGF.B.createBuiltin(
14171438
loc,
14181439
ctx.getIdentifier(

stdlib/public/Concurrency/Task.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,7 @@ extension Task {
487487
flags.isFuture = true
488488

489489
// Create the asynchronous task future.
490-
// FIXME: This should be an empty closure instead. Returning `0` here is
491-
// a workaround for rdar://74957357
492-
let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, nil, { return 0 })
490+
let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, nil, {})
493491

494492
// Enqueue the resulting job.
495493
_enqueueJobGlobalWithDelay(duration, Builtin.convertTaskToJob(task))

0 commit comments

Comments
 (0)