Skip to content

Commit c455947

Browse files
committed
Swift: Assign indexes to extensions looking at all the extensions of a type
1 parent 463f79b commit c455947

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

swift/extractor/mangler/SwiftMangler.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,19 @@ unsigned SwiftMangler::getExtensionIndex(const swift::ExtensionDecl* decl,
112112
if (auto found = preloadedExtensionIndexes.extract(decl)) {
113113
return found.mapped();
114114
}
115-
if (auto parentModule = llvm::dyn_cast<swift::ModuleDecl>(parent)) {
116-
llvm::SmallVector<swift::Decl*> siblings;
117-
parentModule->getTopLevelDecls(siblings);
118-
indexExtensions(siblings);
119-
} else if (auto iterableParent = llvm::dyn_cast<swift::IterableDeclContext>(parent)) {
120-
indexExtensions(iterableParent->getAllMembers());
121-
} else {
122-
// TODO use a generic logging handle for Swift entities here, once it's available
123-
CODEQL_ASSERT(false, "non-local context must be module or iterable decl context");
115+
for (const auto& extension : decl->getExtendedNominal()->getExtensions()) {
116+
auto index = 0u;
117+
if (getParent(extension) == parent) {
118+
preloadedExtensionIndexes.emplace(extension, index);
119+
index++;
120+
}
124121
}
125122
auto found = preloadedExtensionIndexes.extract(decl);
126123
// TODO use a generic logging handle for Swift entities here, once it's available
127124
CODEQL_ASSERT(found, "extension not found within parent");
128125
return found.mapped();
129126
}
130127

131-
void SwiftMangler::indexExtensions(llvm::ArrayRef<swift::Decl*> siblings) {
132-
auto index = 0u;
133-
for (auto sibling : siblings) {
134-
if (sibling->getKind() == swift::DeclKind::Extension) {
135-
preloadedExtensionIndexes.emplace(sibling, index);
136-
}
137-
++index;
138-
}
139-
}
140-
141128
SwiftMangledName SwiftMangler::visitGenericTypeParamDecl(const swift::GenericTypeParamDecl* decl) {
142129
auto ret = visitValueDecl(decl, /*force=*/true);
143130
if (decl->isParameterPack()) {

swift/extractor/mangler/SwiftMangler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
112112
virtual SwiftMangledName fetch(const swift::TypeBase* type) = 0;
113113
SwiftMangledName fetch(swift::Type type) { return fetch(type.getPointer()); }
114114

115-
void indexExtensions(llvm::ArrayRef<swift::Decl*> siblings);
116115
unsigned int getExtensionIndex(const swift::ExtensionDecl* decl, const swift::Decl* parent);
117116
static SwiftMangledName initMangled(const swift::TypeBase* type);
118117
SwiftMangledName initMangled(const swift::Decl* decl);

0 commit comments

Comments
 (0)