Skip to content

Commit 50d6d6a

Browse files
authored
Merge pull request #60897 from tshortli/avoid-printing-extra-inherited-conformances
ModuleInterface: Avoid printing protocols inherited from superclasses
2 parents c89e270 + 1456092 commit 50d6d6a

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,12 @@ class InheritedProtocolCollector {
388388
/// For each type in \p directlyInherited, classify the protocols it refers to
389389
/// as included for printing or not, and record them in the appropriate
390390
/// vectors.
391+
///
392+
/// If \p skipExtra is true then avoid recording any extra protocols to
393+
/// print, such as synthesized conformances or conformances to non-public
394+
/// protocols.
391395
void recordProtocols(ArrayRef<InheritedEntry> directlyInherited,
392-
const Decl *D, bool skipSynthesized = false) {
396+
const Decl *D, bool skipExtra = false) {
393397
Optional<AvailableAttrList> availableAttrs;
394398

395399
for (InheritedEntry inherited : directlyInherited) {
@@ -398,6 +402,9 @@ class InheritedProtocolCollector {
398402
continue;
399403

400404
bool canPrintNormally = canPrintProtocolTypeNormally(inheritedTy, D);
405+
if (!canPrintNormally && skipExtra)
406+
continue;
407+
401408
ExistentialLayout layout = inheritedTy->getExistentialLayout();
402409
for (ProtocolDecl *protoDecl : layout.getProtocols()) {
403410
if (canPrintNormally)
@@ -411,7 +418,7 @@ class InheritedProtocolCollector {
411418
// any of those besides 'AnyObject'.
412419
}
413420

414-
if (skipSynthesized)
421+
if (skipExtra)
415422
return;
416423

417424
// Check for synthesized protocols, like Hashable on enums.
@@ -493,11 +500,12 @@ class InheritedProtocolCollector {
493500
if (auto *CD = dyn_cast<ClassDecl>(D)) {
494501
for (auto *SD = CD->getSuperclassDecl(); SD;
495502
SD = SD->getSuperclassDecl()) {
496-
map[nominal].recordProtocols(
497-
SD->getInherited(), SD, /*skipSynthesized=*/true);
503+
map[nominal].recordProtocols(SD->getInherited(), SD,
504+
/*skipExtra=*/true);
498505
for (auto *Ext: SD->getExtensions()) {
499506
if (shouldInclude(Ext)) {
500-
map[nominal].recordProtocols(Ext->getInherited(), Ext);
507+
map[nominal].recordProtocols(Ext->getInherited(), Ext,
508+
/*skipExtra=*/true);
501509
}
502510
}
503511
}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-emit-module-interface(%t/Foo.swiftinterface) %s -module-name Foo
33
// RUN: %target-swift-typecheck-module-from-interface(%t/Foo.swiftinterface) -module-name Foo
4+
// RUN: %FileCheck %s < %t/Foo.swiftinterface
45

5-
public protocol ProtocolA : class {}
6+
// CHECK: public protocol ProtocolA : AnyObject
7+
public protocol ProtocolA : AnyObject {}
8+
// CHECK: public protocol ProtocolB : Foo.ProtocolA
69
public protocol ProtocolB: ProtocolA {}
10+
// CHECK-NOT: ProtocolC
711
protocol ProtocolC: ProtocolA {}
812

13+
// CHECK: @_hasMissingDesignatedInitializers public class A : Foo.ProtocolB
914
public class A: ProtocolB {}
15+
// CHECK: @_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers public class B : Foo.A
1016
public class B: A, ProtocolC {}
17+
18+
// CHECK: @_hasMissingDesignatedInitializers public class C
19+
public class C {}
20+
extension C: ProtocolC {}
21+
// CHECK: @_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers public class D : Foo.C
22+
public class D: C {}
23+
24+
// CHECK: extension Foo.C : Foo.ProtocolA {}
25+
// CHECK-NOT: extension Foo.D : Foo.ProtocolA {}

0 commit comments

Comments
 (0)