Skip to content

Commit f694cfb

Browse files
authored
Merge pull request swiftlang#35139 from eeckstein/fix-create-task
[Concurrency] IRGen: correct substitution for the createAsyncTaskFuture builtin.
2 parents fcb2e77 + 29543d4 commit f694cfb

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,22 +3664,22 @@ llvm::Value *irgen::emitTaskCreate(
36643664
// Determine the size of the async context for the closure.
36653665
ASTContext &ctx = IGF.IGM.IRGen.SIL.getASTContext();
36663666
auto extInfo = ASTExtInfoBuilder().withAsync().withThrows().build();
3667-
AnyFunctionType *taskFunctionType;
3667+
CanSILFunctionType taskFunctionType;
3668+
CanSILFunctionType substTaskFunctionType;
36683669
if (futureResultType) {
36693670
auto genericParam = GenericTypeParamType::get(0, 0, ctx);
36703671
auto genericSig = GenericSignature::get({genericParam}, {});
3671-
taskFunctionType = GenericFunctionType::get(
3672-
genericSig, { }, genericParam, extInfo);
3672+
auto *ty = GenericFunctionType::get(genericSig, { }, genericParam, extInfo);
36733673

3674-
taskFunctionType = Type(taskFunctionType).subst(subs)->castTo<FunctionType>();
3674+
taskFunctionType = IGF.IGM.getLoweredType(ty).castTo<SILFunctionType>();
3675+
substTaskFunctionType = taskFunctionType->withInvocationSubstitutions(subs);
36753676
} else {
3676-
taskFunctionType = FunctionType::get(
3677-
{ }, ctx.TheEmptyTupleType, extInfo);
3677+
auto *ty = FunctionType::get({ }, ctx.TheEmptyTupleType, extInfo);
3678+
taskFunctionType = IGF.IGM.getLoweredType(ty).castTo<SILFunctionType>();
3679+
substTaskFunctionType = taskFunctionType;
36783680
}
3679-
CanSILFunctionType taskFunctionCanSILType =
3680-
IGF.IGM.getLoweredType(taskFunctionType).castTo<SILFunctionType>();
36813681
auto layout = getAsyncContextLayout(
3682-
IGF.IGM, taskFunctionCanSILType, taskFunctionCanSILType, subs);
3682+
IGF.IGM, taskFunctionType, substTaskFunctionType, subs);
36833683

36843684
CanSILFunctionType taskContinuationFunctionTy = [&]() {
36853685
ASTContext &ctx = IGF.IGM.IRGen.SIL.getASTContext();
@@ -3700,7 +3700,7 @@ llvm::Value *irgen::emitTaskCreate(
37003700
llvm::CallInst *result;
37013701
llvm::Value *theSize, *theFunction;
37023702
auto taskFunctionPointer = FunctionPointer::forExplosionValue(
3703-
IGF, taskFunction, taskFunctionCanSILType);
3703+
IGF, taskFunction, substTaskFunctionType);
37043704
std::tie(theFunction, theSize) =
37053705
getAsyncFunctionAndSize(IGF, SILFunctionTypeRepresentation::Thick,
37063706
taskFunctionPointer, localContextInfo);

stdlib/public/Concurrency/Task.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ extension Task {
281281

282282
}
283283

284-
@_optimize(none)
285284
public func _runAsyncHandler(operation: @escaping () async -> ()) {
286285
_ = Task.runDetached(operation: operation)
287286
}

test/IRGen/async/builtins.sil

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,29 @@ bb0(%0 : $Int, %1: @unowned $Optional<Builtin.NativeObject>, %2: @guaranteed $@a
5959
// CHECK: [[NEW_TASK_AND_CONTEXT:%.*]] = call swiftcc %swift.async_task_and_context @swift_task_create_future_f(
6060
// CHECK-NEXT: [[NEW_CONTEXT_RAW:%.*]] = extractvalue %swift.async_task_and_context [[NEW_TASK_AND_CONTEXT]], 1
6161
// CHECK-NEXT: [[NEW_CONTEXT:%.*]] = bitcast %swift.context* [[NEW_CONTEXT_RAW]] to
62-
// CHECK-NEXT: [[CONTEXT_INFO_LOC:%.*]] = getelementptr inbounds <{{.*}}>* [[NEW_CONTEXT]]
62+
// CHECK-NEXT: [[CONTEXT_INFO_LOC:%.*]] = getelementptr inbounds <{{.*}}>* [[NEW_CONTEXT]], i32 0, i32 7
6363
// CHECK-NEXT: store %swift.refcounted* [[FN_CONTEXT]], %swift.refcounted** [[CONTEXT_INFO_LOC]]
6464
%20 = builtin "createAsyncTaskFuture"<T>(%0 : $Int, %4 : $Optional<Builtin.NativeObject>, %10 : $@thick Any.Type, %2 : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>) : $(Builtin.NativeObject, Builtin.RawPointer)
6565
end_borrow %4 : $Optional<Builtin.NativeObject>
6666
destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer)
6767
%21 = tuple ()
6868
return %21 : $()
6969
}
70+
71+
sil hidden [ossa] @launch_void_future : $@convention(method) (Int, Optional<Builtin.NativeObject>, @guaranteed @async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <()>) -> () {
72+
bb0(%0 : $Int, %1: @unowned $Optional<Builtin.NativeObject>, %2: @guaranteed $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <()>):
73+
%4 = begin_borrow %1 : $Optional<Builtin.NativeObject>
74+
// CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT:%.*]])
75+
%8 = metatype $@thick ().Type // user: %9
76+
%9 = init_existential_metatype %8 : $@thick ().Type, $@thick Any.Type // user: %10
77+
// CHECK: [[NEW_TASK_AND_CONTEXT:%.*]] = call swiftcc %swift.async_task_and_context @swift_task_create_future_f(
78+
// CHECK-NEXT: [[NEW_CONTEXT_RAW:%.*]] = extractvalue %swift.async_task_and_context [[NEW_TASK_AND_CONTEXT]], 1
79+
// CHECK-NEXT: [[NEW_CONTEXT:%.*]] = bitcast %swift.context* [[NEW_CONTEXT_RAW]] to
80+
// CHECK-NEXT: [[CONTEXT_INFO_LOC:%.*]] = getelementptr inbounds <{{.*}}>* [[NEW_CONTEXT]], i32 0, i32 7
81+
// CHECK-NEXT: store %swift.refcounted* [[FN_CONTEXT]], %swift.refcounted** [[CONTEXT_INFO_LOC]]
82+
%20 = builtin "createAsyncTaskFuture"<()>(%0 : $Int, %4 : $Optional<Builtin.NativeObject>, %9 : $@thick Any.Type, %2 : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer)
83+
end_borrow %4 : $Optional<Builtin.NativeObject>
84+
destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer)
85+
%21 = tuple ()
86+
return %21 : $()
87+
}

0 commit comments

Comments
 (0)