Skip to content

Commit ca38efd

Browse files
committed
Test
1 parent 5f58346 commit ca38efd

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

swift/extractor/mangler/SwiftMangler.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Logger& logger() {
1919
return ret;
2020
}
2121

22-
std::unordered_map<const swift::Decl*, unsigned> preloadedExtensionIndexes;
23-
2422
const swift::Decl* getParent(const swift::Decl* decl) {
2523
auto context = decl->getDeclContext();
2624
if (context->getContextKind() == swift::DeclContextKind::FileUnit) {
@@ -42,6 +40,8 @@ std::string_view getTypeKindStr(const swift::TypeBase* type) {
4240

4341
} // namespace
4442

43+
std::unordered_map<const swift::Decl*, unsigned> SwiftMangler::preloadedExtensionIndexes;
44+
4545
SwiftMangledName SwiftMangler::initMangled(const swift::TypeBase* type) {
4646
return {getTypeKindStr(type), '_'};
4747
}
@@ -113,38 +113,35 @@ unsigned SwiftMangler::getExtensionIndex(const swift::ExtensionDecl* decl,
113113
// indexes once for each encountered parent into the `preloadedExtensionIndexes` mapping.
114114
// Because we mangle declarations only once in a given trap/dispatcher context, we can safely
115115
// discard preloaded indexes on use
116-
if (auto found = preloadedExtensionIndexes.find(decl); found != preloadedExtensionIndexes.end()) {
116+
if (auto found = SwiftMangler::preloadedExtensionIndexes.find(decl);
117+
found != SwiftMangler::preloadedExtensionIndexes.end()) {
117118
return found->second;
118119
}
119120
if (const auto* parentModule = llvm::dyn_cast<swift::ModuleDecl>(parent)) {
120121
llvm::SmallVector<swift::Decl*> siblings;
121122
parentModule->getTopLevelDecls(siblings);
122123
indexExtensions(siblings);
123124
if (const auto* clangModule = parentModule->findUnderlyingClangModule()) {
124-
fprintf(stderr, "\nXXX 1 %p\n", decl);
125-
decl->dump();
126125
indexClangExtensions(clangModule, decl->getASTContext().getClangModuleLoader());
127-
fprintf(stderr, "\nXXX 2\n");
128126
}
129127
} else if (auto iterableParent = llvm::dyn_cast<swift::IterableDeclContext>(parent)) {
130128
indexExtensions(iterableParent->getAllMembers());
131129
} else {
132130
// TODO use a generic logging handle for Swift entities here, once it's available
133131
CODEQL_ASSERT(false, "non-local context must be module or iterable decl context");
134132
}
135-
if (auto found = preloadedExtensionIndexes.find(decl); found != preloadedExtensionIndexes.end()) {
136-
return found->second;
137-
} else {
138-
// TODO use a generic logging handle for Swift entities here, once it's available
139-
CODEQL_ASSERT(false, "extension not found within parent");
140-
}
133+
auto found = SwiftMangler::preloadedExtensionIndexes.find(decl);
134+
// TODO use a generic logging handle for Swift entities here, once it's available
135+
CODEQL_ASSERT(found != SwiftMangler::preloadedExtensionIndexes.end(),
136+
"extension not found within parent");
137+
return found->second;
141138
}
142139

143140
void SwiftMangler::indexExtensions(llvm::ArrayRef<swift::Decl*> siblings) {
144141
auto index = 0u;
145142
for (auto sibling : siblings) {
146143
if (sibling->getKind() == swift::DeclKind::Extension) {
147-
preloadedExtensionIndexes.emplace(sibling, index);
144+
SwiftMangler::preloadedExtensionIndexes.emplace(sibling, index);
148145
index += 3u;
149146
}
150147
}
@@ -164,7 +161,7 @@ void SwiftMangler::indexClangExtensions(const clang::Module* clangModule,
164161
swiftSubmodule->getTopLevelDecls(children);
165162
for (const auto child : children) {
166163
if (child->getKind() == swift::DeclKind::Extension) {
167-
preloadedExtensionIndexes.emplace(child, index);
164+
SwiftMangler::preloadedExtensionIndexes.emplace(child, index);
168165
index += 7u;
169166
}
170167
}

swift/extractor/mangler/SwiftMangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
106106
SwiftMangledName visitPackExpansionType(const swift::PackExpansionType* type);
107107

108108
private:
109+
static std::unordered_map<const swift::Decl*, unsigned> preloadedExtensionIndexes;
110+
109111
virtual SwiftMangledName fetch(const swift::Decl* decl) = 0;
110112
virtual SwiftMangledName fetch(const swift::TypeBase* type) = 0;
111113
SwiftMangledName fetch(swift::Type type) { return fetch(type.getPointer()); }

0 commit comments

Comments
 (0)