Skip to content

Commit c2b3be4

Browse files
authored
Merge pull request #34750 from nate-chandler/concurrency/irgen/rdar70597390
[Async CC] Unroll workaround where @main was async.
2 parents 390dd28 + 357988e commit c2b3be4

File tree

38 files changed

+42
-87
lines changed

38 files changed

+42
-87
lines changed

lib/IRGen/IRGenFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class IRGenFunction {
8383
OptimizationMode Mode = OptimizationMode::NotSet,
8484
const SILDebugScope *DbgScope = nullptr,
8585
Optional<SILLocation> DbgLoc = None);
86-
virtual ~IRGenFunction();
86+
~IRGenFunction();
8787

8888
void unimplemented(SourceLoc Loc, StringRef Message);
8989

@@ -128,9 +128,9 @@ class IRGenFunction {
128128
CoroutineHandle = handle;
129129
}
130130

131-
virtual llvm::Value *getAsyncTask();
132-
virtual llvm::Value *getAsyncExecutor();
133-
virtual llvm::Value *getAsyncContext();
131+
llvm::Value *getAsyncTask();
132+
llvm::Value *getAsyncExecutor();
133+
llvm::Value *getAsyncContext();
134134

135135
llvm::Function *getOrCreateResumePrjFn();
136136
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,

lib/IRGen/IRGenSIL.cpp

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -856,42 +856,6 @@ class IRGenSILFunction :
856856
}
857857
}
858858

