Skip to content

Commit 4968857

Browse files
[BridgingHeaderChaining] Bind bridging header module when load module
When loading a module with embedded bridging header, bind the bridging header module in the context when bridging header auto chaining is used. This is because all the bridging header contents are chained into a PCH file so binary module with bridging header should reference the PCH file for all declarations. rdar://148538787 (cherry picked from commit 02ee2f4)
1 parent 7be7640 commit 4968857

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,16 @@ class ClangImporter final : public ClangModuleLoader {
428428
bool trackParsedSymbols = false,
429429
bool implicitImport = false);
430430

431+
/// Bind the bridging header content to the module.
432+
///
433+
/// \param adapter The module that depends on the contents of this header.
434+
/// \param diagLoc A location to attach any diagnostics to if import fails.
435+
///
436+
/// \returns true if there was an error importing the header.
437+
///
438+
/// \sa importBridgingHeader
439+
bool bindBridgingHeader(ModuleDecl *adapter, SourceLoc diagLoc);
440+
431441
/// Returns the module that contains imports and declarations from all loaded
432442
/// Objective-C header files.
433443
///

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,12 +1869,7 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter,
18691869
bool trackParsedSymbols,
18701870
bool implicitImport) {
18711871
if (isPCHFilenameExtension(header)) {
1872-
Impl.ImportedHeaderOwners.push_back(adapter);
1873-
// We already imported this with -include-pch above, so we should have
1874-
// collected a bunch of PCH-encoded module imports that we just need to
1875-
// replay in handleDeferredImports.
1876-
Impl.handleDeferredImports(diagLoc);
1877-
return false;
1872+
return bindBridgingHeader(adapter, diagLoc);
18781873
}
18791874

18801875
clang::FileManager &fileManager = Impl.Instance->getFileManager();
@@ -1901,6 +1896,15 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter,
19011896
std::move(sourceBuffer), implicitImport);
19021897
}
19031898

1899+
bool ClangImporter::bindBridgingHeader(ModuleDecl *adapter, SourceLoc diagLoc) {
1900+
Impl.ImportedHeaderOwners.push_back(adapter);
1901+
// We already imported this with -include-pch above, so we should have
1902+
// collected a bunch of PCH-encoded module imports that we just need to
1903+
// replay in handleDeferredImports.
1904+
Impl.handleDeferredImports(diagLoc);
1905+
return false;
1906+
}
1907+
19041908
static llvm::Expected<llvm::cas::ObjectRef>
19051909
setupIncludeTreeInput(clang::CompilerInvocation &invocation,
19061910
StringRef headerPath, StringRef pchIncludeTree) {

lib/Serialization/ModuleFile.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,18 @@ ModuleFile::loadDependenciesForFileContext(const FileUnit *file,
165165
if (dependency.isHeader()) {
166166
// The path may be empty if the file being loaded is a partial AST,
167167
// and the current compiler invocation is a merge-modules step.
168-
if (!dependency.Core.RawPath.empty() &&
169-
!M->getASTContext().SearchPathOpts.BridgingHeaderChaining) {
168+
if (!dependency.Core.RawPath.empty()) {
169+
// If using bridging header chaining, just bind the entire bridging
170+
// header pch to the module. Otherwise, import the header.
170171
bool hadError =
171-
clangImporter->importHeader(dependency.Core.RawPath,
172-
file->getParentModule(),
173-
Core->importedHeaderInfo.fileSize,
174-
Core->importedHeaderInfo.fileModTime,
175-
Core->importedHeaderInfo.contents,
176-
diagLoc);
172+
M->getASTContext().SearchPathOpts.BridgingHeaderChaining
173+
? clangImporter->bindBridgingHeader(file->getParentModule(),
174+
diagLoc)
175+
: clangImporter->importHeader(
176+
dependency.Core.RawPath, file->getParentModule(),
177+
Core->importedHeaderInfo.fileSize,
178+
Core->importedHeaderInfo.fileModTime,
179+
Core->importedHeaderInfo.contents, diagLoc);
177180
if (hadError)
178181
return error(Status::FailedToLoadBridgingHeader);
179182
}

test/ScanDependencies/bridging-header-autochaining.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ extension A {
188188
public func testA() {}
189189
}
190190

191+
public class AB : B {}
192+
191193
//--- user2.swift
192194
import Test
193195

0 commit comments

Comments
 (0)