Skip to content

Commit 4dbe922

Browse files
committed
[SILGen] Used type AbstractionPattern.
Previously, AbstractionPattern::getOpaque() was used for async continuations. That was problematic for functions like ```objc - (void)performVoid2VoidWithCompletion:(void (^ _Nonnull)(void (^ _Nonnull)(void)))completion; ``` whose completion takes a closure. Doing so resulted in attempting to build a block to func thunk where one of the functions had an out parameter. Instead, use the AbstractionPattern(ty). rdar://79383990
1 parent e6021ba commit 4dbe922

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

lib/SIL/IR/SILInstructions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ SILType GetAsyncContinuationInstBase::getLoweredResumeType() const {
27842784
auto formalType = getFormalResumeType();
27852785
auto &M = getFunction()->getModule();
27862786
auto c = getFunction()->getTypeExpansionContext();
2787-
return M.Types.getLoweredType(AbstractionPattern::getOpaque(), formalType, c);
2787+
return M.Types.getLoweredType(AbstractionPattern(formalType), formalType, c);
27882788
}
27892789

27902790
ReturnInst::ReturnInst(SILFunction &func, SILDebugLocation debugLoc,

lib/SILGen/ResultPlan.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,9 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
465465
{
466466
// Allocate space to receive the resume value when the continuation is
467467
// resumed.
468-
opaqueResumeType = SGF.getLoweredType(AbstractionPattern::getOpaque(),
469-
calleeTypeInfo.substResultType);
468+
opaqueResumeType =
469+
SGF.getLoweredType(AbstractionPattern(calleeTypeInfo.substResultType),
470+
calleeTypeInfo.substResultType);
470471
resumeBuf = SGF.emitTemporaryAllocation(loc, opaqueResumeType);
471472
}
472473

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_res
5757
// rdar://73798726
5858
- (void)getSomeObjectWithCompletionHandler:(nullable void (^)(NSObject *_Nullable x, NSError *_Nullable error))handler;
5959

60+
- (void)performVoid2VoidWithCompletion:(void (^ _Nonnull)(void (^ _Nonnull)(void)))completion;
61+
- (void)performId2VoidWithCompletion:(void (^ _Nonnull)(void (^ _Nonnull)(id _Nonnull)))completion;
62+
- (void)performId2IdWithCompletion:(void (^ _Nonnull)(id _Nonnull (^ _Nonnull)(id _Nonnull)))completion;
63+
- (void)performNSString2NSStringWithCompletion:(void (^ _Nonnull)(NSString * _Nonnull (^ _Nonnull)(NSString * _Nonnull)))completion;
64+
- (void)performNSString2NSStringNSStringWithCompletion:(void (^ _Nonnull)(NSString * _Nonnull (^ _Nonnull)(NSString * _Nonnull), NSString * _Nonnull))completion;
65+
- (void)performId2VoidId2VoidWithCompletion:(void (^ _Nonnull)(void (^ _Nonnull)(id _Nonnull), void (^ _Nonnull)(id _Nonnull)))completion;
66+
6067
-(void)oldAPIWithCompletionHandler:(void (^ _Nonnull)(NSString *_Nullable, NSError *_Nullable))handler __attribute__((availability(macosx, deprecated=10.14)));
6168

6269
-(void)someAsyncMethodWithBlock:(void (^ _Nonnull)(NSString *_Nullable, NSError *_Nullable))completionHandler;

test/SILGen/objc_async.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ func testSlowServer(slowServer: SlowServer) async throws {
7676
let _: NSObject? = try await slowServer.stopRecording()
7777
let _: NSObject = try await slowServer.someObject()
7878

79+
let _: () -> Void = await slowServer.performVoid2Void()
80+
let _: (Any) -> Void = await slowServer.performId2Void()
81+
let _: (Any) -> Any = await slowServer.performId2Id()
82+
let _: (String) -> String = await slowServer.performNSString2NSString()
83+
84+
let _: ((String) -> String, String) = await slowServer.performNSString2NSStringNSString()
85+
let _: ((Any) -> Void, (Any) -> Void) = await slowServer.performId2VoidId2Void()
7986
}
8087

8188
func testGeneric<T: AnyObject>(x: GenericObject<T>) async throws {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend %s -emit-silgen -disable-availability-checking
2+
// REQUIRES: objc_interop
3+
// REQUIRES: OS=macosx
4+
5+
import Foundation
6+
7+
func test(s: NSBackgroundActivityScheduler) async {
8+
_ = await s.schedule()
9+
}

0 commit comments

Comments
 (0)