@@ -19,6 +19,8 @@ Logger& logger() {
1919 return ret;
2020}
2121
22+ std::unordered_map<const swift::Decl*, unsigned > preloadedExtensionIndexes;
23+
2224const swift::Decl* getParent (const swift::Decl* decl) {
2325 auto context = decl->getDeclContext ();
2426 if (context->getContextKind () == swift::DeclContextKind::FileUnit) {
@@ -111,26 +113,31 @@ unsigned SwiftMangler::getExtensionIndex(const swift::ExtensionDecl* decl,
111113 // indexes once for each encountered parent into the `preloadedExtensionIndexes` mapping.
112114 // Because we mangle declarations only once in a given trap/dispatcher context, we can safely
113115 // discard preloaded indexes on use
114- if (auto found = preloadedExtensionIndexes.extract (decl)) {
115- return found. mapped () ;
116+ if (auto found = preloadedExtensionIndexes.find (decl); found != preloadedExtensionIndexes. end ( )) {
117+ return found-> second ;
116118 }
117119 if (const auto * parentModule = llvm::dyn_cast<swift::ModuleDecl>(parent)) {
118120 llvm::SmallVector<swift::Decl*> siblings;
119121 parentModule->getTopLevelDecls (siblings);
120122 indexExtensions (siblings);
121123 if (const auto * clangModule = parentModule->findUnderlyingClangModule ()) {
124+ fprintf (stderr, " \n XXX 1 %p\n " , decl);
125+ decl->dump ();
122126 indexClangExtensions (clangModule, decl->getASTContext ().getClangModuleLoader ());
127+ fprintf (stderr, " \n XXX 2\n " );
123128 }
124129 } else if (auto iterableParent = llvm::dyn_cast<swift::IterableDeclContext>(parent)) {
125130 indexExtensions (iterableParent->getAllMembers ());
126131 } else {
127132 // TODO use a generic logging handle for Swift entities here, once it's available
128133 CODEQL_ASSERT (false , " non-local context must be module or iterable decl context" );
129134 }
130- auto found = preloadedExtensionIndexes.extract (decl);
131- // TODO use a generic logging handle for Swift entities here, once it's available
132- CODEQL_ASSERT (found, " extension not found within parent" );
133- return found.mapped ();
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+ }
134141}
135142
136143void SwiftMangler::indexExtensions (llvm::ArrayRef<swift::Decl*> siblings) {
0 commit comments