Skip to content

Commit 70a13aa

Browse files
Merge pull request swiftlang#36661 from varungandhi-apple/vg-main
Fix IRGen and tests to use musttail/swiftasync correctly
2 parents 08c5507 + 871efc7 commit 70a13aa

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,12 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) {
26132613
FunctionPointer(silFunctionType, realReplFn, authInfo, signature)
26142614
.getAsFunction(IGF),
26152615
forwardedArgs);
2616-
Res->setTailCall();
2616+
if (Res->getCallingConv() == llvm::CallingConv::SwiftTail &&
2617+
Res->getCaller()->getCallingConv() == llvm::CallingConv::SwiftTail) {
2618+
Res->setTailCallKind(IGF.IGM.AsyncTailCallKind);
2619+
} else {
2620+
Res->setTailCall();
2621+
}
26172622
if (IGF.CurFn->getReturnType()->isVoidTy())
26182623
IGF.Builder.CreateRetVoid();
26192624
else

test/IRGen/async/run-call-dynamic-void_to_void.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import _Concurrency
1717
// CHECK-LL: @"$s4main3runyyYFTu" = hidden global %swift.async_func_pointer
1818

1919
// CHECK-LL: define hidden swift{{(tail)?}}cc void @"$s4main3runyyYF"(%swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}}
20+
// CHECK-LL: musttail call swifttailcc void
2021
dynamic func run() async {
2122
print("running")
2223
}

unittests/runtime/Actor.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class TaskContinuationFromLambda {
120120

121121
SWIFT_CC(swiftasync)
122122
static void invoke(SWIFT_ASYNC_CONTEXT AsyncContext *context, SWIFT_CONTEXT HeapObject *) {
123-
(*lambdaStorage)(static_cast<Context*>(context));
123+
return (*lambdaStorage)(static_cast<Context*>(context));
124124
}
125125

126126
public:
@@ -220,20 +220,20 @@ static AsyncTask *createTaskStoring(JobPriority priority,
220220
TEST(ActorTest, validateTestHarness) {
221221
run([] {
222222
auto task0 = createTask(JobPriority::Background,
223-
[](AsyncContext *context) {
223+
[](AsyncContext *context) SWIFT_CC(swiftasync) {
224224
EXPECT_PROGRESS(5);
225225
EXPECT_PROGRESS(6);
226226
finishTest();
227227
return context->ResumeParent(context);
228228
});
229229
auto task1 = createTask(JobPriority::Default,
230-
[](AsyncContext *context) {
230+
[](AsyncContext *context) SWIFT_CC(swiftasync) {
231231
EXPECT_PROGRESS(1);
232232
EXPECT_PROGRESS(2);
233233
return context->ResumeParent(context);
234234
});
235235
auto task2 = createTask(JobPriority::Default,
236-
[](AsyncContext *context) {
236+
[](AsyncContext *context) SWIFT_CC(swiftasync) {
237237
EXPECT_PROGRESS(3);
238238
EXPECT_PROGRESS(4);
239239
return context->ResumeParent(context);
@@ -254,22 +254,22 @@ TEST(ActorTest, actorSwitch) {
254254
auto actor = createActor();
255255
auto task0 = createTaskStoring(JobPriority::Default,
256256
(AsyncTask*) nullptr, actor,
257-
[](Context *context) {
257+
[](Context *context) SWIFT_CC(swiftasync) {
258258
EXPECT_PROGRESS(1);
259259
EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric());
260260
EXPECT_EQ(nullptr, context->get<0>());
261261
std::get<0>(context->values) = swift_task_getCurrent();
262262

263263
auto continuation = prepareContinuation<Context>(
264-
[](Context *context) {
264+
[](Context *context) SWIFT_CC(swiftasync) {
265265
EXPECT_PROGRESS(2);
266266
auto executor = swift_task_getCurrentExecutor();
267267
EXPECT_FALSE(executor.isGeneric());
268268
EXPECT_EQ(ExecutorRef::forDefaultActor(context->get<1>()),
269269
executor);
270270
EXPECT_EQ(swift_task_getCurrent(), context->get<0>());
271271
auto continuation = prepareContinuation<Context>(
272-
[](Context *context) {
272+
[](Context *context) SWIFT_CC(swiftasync) {
273273
EXPECT_PROGRESS(3);
274274
EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric());
275275
EXPECT_EQ(swift_task_getCurrent(), context->get<0>());
@@ -296,7 +296,7 @@ TEST(ActorTest, actorContention) {
296296

297297
auto task0 = createTaskStoring(JobPriority::Default,
298298
(AsyncTask*) nullptr, actor,
299-
[](Context *context) {
299+
[](Context *context) SWIFT_CC(swiftasync) {
300300
EXPECT_PROGRESS(1);
301301
EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric());
302302
EXPECT_EQ(nullptr, context->get<0>());
@@ -305,7 +305,7 @@ TEST(ActorTest, actorContention) {
305305
std::get<0>(context->values) = task;
306306

307307
parkTask(task, context,
308-
[](Context *context) {
308+
[](Context *context) SWIFT_CC(swiftasync) {
309309
EXPECT_PROGRESS(3);
310310
auto executor = swift_task_getCurrentExecutor();
311311
EXPECT_FALSE(executor.isGeneric());
@@ -314,7 +314,7 @@ TEST(ActorTest, actorContention) {
314314
auto task = swift_task_getCurrent();
315315
EXPECT_EQ(task, context->get<0>());
316316
parkTask(task, context,
317-
[](Context *context) {
317+
[](Context *context) SWIFT_CC(swiftasync) {
318318
EXPECT_PROGRESS(4);
319319
EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric());
320320
EXPECT_EQ(swift_task_getCurrent(), context->get<0>());
@@ -329,7 +329,7 @@ TEST(ActorTest, actorContention) {
329329

330330
auto task1 = createTaskStoring(JobPriority::Background,
331331
(AsyncTask*) nullptr, actor,
332-
[](Context *context) {
332+
[](Context *context) SWIFT_CC(swiftasync) {
333333
EXPECT_PROGRESS(2);
334334
auto executor = swift_task_getCurrentExecutor();
335335
EXPECT_FALSE(executor.isGeneric());
@@ -340,7 +340,7 @@ TEST(ActorTest, actorContention) {
340340
std::get<0>(context->values) = task;
341341

342342
parkTask(task, context,
343-
[](Context *context) {
343+
[](Context *context) SWIFT_CC(swiftasync) {
344344
EXPECT_PROGRESS(5);
345345
EXPECT_TRUE(swift_task_getCurrentExecutor().isGeneric());
346346
EXPECT_EQ(swift_task_getCurrent(), context->get<0>());

unittests/runtime/TaskStatus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void simpleTaskInvokeFunction(SWIFT_ASYNC_CONTEXT AsyncContext *context,
4848
// Return to finish off the task.
4949
// In a normal situation we'd need to free the context, but here
5050
// we know we're at the top level.
51-
valueContext->ResumeParent(valueContext);
51+
return valueContext->ResumeParent(valueContext);
5252
}
5353

5454
template <class T>

0 commit comments

Comments
 (0)