Skip to content

Commit ffbbfb7

Browse files
committed
[ConstraintSystem] Strip Sendable while processing AnyObject lookup results
All of the declarations returned by dynamic `AnyObject` lookup are `@objc` and hence `@preconcurrency` which means that it should be possible to introduce `@Sendable` and `any Sendable` annotations without affecting lookup and shadowing behavior.
1 parent 0004a4b commit ffbbfb7

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,14 @@ void ConstraintSystem::recordAppliedDisjunction(
331331
/// Retrieve a dynamic result signature for the given declaration.
332332
static std::tuple<char, ObjCSelector, CanType>
333333
getDynamicResultSignature(ValueDecl *decl) {
334+
// Handle functions.
334335
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
335-
// Handle functions.
336-
auto type = func->getMethodInterfaceType();
336+
// Strip `@Sendable` and `any Sendable` because it should be
337+
// possible to add them without affecting lookup results and
338+
// shadowing. All of the declarations that are processed here
339+
// are `@objc` and hence `@preconcurrency`.
340+
auto type = func->getMethodInterfaceType()->stripConcurrency(
341+
/*recursive=*/true, /*dropGlobalActor=*/false);
337342
return std::make_tuple(func->isStatic(), func->getObjCSelector(),
338343
type->getCanonicalType());
339344
}

test/Concurrency/sendable_objc_attr_in_type_context_swift5.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ void doSomethingConcurrently(__attribute__((noescape)) void SWIFT_SENDABLE (^blo
7474
-(void)updateWithCompletionHandler: (void (^_Nullable)(void)) handler;
7575
@end
7676

77+
@protocol TestWitnesses
78+
-(void)willSendDataWithCompletion: (void (^)(void)) completion;
79+
@end
80+
7781
#pragma clang assume_nonnull end
7882

7983
//--- main.swift
@@ -176,3 +180,12 @@ class TestConformanceWithoutStripping : InnerSendableTypes {
176180
self.update { } // Ok - no ambiguity
177181
}
178182
}
183+
184+
@objc
185+
class ImplicitShadowing : NSObject, TestWitnesses {
186+
func willSendData(completion: @escaping () -> Void) {}
187+
188+
func test() {
189+
(self as AnyObject).willSendData { } // Ok
190+
}
191+
}

test/Concurrency/sendable_objc_attr_in_type_context_swift6.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ void doSomethingConcurrently(__attribute__((noescape)) void SWIFT_SENDABLE (^blo
7474
-(void)updateWithCompletionHandler: (void (^_Nullable)(void)) handler;
7575
@end
7676

77+
@protocol TestWitnesses
78+
-(void)willSendDataWithCompletion: (void (^)(void)) completion;
79+
@end
80+
7781
#pragma clang assume_nonnull end
7882

7983
//--- main.swift
@@ -178,8 +182,17 @@ class TestConformanceWithoutStripping : InnerSendableTypes {
178182

179183
@objc func update(completionHandler: (() -> Void)? = nil) {}
180184

181-
func testCompute() {
185+
func test() {
182186
self.compute { } // Ok - no ambiguity
183187
self.update { } // Ok - no ambiguity
184188
}
185189
}
190+
191+
@objc
192+
class ImplicitShadowing : NSObject, TestWitnesses {
193+
func willSendData(completion: @escaping () -> Void) {}
194+
195+
func test() {
196+
(self as AnyObject).willSendData { } // Ok
197+
}
198+
}

0 commit comments

Comments
 (0)