|
18 | 18 | #ifndef SWIFT_SIL_SILVTABLEVISITOR_H |
19 | 19 | #define SWIFT_SIL_SILVTABLEVISITOR_H |
20 | 20 |
|
21 | | -#include <string> |
22 | | - |
23 | 21 | #include "swift/AST/Decl.h" |
24 | 22 | #include "swift/AST/Types.h" |
25 | | -#include "swift/AST/ASTMangler.h" |
26 | 23 |
|
27 | 24 | namespace swift { |
28 | 25 |
|
29 | | -// Utility class for deterministically ordering vtable entries for |
30 | | -// synthesized methods. |
31 | | -struct SortedFuncList { |
32 | | - using Entry = std::pair<std::string, AbstractFunctionDecl *>; |
33 | | - SmallVector<Entry, 2> elts; |
34 | | - bool sorted = false; |
35 | | - |
36 | | - void add(AbstractFunctionDecl *afd) { |
37 | | - Mangle::ASTMangler mangler; |
38 | | - std::string mangledName; |
39 | | - if (auto *cd = dyn_cast<ConstructorDecl>(afd)) |
40 | | - mangledName = mangler.mangleConstructorEntity(cd, 0); |
41 | | - else |
42 | | - mangledName = mangler.mangleEntity(afd); |
43 | | - |
44 | | - elts.push_back(std::make_pair(mangledName, afd)); |
45 | | - } |
46 | | - |
47 | | - bool empty() { return elts.empty(); } |
48 | | - |
49 | | - void sort() { |
50 | | - assert(!sorted); |
51 | | - sorted = true; |
52 | | - std::sort(elts.begin(), |
53 | | - elts.end(), |
54 | | - [](const Entry &lhs, const Entry &rhs) -> bool { |
55 | | - return lhs.first < rhs.first; |
56 | | - }); |
57 | | - } |
58 | | - |
59 | | - decltype(elts)::const_iterator begin() const { |
60 | | - assert(sorted); |
61 | | - return elts.begin(); |
62 | | - } |
63 | | - |
64 | | - decltype(elts)::const_iterator end() const { |
65 | | - assert(sorted); |
66 | | - return elts.end(); |
67 | | - } |
68 | | -}; |
69 | | - |
70 | 26 | /// A CRTP class for visiting virtually-dispatched methods of a class. |
71 | 27 | /// |
72 | 28 | /// You must override these two methods in your subclass: |
@@ -192,33 +148,8 @@ template <class T> class SILVTableVisitor { |
192 | 148 | if (!theClass->hasKnownSwiftImplementation()) |
193 | 149 | return; |
194 | 150 |
|
195 | | - // Note that while vtable order is not ABI, we still want it to be |
196 | | - // consistent between translation units. |
197 | | - // |
198 | | - // So, sort synthesized members by their mangled name, since they |
199 | | - // are added lazily during type checking, with the remaining ones |
200 | | - // forced at the end. |
201 | | - SortedFuncList synthesizedMembers; |
202 | | - |
203 | | - for (auto member : theClass->getEmittedMembers()) { |
204 | | - if (auto *afd = dyn_cast<AbstractFunctionDecl>(member)) { |
205 | | - if (afd->isSynthesized()) { |
206 | | - synthesizedMembers.add(afd); |
207 | | - continue; |
208 | | - } |
209 | | - } |
210 | | - |
| 151 | + for (auto member : theClass->getEmittedMembers()) |
211 | 152 | maybeAddMember(member); |
212 | | - } |
213 | | - |
214 | | - if (synthesizedMembers.empty()) |
215 | | - return; |
216 | | - |
217 | | - synthesizedMembers.sort(); |
218 | | - |
219 | | - for (const auto &pair : synthesizedMembers) { |
220 | | - maybeAddMember(pair.second); |
221 | | - } |
222 | 153 | } |
223 | 154 | }; |
224 | 155 |
|
|
0 commit comments