Skip to content

Commit f0907d3

Browse files
committed
APIDigester: Stop calling getAllConformances() on protocols
1 parent 064b713 commit f0907d3

File tree

3 files changed

+48
-31
lines changed

3 files changed

+48
-31
lines changed

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct swift::ide::api::SDKNodeInitInfo {
5050
SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD);
5151
SDKNodeInitInfo(SDKContext &Ctx, OperatorDecl *D);
5252
SDKNodeInitInfo(SDKContext &Ctx, ImportDecl *ID);
53-
SDKNodeInitInfo(SDKContext &Ctx, ProtocolConformance *Conform);
53+
SDKNodeInitInfo(SDKContext &Ctx, ProtocolConformanceRef Conform);
5454
SDKNodeInitInfo(SDKContext &Ctx, Type Ty, TypeInitInfo Info = TypeInitInfo());
5555
SDKNode* createSDKNode(SDKNodeKind Kind);
5656
};
@@ -1459,17 +1459,21 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ImportDecl *ID):
14591459
Name = PrintedName = Ctx.buffer(content);
14601460
}
14611461

1462-
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ProtocolConformance *Conform):
1463-
SDKNodeInitInfo(Ctx, Conform->getProtocol()) {
1462+
SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ProtocolConformanceRef Conform):
1463+
SDKNodeInitInfo(Ctx, Conform.getRequirement()) {
14641464
// The conformance can be conditional. The generic signature keeps track of
14651465
// the requirements.
1466-
GenericSig = printGenericSignature(Ctx, Conform, Ctx.checkingABI());
1467-
SugaredGenericSig = Ctx.checkingABI() ?
1468-
printGenericSignature(Ctx, Conform, false): StringRef();
1469-
// Whether this conformance is ABI placeholder depends on the decl context
1470-
// of this conformance.
1471-
IsABIPlaceholder = isABIPlaceholderRecursive(Conform->getDeclContext()->
1472-
getAsDecl());
1466+
if (Conform.isConcrete()) {
1467+
auto *Concrete = Conform.getConcrete();
1468+
1469+
GenericSig = printGenericSignature(Ctx, Concrete, Ctx.checkingABI());
1470+
SugaredGenericSig = Ctx.checkingABI() ?
1471+
printGenericSignature(Ctx, Concrete, false): StringRef();
1472+
// Whether this conformance is ABI placeholder depends on the decl context
1473+
// of this conformance.
1474+
IsABIPlaceholder = isABIPlaceholderRecursive(Concrete->getDeclContext()->
1475+
getAsDecl());
1476+
}
14731477
}
14741478

14751479
static bool isProtocolRequirement(ValueDecl *VD) {
@@ -1910,7 +1914,7 @@ SwiftDeclCollector::constructConformanceNode(ProtocolConformance *Conform) {
19101914
if (Ctx.checkingABI())
19111915
Conform = Conform->getCanonicalConformance();
19121916
auto ConfNode = cast<SDKNodeConformance>(SDKNodeInitInfo(Ctx,
1913-
Conform).createSDKNode(SDKNodeKind::Conformance));
1917+
ProtocolConformanceRef(Conform)).createSDKNode(SDKNodeKind::Conformance));
19141918
Conform->forEachTypeWitness(
19151919
[&](AssociatedTypeDecl *assoc, Type ty, TypeDecl *typeDecl) -> bool {
19161920
ConfNode->addChild(constructTypeWitnessNode(assoc, ty));
@@ -1922,12 +1926,25 @@ SwiftDeclCollector::constructConformanceNode(ProtocolConformance *Conform) {
19221926
void swift::ide::api::
19231927
SwiftDeclCollector::addConformancesToTypeDecl(SDKNodeDeclType *Root,
19241928
NominalTypeDecl *NTD) {
1925-
// Avoid adding the same conformance twice.
1926-
SmallPtrSet<ProtocolConformance*, 4> Seen;
1927-
for (auto &Conf: NTD->getAllConformances()) {
1928-
if (!Ctx.shouldIgnore(Conf->getProtocol()) && !Seen.count(Conf))
1929-
Root->addConformance(constructConformanceNode(Conf));
1930-
Seen.insert(Conf);
1929+
if (auto *PD = dyn_cast<ProtocolDecl>(NTD)) {
1930+
PD->walkInheritedProtocols([&](ProtocolDecl *inherited) {
1931+
if (PD != inherited && !Ctx.shouldIgnore(inherited)) {
1932+
ProtocolConformanceRef Conf(inherited);
1933+
auto ConfNode = SDKNodeInitInfo(Ctx, Conf)
1934+
.createSDKNode(SDKNodeKind::Conformance);
1935+
Root->addConformance(ConfNode);
1936+
}
1937+
1938+
return TypeWalker::Action::Continue;
1939+
});
1940+
} else {
1941+
// Avoid adding the same conformance twice.
1942+
SmallPtrSet<ProtocolConformance*, 4> Seen;
1943+
for (auto &Conf: NTD->getAllConformances()) {
1944+
if (!Ctx.shouldIgnore(Conf->getProtocol()) && !Seen.count(Conf))
1945+
Root->addConformance(constructConformanceNode(Conf));
1946+
Seen.insert(Conf);
1947+
}
19311948
}
19321949
}
19331950

test/api-digester/Outputs/cake-abi.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@
100100
"genericSig": "<τ_0_0 : cake.P1, τ_0_0 : cake.P2>",
101101
"sugared_genericSig": "<Self : cake.P1, Self : cake.P2>",
102102
"conformances": [
103-
{
104-
"kind": "Conformance",
105-
"name": "P2",
106-
"printedName": "P2",
107-
"usr": "s:4cake2P2P",
108-
"mangledName": "$s4cake2P2P"
109-
},
110103
{
111104
"kind": "Conformance",
112105
"name": "P1",
113106
"printedName": "P1",
114107
"usr": "s:4cake2P1P",
115108
"mangledName": "$s4cake2P1P"
109+
},
110+
{
111+
"kind": "Conformance",
112+
"name": "P2",
113+
"printedName": "P2",
114+
"usr": "s:4cake2P2P",
115+
"mangledName": "$s4cake2P2P"
116116
}
117117
]
118118
},

test/api-digester/Outputs/cake.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@
9898
"moduleName": "cake",
9999
"genericSig": "<Self : cake.P1, Self : cake.P2>",
100100
"conformances": [
101-
{
102-
"kind": "Conformance",
103-
"name": "P2",
104-
"printedName": "P2",
105-
"usr": "s:4cake2P2P",
106-
"mangledName": "$s4cake2P2P"
107-
},
108101
{
109102
"kind": "Conformance",
110103
"name": "P1",
111104
"printedName": "P1",
112105
"usr": "s:4cake2P1P",
113106
"mangledName": "$s4cake2P1P"
107+
},
108+
{
109+
"kind": "Conformance",
110+
"name": "P2",
111+
"printedName": "P2",
112+
"usr": "s:4cake2P2P",
113+
"mangledName": "$s4cake2P2P"
114114
}
115115
]
116116
},

0 commit comments

Comments
 (0)