2121using namespace swift ;
2222using namespace symbolgraphgen ;
2323
24+ namespace {
25+
26+ // / Compare the two \c ModuleDecl instances to see whether they are the same.
27+ // /
28+ // / Pass \c true to the \c ignoreUnderlying argument to consider two modules the same even if
29+ // / one is a Swift module and the other a non-Swift module. This allows a Swift module and its
30+ // / underlying Clang module to compare as equal.
31+ bool areModulesEqual (const ModuleDecl *lhs, const ModuleDecl *rhs, bool ignoreUnderlying = false ) {
32+ return lhs->getNameStr () == rhs->getNameStr ()
33+ && (ignoreUnderlying || lhs->isNonSwiftModule () == rhs->isNonSwiftModule ());
34+ }
35+
36+ } // anonymous namespace
37+
2438SymbolGraphASTWalker::SymbolGraphASTWalker (ModuleDecl &M,
2539 const SmallPtrSet<ModuleDecl *, 4 > ExportedImportedModules,
2640 const SymbolGraphOptions &Options)
@@ -45,10 +59,10 @@ SymbolGraph *SymbolGraphASTWalker::getModuleSymbolGraph(const Decl *D) {
4559 }
4660 }
4761
48- if (this ->M . getNameStr (). equals (M-> getNameStr () )) {
62+ if (areModulesEqual (& this ->M , M, true )) {
4963 return &MainGraph;
5064 } else if (MainGraph.DeclaringModule .hasValue () &&
51- MainGraph.DeclaringModule .getValue ()-> getNameStr (). equals (M-> getNameStr () )) {
65+ areModulesEqual ( MainGraph.DeclaringModule .getValue (), M, true )) {
5266 // Cross-import overlay modules already appear as "extensions" of their declaring module; we
5367 // should put actual extensions of that module into the main graph
5468 return &MainGraph;
@@ -220,6 +234,6 @@ bool SymbolGraphASTWalker::isFromExportedImportedModule(const Decl* D) const {
220234 auto *M = D->getModuleContext ();
221235
222236 return llvm::any_of (ExportedImportedModules, [&M](const auto *MD) {
223- return M-> getNameStr (). equals ( MD->getModuleContext ()-> getNameStr ());
237+ return areModulesEqual (M, MD->getModuleContext ());
224238 });
225239}
0 commit comments