@@ -98,46 +98,31 @@ SwiftMangledName SwiftMangler::visitExtensionDecl(const swift::ExtensionDecl* de
9898 return {};
9999 }
100100
101- auto parent = getParent (decl);
102101 auto target = decl->getExtendedType ();
103- return initMangled (decl) << fetch (target) << getExtensionIndex (decl, parent );
102+ return initMangled (decl) << fetch (target) << getExtensionIndex (decl);
104103}
105104
106- unsigned SwiftMangler::getExtensionIndex (const swift::ExtensionDecl* decl,
107- const swift::Decl* parent) {
105+ unsigned SwiftMangler::getExtensionIndex (const swift::ExtensionDecl* decl) {
108106 // to avoid iterating multiple times on the parent of multiple extensions, we preload extension
109107 // indexes once for each encountered parent into the `preloadedExtensionIndexes` mapping.
110108 // Because we mangle declarations only once in a given trap/dispatcher context, we can safely
111109 // discard preloaded indexes on use
112110 if (auto found = preloadedExtensionIndexes.extract (decl)) {
113111 return found.mapped ();
114112 }
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" );
113+ for (const auto & sibling : decl->getExtendedNominal ()->getExtensions ()) {
114+ auto index = 0u ;
115+ if (sibling->getDeclContext () == decl->getDeclContext ()) {
116+ preloadedExtensionIndexes.emplace (sibling, index);
117+ index++;
118+ }
124119 }
125120 auto found = preloadedExtensionIndexes.extract (decl);
126121 // TODO use a generic logging handle for Swift entities here, once it's available
127122 CODEQL_ASSERT (found, " extension not found within parent" );
128123 return found.mapped ();
129124}
130125
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-
141126SwiftMangledName SwiftMangler::visitGenericTypeParamDecl (const swift::GenericTypeParamDecl* decl) {
142127 auto ret = visitValueDecl (decl, /* force=*/ true );
143128 if (decl->isParameterPack ()) {
0 commit comments