@@ -112,32 +112,21 @@ 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+
116+ auto index = 0u ;
117+ for (const auto & extension : decl->getExtendedNominal ()->getExtensions ()) {
118+ if (getParent (extension) == parent) {
119+ preloadedExtensionIndexes.emplace (extension, index);
120+ index++;
121+ }
124122 }
123+
125124 auto found = preloadedExtensionIndexes.extract (decl);
126125 // TODO use a generic logging handle for Swift entities here, once it's available
127126 CODEQL_ASSERT (found, " extension not found within parent" );
128127 return found.mapped ();
129128}
130129
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-
141130SwiftMangledName SwiftMangler::visitGenericTypeParamDecl (const swift::GenericTypeParamDecl* decl) {
142131 auto ret = visitValueDecl (decl, /* force=*/ true );
143132 if (decl->isParameterPack ()) {
0 commit comments