Skip to content

Commit 57fd46d

Browse files
committed
[SIL] Fixed return index for call-as-async (BOOL, Error, Value) case.
When converting an ObjC method type which is being called as async to a Swift function type, some of the values passed to the ObjC method's completion handler are converted to return values of the Swift function. The flag and error parameters, however, if present, are ignored. When abstracting the result type for the Swift method, the formal type of the corresponding parameter in the ObjC method's completion handler is used. Digging out that parameter entails indexing into the parameters of the completion handler. Previously, the indexing logic relied on the error appearing before the flag if both appeared before the value of interest. Here, the indexing is tweaked to check both special indices for each possible index until the first that matches neither is found. rdar://81625544
1 parent e99cbaf commit 57fd46d

File tree

4 files changed

+614
-6
lines changed

4 files changed

+614
-6
lines changed

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,14 @@ AbstractionPattern AbstractionPattern::getFunctionResultType() const {
574574
// If there's a single argument, abstract it according to its formal type
575575
// in the ObjC signature.
576576
unsigned callbackResultIndex = 0;
577-
if (callbackErrorIndex && callbackResultIndex >= *callbackErrorIndex)
578-
++callbackResultIndex;
579-
if (callbackErrorFlagIndex
580-
&& callbackResultIndex >= *callbackErrorFlagIndex)
581-
++callbackResultIndex;
582-
577+
for (auto index : indices(callbackParamTy->getParamTypes())) {
578+
if (callbackErrorIndex && index == *callbackErrorIndex)
579+
continue;
580+
if (callbackErrorFlagIndex && index == *callbackErrorFlagIndex)
581+
continue;
582+
callbackResultIndex = index;
583+
break;
584+
}
583585
auto clangResultType = callbackParamTy
584586
->getParamType(callbackResultIndex)
585587
.getTypePtr();
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#include <Foundation/Foundation.h>
2+
3+
#pragma clang assume_nonnull begin
4+
5+
typedef void (^CompletionHandler)(void);
6+
7+
@interface PFXObject : NSObject
8+
- (void)performSingleFlaggy1WithCompletionHandler:
9+
(void (^)(BOOL, CompletionHandler _Nullable))completionHandler
10+
__attribute__((swift_async_error(zero_argument, 1)));
11+
- (void)performSingleFlaggy2WithCompletionHandler:
12+
(void (^)(CompletionHandler _Nullable, BOOL))completionHandler
13+
__attribute__((swift_async_error(zero_argument, 2)));
14+
15+
- (void)performSingleErrory1WithCompletionHandler:
16+
(void (^)(NSError *_Nullable,
17+
CompletionHandler _Nullable))completionHandler;
18+
- (void)performSingleErrory2WithCompletionHandler:
19+
(void (^)(CompletionHandler _Nullable,
20+
NSError *_Nullable))completionHandler;
21+
22+
- (void)performSingleBothy12WithCompletionHandler:
23+
(void (^)(NSError *_Nullable, BOOL,
24+
CompletionHandler _Nullable))completionHandler
25+
__attribute__((swift_async_error(zero_argument, 2)));
26+
- (void)performSingleBothy13WithCompletionHandler:
27+
(void (^)(NSError *_Nullable, CompletionHandler _Nullable,
28+
BOOL))completionHandler
29+
__attribute__((swift_async_error(zero_argument, 3)));
30+
- (void)performSingleBothy21WithCompletionHandler:
31+
(void (^)(BOOL, NSError *_Nullable,
32+
CompletionHandler _Nullable))completionHandler
33+
__attribute__((swift_async_error(zero_argument, 1)));
34+
- (void)performSingleBothy23WithCompletionHandler:
35+
(void (^)(CompletionHandler _Nullable, NSError *_Nullable,
36+
BOOL))completionHandler
37+
__attribute__((swift_async_error(zero_argument, 3)));
38+
- (void)performSingleBothy31WithCompletionHandler:
39+
(void (^)(BOOL, CompletionHandler _Nullable,
40+
NSError *_Nullable))completionHandler
41+
__attribute__((swift_async_error(zero_argument, 1)));
42+
- (void)performSingleBothy32WithCompletionHandler:
43+
(void (^)(CompletionHandler _Nullable, BOOL,
44+
NSError *_Nullable))completionHandler
45+
__attribute__((swift_async_error(zero_argument, 2)));
46+
47+
- (void)performDoubleFlaggy1WithCompletionHandler:
48+
(void (^)(BOOL, CompletionHandler _Nullable,
49+
CompletionHandler _Nullable))completionHandler
50+
__attribute__((swift_async_error(zero_argument, 1)));
51+
- (void)performDoubleFlaggy2WithCompletionHandler:
52+
(void (^)(CompletionHandler _Nullable, BOOL,
53+
CompletionHandler _Nullable))completionHandler
54+
__attribute__((swift_async_error(zero_argument, 2)));
55+
- (void)performDoubleFlaggy3WithCompletionHandler:
56+
(void (^)(CompletionHandler _Nullable, CompletionHandler _Nullable,
57+
BOOL))completionHandler
58+
__attribute__((swift_async_error(zero_argument, 3)));
59+
60+
- (void)performDoubleErrory1WithCompletionHandler:
61+
(void (^)(NSError *_Nullable, CompletionHandler _Nullable,
62+
CompletionHandler _Nullable))completionHandler;
63+
- (void)performDoubleErrory2WithCompletionHandler:
64+
(void (^)(CompletionHandler _Nullable, NSError *_Nullable,
65+
CompletionHandler _Nullable))completionHandler;
66+
- (void)performDoubleErrory3WithCompletionHandler:
67+
(void (^)(CompletionHandler _Nullable, CompletionHandler _Nullable,
68+
NSError *_Nullable))completionHandler;
69+
70+
- (void)performDoubleBothy12WithCompletionHandler:
71+
(void (^)(NSError *_Nullable, BOOL, CompletionHandler _Nullable,
72+
CompletionHandler _Nullable))completionHandler
73+
__attribute__((swift_async_error(zero_argument, 2)));
74+
- (void)performDoubleBothy13WithCompletionHandler:
75+
(void (^)(NSError *_Nullable, CompletionHandler _Nullable, BOOL,
76+
CompletionHandler _Nullable))completionHandler
77+
__attribute__((swift_async_error(zero_argument, 3)));
78+
- (void)performDoubleBothy14WithCompletionHandler:
79+
(void (^)(NSError *_Nullable, CompletionHandler _Nullable,
80+
CompletionHandler _Nullable, BOOL))completionHandler
81+
__attribute__((swift_async_error(zero_argument, 4)));
82+
83+
- (void)performDoubleBothy21WithCompletionHandler:
84+
(void (^)(BOOL, NSError *_Nullable, CompletionHandler _Nullable,
85+
CompletionHandler _Nullable))completionHandler
86+
__attribute__((swift_async_error(zero_argument, 1)));
87+
- (void)performDoubleBothy23WithCompletionHandler:
88+
(void (^)(CompletionHandler _Nullable, NSError *_Nullable, BOOL,
89+
CompletionHandler _Nullable))completionHandler
90+
__attribute__((swift_async_error(zero_argument, 3)));
91+
- (void)performDoubleBothy24WithCompletionHandler:
92+
(void (^)(CompletionHandler _Nullable, NSError *_Nullable,
93+
CompletionHandler _Nullable, BOOL))completionHandler
94+
__attribute__((swift_async_error(zero_argument, 4)));
95+
96+
- (void)performDoubleBothy31WithCompletionHandler:
97+
(void (^)(BOOL, CompletionHandler _Nullable, NSError *_Nullable,
98+
CompletionHandler _Nullable))completionHandler
99+
__attribute__((swift_async_error(zero_argument, 1)));
100+
- (void)performDoubleBothy32WithCompletionHandler:
101+
(void (^)(CompletionHandler _Nullable, BOOL, NSError *_Nullable,
102+
CompletionHandler _Nullable))completionHandler
103+
__attribute__((swift_async_error(zero_argument, 2)));
104+
- (void)performDoubleBothy34WithCompletionHandler:
105+
(void (^)(CompletionHandler _Nullable, CompletionHandler _Nullable,
106+
NSError *_Nullable, BOOL))completionHandler
107+
__attribute__((swift_async_error(zero_argument, 4)));
108+
109+
- (void)performDoubleBothy41WithCompletionHandler:
110+
(void (^)(BOOL, CompletionHandler _Nullable, CompletionHandler _Nullable,
111+
NSError *_Nullable))completionHandler
112+
__attribute__((swift_async_error(zero_argument, 1)));
113+
- (void)performDoubleBothy42WithCompletionHandler:
114+
(void (^)(CompletionHandler _Nullable, BOOL, CompletionHandler _Nullable,
115+
NSError *_Nullable))completionHandler
116+
__attribute__((swift_async_error(zero_argument, 2)));
117+
- (void)performDoubleBothy43WithCompletionHandler:
118+
(void (^)(CompletionHandler _Nullable, CompletionHandler _Nullable, BOOL,
119+
NSError *_Nullable))completionHandler
120+
__attribute__((swift_async_error(zero_argument, 3)));
121+
@end
122+
123+
#pragma clang assume_nonnull end

0 commit comments

Comments
 (0)