Skip to content

Commit fc20deb

Browse files
committed
Jump through hoops to avoid adding a new Serialization -> clang::Module dependency.
1 parent 21e34d7 commit fc20deb

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

include/swift/ClangImporter/ClangModule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class ClangModuleUnit final : public LoadedFile {
5656
/// Returns the Swift module that overlays this Clang module.
5757
ModuleDecl *getAdapterModule() const;
5858

59+
/// Retrieve the "exported" name of the module, which is usually the module
60+
/// name, but might be the name of the public module through which this
61+
/// (private) module is re-exported.
62+
std::string getExportedModuleName() const;
63+
5964
virtual bool isSystemModule() const override;
6065

6166
virtual void lookupValue(ModuleDecl::AccessPathTy accessPath,

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,13 @@ clang::ASTContext &ClangModuleUnit::getClangASTContext() const {
28592859
return owner.getClangASTContext();
28602860
}
28612861

2862+
std::string ClangModuleUnit::getExportedModuleName() const {
2863+
if (clangModule && !clangModule->ExportAsModule.empty())
2864+
return clangModule->ExportAsModule;
2865+
2866+
return getParentModule()->getName().str();
2867+
}
2868+
28622869
ModuleDecl *ClangModuleUnit::getAdapterModule() const {
28632870
if (!clangModule)
28642871
return nullptr;

lib/Serialization/ModuleFile.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include "swift/AST/USRGeneration.h"
2222
#include "swift/Basic/Range.h"
2323
#include "swift/ClangImporter/ClangImporter.h"
24+
#include "swift/ClangImporter/ClangModule.h"
2425
#include "swift/Serialization/BCReadingExtras.h"
2526
#include "swift/Serialization/SerializedModuleLoader.h"
26-
#include "clang/Basic/Module.h"
2727
#include "llvm/ADT/StringExtras.h"
2828
#include "llvm/Support/MemoryBuffer.h"
2929
#include "llvm/Support/OnDiskHashTable.h"
@@ -1562,18 +1562,20 @@ void ModuleFile::loadExtensions(NominalTypeDecl *nominal) {
15621562
}
15631563

15641564
if (nominal->getParent()->isModuleScopeContext()) {
1565-
Identifier moduleName = nominal->getParentModule()->getName();
1565+
auto parentModule = nominal->getParentModule();
1566+
StringRef moduleName = parentModule->getName().str();
15661567

15671568
// If the originating module is a private module whose interface is
15681569
// re-exported via public module, check the name of the public module.
1569-
if (auto clangModule
1570-
= nominal->getParentModule()->findUnderlyingClangModule()) {
1571-
if (!clangModule->ExportAsModule.empty())
1572-
moduleName = getContext().getIdentifier(clangModule->ExportAsModule);
1570+
std::string exportedModuleName;
1571+
if (auto clangModuleUnit =
1572+
dyn_cast<ClangModuleUnit>(parentModule->getFiles().front())) {
1573+
exportedModuleName = clangModuleUnit->getExportedModuleName();
1574+
moduleName = exportedModuleName;
15731575
}
15741576

15751577
for (auto item : *iter) {
1576-
if (item.first != moduleName.str())
1578+
if (item.first != moduleName)
15771579
continue;
15781580
Expected<Decl *> declOrError = getDeclChecked(item.second);
15791581
if (!declOrError) {

0 commit comments

Comments
 (0)