Skip to content

Commit 1a66c89

Browse files
committed
SIL: Remove CHA's unused 'protocol implementations' analysis
This was performing a walk over all parsed Decls in all sources files, to build a data structure that was never used.
1 parent ba58d3c commit 1a66c89

File tree

2 files changed

+0
-51
lines changed

2 files changed

+0
-51
lines changed

include/swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ class ClassHierarchyAnalysis : public SILAnalysis {
8080
return IndirectSubclassesCache[C];
8181
}
8282

83-
const NominalTypeList &getProtocolImplementations(ProtocolDecl *P) {
84-
return ProtocolImplementationsCache[P];
85-
}
86-
8783
/// Returns true if the class is inherited by another class in this module.
8884
bool hasKnownDirectSubclasses(ClassDecl *C) {
8985
return DirectSubclassesCache.count(C);
@@ -96,11 +92,6 @@ class ClassHierarchyAnalysis : public SILAnalysis {
9692
!IndirectSubclassesCache[C].empty();
9793
}
9894

99-
/// Returns true if the protocol is implemented by any class in this module.
100-
bool hasKnownImplementations(ProtocolDecl *C) {
101-
return ProtocolImplementationsCache.count(C);
102-
}
103-
10495
private:
10596
/// Compute inheritance properties.
10697
void init();
@@ -114,9 +105,6 @@ class ClassHierarchyAnalysis : public SILAnalysis {
114105

115106
/// A cache that maps a class to all of its known indirect subclasses.
116107
llvm::DenseMap<ClassDecl*, ClassList> IndirectSubclassesCache;
117-
118-
/// A cache that maps a protocol to all of its known implementations.
119-
ProtocolImplementations ProtocolImplementationsCache;
120108
};
121109

122110
}

lib/SILOptimizer/Analysis/ClassHierarchyAnalysis.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,14 @@
1212

1313
#include "swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h"
1414
#include "swift/AST/ASTContext.h"
15-
#include "swift/AST/ASTWalker.h"
1615
#include "swift/AST/Module.h"
1716
#include "swift/SIL/SILInstruction.h"
1817
#include "swift/SIL/SILValue.h"
1918
#include "swift/SIL/SILModule.h"
2019

2120
using namespace swift;
2221

23-
namespace {
24-
/// A helper class to collect all nominal type declarations.
25-
class NominalTypeWalker: public ASTWalker {
26-
ClassHierarchyAnalysis::ProtocolImplementations &ProtocolImplementationsCache;
27-
public:
28-
NominalTypeWalker(ClassHierarchyAnalysis::ProtocolImplementations
29-
&ProtocolImplementationsCache)
30-
:ProtocolImplementationsCache(ProtocolImplementationsCache) {
31-
}
32-
33-
bool walkToDeclPre(Decl *D) override {
34-
auto *NTD = dyn_cast<NominalTypeDecl>(D);
35-
if (!NTD || !NTD->hasInterfaceType())
36-
return true;
37-
auto Protocols = NTD->getAllProtocols();
38-
// We are only interested in types implementing protocols.
39-
if (!Protocols.empty()) {
40-
for (auto &Protocol : Protocols) {
41-
auto &K = ProtocolImplementationsCache[Protocol];
42-
K.push_back(NTD);
43-
}
44-
}
45-
return true;
46-
}
47-
};
48-
} // end anonymous namespace
49-
5022
void ClassHierarchyAnalysis::init() {
51-
// Process all types implementing protocols.
52-
SmallVector<Decl *, 32> Decls;
53-
// TODO: It would be better if we could get all declarations
54-
// from a given module, not only the top-level ones.
55-
M->getSwiftModule()->getTopLevelDecls(Decls);
56-
57-
NominalTypeWalker Walker(ProtocolImplementationsCache);
58-
for (auto *D: Decls) {
59-
D->walk(Walker);
60-
}
61-
6223
// For each class declaration in our V-table list:
6324
for (auto &VT : M->getVTableList()) {
6425
ClassDecl *C = VT.getClass();

0 commit comments

Comments
 (0)