@@ -19,43 +19,6 @@ Logger& logger() {
1919 return ret;
2020}
2121
22- const swift::ModuleDecl* getRealModuleOf (const swift::Decl* decl) {
23- auto * swiftModule = decl->getModuleContext ();
24- auto * clangModule = swiftModule->findUnderlyingClangModule ();
25-
26- if (!clangModule) {
27- return swiftModule;
28- }
29-
30- auto * clangModuleLoader = decl->getASTContext ().getClangModuleLoader ();
31-
32- if (!clangModuleLoader) {
33- return swiftModule;
34- }
35-
36- static std::unordered_map<const swift::Decl*, const swift::ModuleDecl*> cache;
37-
38- if (auto result = cache.find (decl); result != cache.end ()) {
39- return result->second ;
40- }
41-
42- for (const auto & submodule : clangModule->submodules ()) {
43- if (auto * swiftSubmodule = clangModuleLoader->getWrapperForModule (submodule)) {
44- llvm::SmallVector<swift::Decl*> children;
45- swiftSubmodule->getTopLevelDecls (children);
46- for (const auto child : children) {
47- cache[child] = swiftSubmodule;
48- }
49- }
50- }
51-
52- if (auto result = cache.find (decl); result != cache.end ()) {
53- return result->second ;
54- } else {
55- return swiftModule;
56- }
57- }
58-
5922const swift::Decl* getParent (const swift::Decl* decl) {
6023 auto context = decl->getDeclContext ();
6124 if (context->getContextKind () == swift::DeclContextKind::FileUnit) {
@@ -151,11 +114,13 @@ unsigned SwiftMangler::getExtensionIndex(const swift::ExtensionDecl* decl,
151114 if (auto found = preloadedExtensionIndexes.extract (decl)) {
152115 return found.mapped ();
153116 }
154- if (llvm::isa<swift::ModuleDecl>(parent)) {
155- auto * parentModule = getRealModuleOf (decl);
117+ if (const auto * parentModule = llvm::dyn_cast<swift::ModuleDecl>(parent)) {
156118 llvm::SmallVector<swift::Decl*> siblings;
157119 parentModule->getTopLevelDecls (siblings);
158120 indexExtensions (siblings);
121+ if (const auto * clangModule = parentModule->findUnderlyingClangModule ()) {
122+ indexClangExtensions (clangModule, decl->getASTContext ().getClangModuleLoader ());
123+ }
159124 } else if (auto iterableParent = llvm::dyn_cast<swift::IterableDeclContext>(parent)) {
160125 indexExtensions (iterableParent->getAllMembers ());
161126 } else {
@@ -173,8 +138,31 @@ void SwiftMangler::indexExtensions(llvm::ArrayRef<swift::Decl*> siblings) {
173138 for (auto sibling : siblings) {
174139 if (sibling->getKind () == swift::DeclKind::Extension) {
175140 preloadedExtensionIndexes.emplace (sibling, index);
141+ index += 3u ;
142+ }
143+ }
144+ }
145+
146+ void SwiftMangler::indexClangExtensions (const clang::Module* clangModule,
147+ swift::ClangModuleLoader* moduleLoader) {
148+ if (!moduleLoader) {
149+ return ;
150+ }
151+
152+ auto submoduleIndex = 5u ;
153+ for (const auto & submodule : clangModule->submodules ()) {
154+ auto index = submoduleIndex;
155+ if (auto * swiftSubmodule = moduleLoader->getWrapperForModule (submodule)) {
156+ llvm::SmallVector<swift::Decl*> children;
157+ swiftSubmodule->getTopLevelDecls (children);
158+ for (const auto child : children) {
159+ if (child->getKind () == swift::DeclKind::Extension) {
160+ preloadedExtensionIndexes.emplace (child, index);
161+ index += 7u ;
162+ }
163+ }
176164 }
177- ++index ;
165+ submoduleIndex += 5u ;
178166 }
179167}
180168
0 commit comments