Skip to content

Commit e057b68

Browse files
committed
Sema: Effectively revert #70569.
The fix caused a source break that is now captured as an additional test case in `objc_async_conformance.swift`. Resolves rdar://121527977
1 parent 6a86bf3 commit e057b68

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4943,6 +4943,8 @@ hasInvalidTypeInConformanceContext(const ValueDecl *requirement,
49434943

49444944
void ConformanceChecker::resolveValueWitnesses() {
49454945
bool usesPreconcurrencyConformance = false;
4946+
auto objcRequirementMap = getObjCRequirementMap(Proto);
4947+
49464948
for (auto *requirement : Proto->getProtocolRequirements()) {
49474949
// Associated type requirements handled elsewhere.
49484950
if (isa<TypeDecl>(requirement))
@@ -5080,6 +5082,23 @@ void ConformanceChecker::resolveValueWitnesses() {
50805082
continue;
50815083
}
50825084

5085+
// If this requirement is part of a pair of imported async requirements,
5086+
// where one has already been witnessed, we can skip it.
5087+
//
5088+
// This situation primarily arises when the ClangImporter translates an
5089+
// async-looking ObjC protocol method requirement into two Swift protocol
5090+
// requirements: an async version and a sync version. Exactly one of the two
5091+
// must be witnessed by the conformer.
5092+
if (!requirement->isImplicit() &&
5093+
getObjCRequirementSibling(
5094+
Proto, requirement, objcRequirementMap,
5095+
[this](AbstractFunctionDecl *cand) {
5096+
return !cand->getAttrs().hasAttribute<OptionalAttr>() &&
5097+
!cand->isImplicit() && this->Conformance->hasWitness(cand);
5098+
})) {
5099+
continue;
5100+
}
5101+
50835102
// Try substituting into the requirement's interface type. If we fail,
50845103
// either a generic requirement was not satisfied or we tripped on an
50855104
// invalid type witness, and there's no point in resolving a witness.

test/ClangImporter/objc_async_conformance.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ class C5 {
112112
class C6: C5, ServiceProvider {
113113
@MainActor func allOperations() async -> [String] { [] }
114114
}
115+
116+
extension ImplementsLoadable: @retroactive Loadable {
117+
public func loadStuff(withOtherIdentifier otherIdentifier: Int, reply: @escaping () -> Void) {}
118+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,15 @@ MAIN_ACTOR
344344
error:(NSError * __autoreleasing *)error;
345345
@end
346346

347+
@protocol Loadable
348+
- (void)loadStuffWithIdentifier:(NSInteger)identifier reply:(void (^)())reply;
349+
- (void)loadStuffWithOtherIdentifier:(NSInteger)otherIdentifier reply:(void (^)())reply;
350+
- (void)loadStuffWithGroupID:(NSInteger)groupID reply:(void (^)())reply;
351+
@end
352+
353+
@interface ImplementsLoadable : NSObject
354+
- (void)loadStuffWithIdentifier:(NSInteger)identifier reply:(void (^)())reply;
355+
- (void)loadStuffWithGroupID:(NSInteger)groupID reply:(void (^)())reply;
356+
@end
357+
347358
#pragma clang assume_nonnull end

test/Serialization/conformance-objc-async.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// RUN: %target-swift-frontend -compile-module-from-interface %t/Conformance.swiftinterface -module-name Conformance -o /dev/null -I %t
55
// REQUIRES: objc_interop
66

7+
// REQUIRES: rdar119435253
8+
79
//--- module.modulemap
810
module ObjCProto {
911
header "objc_proto.h"

0 commit comments

Comments
 (0)