Skip to content

Commit aaa5ce1

Browse files
authored
Merge pull request #15338 from DougGregor/redundantly-inherit-objc-protocols
[GSB] Allow redundant inheritance for all Objective-C-defined protocols.
2 parents 5585c34 + 59077bd commit aaa5ce1

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6178,29 +6178,34 @@ Constraint<T> GenericSignatureBuilder::checkConstraintList(
61786178

61796179
/// Determine whether this is a redundantly inheritable Objective-C protocol.
61806180
///
6181-
/// If we do have a redundantly inheritable Objective-C protocol, record that
6182-
/// the conformance was restated on the protocol whose requirement signature
6183-
/// we are computing.
6181+
/// A redundantly-inheritable Objective-C protocol is one where we will
6182+
/// silently accept a directly-stated redundant conformance to this protocol,
6183+
/// and emit this protocol in the list of "inherited" protocols. There are
6184+
/// two cases where we allow this:
61846185
///
6185-
/// At present, there is only one such protocol that we know about:
6186-
/// JavaScriptCore's JSExport.
6186+
// 1) For a protocol defined in Objective-C, so that we will match Clang's
6187+
/// behavior, and
6188+
/// 2) For an @objc protocol defined in Swift that directly inherits from
6189+
/// JavaScriptCore's JSExport, which depends on this behavior.
61876190
static bool isRedundantlyInheritableObjCProtocol(
61886191
ProtocolDecl *proto,
61896192
const RequirementSource *source) {
61906193
if (!proto->isObjC()) return false;
61916194

6192-
// Only JSExport protocol behaves this way.
6193-
if (!proto->getName().is("JSExport")) return false;
6194-
61956195
// Only do this for the requirement signature computation.
61966196
auto parentSource = source->parent;
61976197
if (!parentSource ||
61986198
parentSource->kind != RequirementSource::RequirementSignatureSelf)
61996199
return false;
62006200

6201+
// Check the two conditions in which we will suppress the diagnostic and
6202+
// emit the redundant inheritance.
6203+
auto inheritingProto = parentSource->getProtocolDecl();
6204+
if (!inheritingProto->hasClangNode() && !proto->getName().is("JSExport"))
6205+
return false;
6206+
62016207
// If the inheriting protocol already has @_restatedObjCConformance with
62026208
// this protocol, we're done.
6203-
auto inheritingProto = parentSource->getProtocolDecl();
62046209
for (auto *attr : inheritingProto->getAttrs()
62056210
.getAttributes<RestatedObjCConformanceAttr>()) {
62066211
if (attr->Proto == proto) return true;

test/IRGen/Inputs/usr/include/Gizmo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ NSString *NSStringFromRect(struct NSRect r);
9393
- (void)foo;
9494
@end
9595

96+
@protocol NSFungingAndRuncing <NSRuncing, NSFunging>
97+
@end
98+
99+
@protocol NSDoubleInheritedFunging <NSFungingAndRuncing, NSFunging>
100+
@end
101+
96102
typedef NS_ENUM(unsigned short, NSRuncingOptions) {
97103
NSRuncingMince = 123,
98104
NSRuncingQuinceSliced = 4567,

test/IRGen/objc_protocols.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ protocol InheritingProtocol : BaseProtocol { }
120120
// CHECK: @_PROTOCOLS__TtC14objc_protocols17ImplementingClass {{.*}} @_PROTOCOL__TtP14objc_protocols12BaseProtocol_
121121
class ImplementingClass : InheritingProtocol { }
122122

123+
// CHECK: @_PROTOCOL_PROTOCOLS_NSDoubleInheritedFunging = private constant{{.*}}i64 2{{.*}} @_PROTOCOL_NSFungingAndRuncing {{.*}}@_PROTOCOL_NSFunging
124+
123125
// -- Force generation of witness for Zim.
124126
// CHECK: define hidden swiftcc { %objc_object*, i8** } @"$S14objc_protocols22mixed_heritage_erasure{{[_0-9a-zA-Z]*}}F"
125127
func mixed_heritage_erasure(_ x: Zim) -> Frungible {
@@ -209,3 +211,8 @@ func canter<T : Palomino>(_ t: Stirrup<T>) {}
209211
func gallop<T : Vanner>(_ t: Stirrup<T>) {
210212
canter(t)
211213
}
214+
215+
// SR-7130
216+
func triggerDoubleInheritedFunging() -> AnyObject {
217+
return NSDoubleInheritedFunging.self as AnyObject
218+
}

0 commit comments

Comments
 (0)