859-
llvm::Value *getAsyncTask() override {
860-
// FIXME: (1) Remove this override, (2) mark the IRGenFunction::getAsyncTask
861-
// declaration as non-virtual, and (3) mark IRGenFunction's
862-
// destructor non-virtual once Task.runDetached is available.
863-
// rdar://problem/70597390*/
864-
if (CurSILFn->getLoweredFunctionType()->getRepresentation() ==
865-
SILFunctionTypeRepresentation::CFunctionPointer) {
866-
return llvm::Constant::getNullValue(IGM.SwiftTaskPtrTy);
867-
}
868-
return IRGenFunction::getAsyncTask();
869-
}
870-
871-
llvm::Value *getAsyncExecutor() override {
872-
// FIXME: (1) Remove this override, (2) mark the
873-
// IRGenFunction::getAsyncExecutor declaration as non-virtual, and
874-
// (3) mark IRGenFunction's destructor non-virtual once
875-
// Task.runDetached is available. rdar://problem/70597390*/
876-
if (CurSILFn->getLoweredFunctionType()->getRepresentation() ==
877-
SILFunctionTypeRepresentation::CFunctionPointer) {
878-
return llvm::Constant::getNullValue(IGM.SwiftExecutorPtrTy);
879-
}
880-
return IRGenFunction::getAsyncExecutor();
881-
}
882-
883-
llvm::Value *getAsyncContext() override {
884-
// FIXME: (1) Remove this override, (2) mark the
885-
// IRGenFunction::getAsyncContext declaration as non-virtual, and
886-
// (3) mark IRGenFunction's destructor non-virtual once
887-
// Task.runDetached is available. rdar://problem/70597390*/
888-
if (CurSILFn->getLoweredFunctionType()->getRepresentation() ==
889-
SILFunctionTypeRepresentation::CFunctionPointer) {
890-
return llvm::Constant::getNullValue(IGM.SwiftContextPtrTy);
891-
}
892-
return IRGenFunction::getAsyncContext();
893-
}
894-
895859
//===--------------------------------------------------------------------===//
896860
// SIL instruction lowering
897861
//===--------------------------------------------------------------------===//
@@ -1440,11 +1404,7 @@ std::unique_ptr<COrObjCEntryPointArgumentEmission>
14401404
getCOrObjCEntryPointArgumentEmission(IRGenSILFunction &IGF,
14411405
SILBasicBlock &entry,
14421406
Explosion &allParamValues) {
1443-
if (IGF.CurSILFn->isAsync() &&
1444-
!(/*FIXME: Remove this condition once Task.runDetached is
1445-
available. rdar://problem/70597390*/
1446-
IGF.CurSILFn->getLoweredFunctionType()->getRepresentation() ==
1447-
SILFunctionTypeRepresentation::CFunctionPointer)) {
1407+
if (IGF.CurSILFn->isAsync()) {
14481408
llvm_unreachable("unsupported");
14491409
} else {
14501410
return std::make_unique<SyncCOrObjCEntryPointArgumentEmission>(
@@ -3250,12 +3210,7 @@ static void emitReturnInst(IRGenSILFunction &IGF,
32503210
auto &retTI = cast<LoadableTypeInfo>(IGF.getTypeInfo(resultTy));
32513211
retTI.initialize(IGF, result, IGF.IndirectReturn, false);
32523212
IGF.Builder.CreateRetVoid();
3253-
} else if (IGF.isAsync() &&
3254-
!(/*FIXME: Remove this condition once Task.runDetached is
3255-
available. rdar://problem/70597390*/
3256-
IGF.CurSILFn->getLoweredFunctionType()
3257-
->getRepresentation() ==
3258-
SILFunctionTypeRepresentation::CFunctionPointer)) {
3213+
} else if (IGF.isAsync()) {
32593214
// If we're generating an async function, store the result into the buffer.
32603215
assert(!IGF.IndirectReturn.isValid() &&
32613216
"Formally direct results should stay direct results for async "

test/IRGen/async/run-call-classinstance-int64-to-void.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ sil @test_case : $@convention(thin) @async () -> () {
105105
return %void : $()
106106
}
107107

108-
sil @main : $@async @convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
108+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
109109
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
110110

111111
%2 = function_ref @test_case : $@convention(thin) @async () -> ()

test/IRGen/async/run-call-classinstance-void-to-void.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ sil @test_case : $@convention(thin) @async () -> () {
103103
return %void : $()
104104
}
105105

106-
sil @main : $@async @convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
106+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
107107
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
108108

109109
%2 = function_ref @test_case : $@convention(thin) @async () -> ()

test/IRGen/async/run-call-existential-to-void.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ sil @test_case : $@convention(thin) @async () -> () {
8181
return %void : $()
8282
}
8383

84-
sil @main : $@async @convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
84+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
8585
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
8686

8787
%2 = function_ref @test_case : $@convention(thin) @async () -> ()

test/IRGen/async/run-call-generic-to-generic.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ sil @test_case : $@convention(thin) @async () -> () {
5353
return %void : $()
5454
}
5555

56-
sil @main : $@async @convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
56+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
5757
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
5858

5959
%2 = function_ref @test_case : $@convention(thin) @async () -> ()

test/IRGen/async/run-call-generic-to-void.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sil @test_case : $@convention(thin) @async () -> () {
4444
return %void : $()
4545
}
4646

47-
sil @main : $@async @convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
47+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
4848
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
4949

5050
%2 = function_ref @test_case : $@convention(thin) @async () -> ()

test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ sil @test_case : $@convention(thin) @async () -> () {
6161
return %void : $()
6262
}
6363

64-
sil @main : $@async @convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
64+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
6565
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
6666

6767
%2 = function_ref @test_case : $@convention(thin) @async () -> ()

test/IRGen/async/run-call-int64-and-int64-to-void.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sil @test_case : $@convention(thin) @async () -> () {
4646
return %void : $()
4747
}
4848

49-
sil @main : $@async @convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
49+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
5050
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
5151

5252
%2 = function_ref @test_case : $@convention(thin) @async () -> ()

test/IRGen/async/run-call-int64-to-void.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ sil @test_case : $@convention(thin) @async () -> () {
4343
return %void : $()
4444
}
4545

46-
sil @main : $@async @convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
46+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
4747
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
4848

4949
%2 = function_ref @test_case : $@convention(thin) @async () -> ()

0 commit comments

Comments
 (0)