add support to getTopLevelDecls for clang submodules (#76401)

rdar://126031510
This commit is contained in:
QuietMisdreavus
2025-01-30 09:39:58 -07:00
committed by GitHub
parent b3275d9db3
commit ab26b8b9d7
23 changed files with 693 additions and 277 deletions

View File

@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/DeclObjC.h"
#include "clang/Basic/Module.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Comment.h"
#include "swift/AST/Decl.h"
@@ -624,14 +625,14 @@ void SymbolGraph::serialize(llvm::json::OStream &OS) {
OS.attributeObject("module", [&](){
if (DeclaringModule) {
// A cross-import overlay can be considered part of its declaring module
OS.attribute("name", (*DeclaringModule)->getNameStr());
OS.attribute("name", getFullModuleName(*DeclaringModule));
std::vector<StringRef> B;
for (auto BModule : BystanderModules) {
B.push_back(BModule.str());
}
OS.attribute("bystanders", B);
} else {
OS.attribute("name", M.getNameStr());
OS.attribute("name", getFullModuleName(&M));
}
AttributeRAII Platform("platform", OS);
@@ -896,7 +897,15 @@ bool SymbolGraph::canIncludeDeclAsNode(const Decl *D,
// If this decl isn't in this module or module that this module imported with `@_exported`, don't record it,
// as it will appear elsewhere in its module's symbol graph.
if (D->getModuleContext()->getName() != M.getName() && !Walker.isConsideredExportedImported(D)) {
// If a Clang decl was declared in a submodule, the Swift decl's context will still point to the
// top-level module. Instead, we need to probe the owning module on the Clang side, which will
// correctly point to the submodule.
auto RealModuleName = (std::string)D->getModuleContext()->getName();
if (auto *ClangDecl = D->getClangDecl())
if (auto *ClangModule = ClangDecl->getOwningModule())
RealModuleName = ClangModule->Name;
if (RealModuleName != (std::string)M.getName() && !Walker.isConsideredExportedImported(D)) {
return false;
}