Skip to content

Commit c493632

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 4cb8453 commit c493632

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
@@ -2794,7 +2794,7 @@ SILType GetAsyncContinuationInstBase::getLoweredResumeType() const {
27942794
auto formalType = getFormalResumeType();
27952795
auto &M = getFunction()->getModule();
27962796
auto c = getFunction()->getTypeExpansionContext();
2797-
return M.Types.getLoweredType(AbstractionPattern::getOpaque(), formalType, c);
2797+
return M.Types.getLoweredType(AbstractionPattern(formalType), formalType, c);
27982798
}
27992799

28002800
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
@@ -70,6 +70,13 @@ func testSlowServer(slowServer: SlowServer) async throws {
7070
let _: NSObject? = try await slowServer.stopRecording()
7171
let _: NSObject = try await slowServer.someObject()
7272

73+
let _: () -> Void = await slowServer.performVoid2Void()
74+
let _: (Any) -> Void = await slowServer.performId2Void()
75+
let _: (Any) -> Any = await slowServer.performId2Id()
76+
let _: (String) -> String = await slowServer.performNSString2NSString()
77+
78+
let _: ((String) -> String, String) = await slowServer.performNSString2NSStringNSString()
79+
let _: ((Any) -> Void, (Any) -> Void) = await slowServer.performId2VoidId2Void()
7380
}
7481

7582
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)