Skip to content

Commit 61e0c55

Browse files
committed
FrontendTool: Remove a usage of getExistentialTypeProtocols()
1 parent 6580e50 commit 61e0c55

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/FrontendTool/ReferenceDependencies.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/Decl.h"
1717
#include "swift/AST/DiagnosticEngine.h"
1818
#include "swift/AST/DiagnosticsFrontend.h"
19+
#include "swift/AST/ExistentialLayout.h"
1920
#include "swift/AST/Module.h"
2021
#include "swift/AST/ModuleLoader.h"
2122
#include "swift/AST/NameLookup.h"
@@ -85,18 +86,24 @@ static bool declIsPrivate(const Decl *member) {
8586
}
8687

8788
static bool extendedTypeIsPrivate(TypeLoc inheritedType) {
88-
if (!inheritedType.getType())
89+
auto type = inheritedType.getType();
90+
if (!type)
8991
return true;
9092

91-
if (!inheritedType.getType()->isExistentialType()) {
93+
if (!type->isExistentialType()) {
9294
// Be conservative. We don't know how to deal with other extended types.
9395
return false;
9496
}
9597

96-
SmallVector<ProtocolDecl *, 2> protocols;
97-
inheritedType.getType()->getExistentialTypeProtocols(protocols);
98+
auto layout = type->getExistentialLayout();
99+
assert(!layout.superclass && "Should not have a subclass existential "
100+
"in the inheritance clause of an extension");
101+
for (auto protoTy : layout.getProtocols()) {
102+
if (!declIsPrivate(protoTy->getDecl()))
103+
return false;
104+
}
98105

99-
return std::all_of(protocols.begin(), protocols.end(), declIsPrivate);
106+
return true;
100107
}
101108

102109
static std::string mangleTypeAsContext(const NominalTypeDecl *type) {
@@ -172,6 +179,8 @@ bool swift::emitReferenceDependencies(DiagnosticEngine &diags,
172179
break;
173180
}
174181

182+
// Check if the extension is just adding members, or if it is
183+
// introducing a conformance to a public protocol.
175184
bool justMembers = std::all_of(ED->getInherited().begin(),
176185
ED->getInherited().end(),
177186
extendedTypeIsPrivate);

0 commit comments

Comments
 (0)