Skip to content

Commit ab4f8d0

Browse files
committed
[RequirementMachine] Inherited requirements collection should account for synthesized protocols
ClangImporter adds `SynthesizedProtocolAttr` to model inheritance from `Sendable` on protocols imported from Objective-C.
1 parent e050e35 commit ab4f8d0

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ void swift::rewriting::expandDefaultRequirements(ASTContext &ctx,
858858
}
859859

860860
/// Collect structural requirements written in the inheritance clause of an
861-
/// AssociatedTypeDecl or GenericTypeParamDecl.
861+
/// AssociatedTypeDecl, GenericTypeParamDecl, or ProtocolDecl.
862862
void swift::rewriting::realizeInheritedRequirements(
863863
TypeDecl *decl, Type type, bool shouldInferRequirements,
864864
SmallVectorImpl<StructuralRequirement> &result,
@@ -891,6 +891,17 @@ void swift::rewriting::realizeInheritedRequirements(
891891

892892
realizeTypeRequirement(dc, type, inheritedType, loc, result, errors);
893893
}
894+
895+
// Also check for `SynthesizedProtocolAttr`s with additional constraints added
896+
// by ClangImporter. This is how imported protocols are marked `Sendable`
897+
// without changing their inheritance lists.
898+
auto attrs = decl->getAttrs().getAttributes<SynthesizedProtocolAttr>();
899+
for (auto attr : attrs) {
900+
auto inheritedType = attr->getProtocol()->getDeclaredType();
901+
auto loc = attr->getLocation();
902+
903+
realizeTypeRequirement(dc, type, inheritedType, loc, result, errors);
904+
}
894905
}
895906

896907
/// StructuralRequirementsRequest realizes all the user-written requirements

test/IDE/print_objc_concurrency_interface.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ import _Concurrency
4343
// CHECK: @available(*, unavailable)
4444
// CHECK-NEXT: extension AuditedBoth : @unchecked Sendable {
4545

46+
// CHECK-LABEL: public protocol SendableProtocol
47+
// CHECK-SAME: : Sendable
48+
4649
// CHECK-LABEL: enum SendableEnum :
4750
// CHECK-SAME: @unchecked Sendable
4851

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ SENDABLE @interface AuditedSendable : NSObject @end
225225
@interface AuditedNonSendable : NSObject @end
226226
NONSENDABLE SENDABLE @interface AuditedBoth : NSObject @end
227227

228+
SENDABLE @protocol SendableProtocol @end
229+
@protocol SendableProtocolRefined <SendableProtocol> @end
230+
228231
typedef NS_ENUM(unsigned, SendableEnum) {
229232
SendableEnumFoo, SendableEnumBar
230233
};

0 commit comments

Comments
 (0)