mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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
This commit is contained in:
@@ -428,6 +428,16 @@ public:
|
|||||||
bool trackParsedSymbols = false,
|
bool trackParsedSymbols = false,
|
||||||
bool implicitImport = false);
|
bool implicitImport = false);
|
||||||
|
|
||||||
|
/// Bind the bridging header content to the module.
|
||||||
|
///
|
||||||
|
/// \param adapter The module that depends on the contents of this header.
|
||||||
|
/// \param diagLoc A location to attach any diagnostics to if import fails.
|
||||||
|
///
|
||||||
|
/// \returns true if there was an error importing the header.
|
||||||
|
///
|
||||||
|
/// \sa importBridgingHeader
|
||||||
|
bool bindBridgingHeader(ModuleDecl *adapter, SourceLoc diagLoc);
|
||||||
|
|
||||||
/// Returns the module that contains imports and declarations from all loaded
|
/// Returns the module that contains imports and declarations from all loaded
|
||||||
/// Objective-C header files.
|
/// Objective-C header files.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1869,12 +1869,7 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter,
|
|||||||
bool trackParsedSymbols,
|
bool trackParsedSymbols,
|
||||||
bool implicitImport) {
|
bool implicitImport) {
|
||||||
if (isPCHFilenameExtension(header)) {
|
if (isPCHFilenameExtension(header)) {
|
||||||
Impl.ImportedHeaderOwners.push_back(adapter);
|
return bindBridgingHeader(adapter, diagLoc);
|
||||||
// We already imported this with -include-pch above, so we should have
|
|
||||||
// collected a bunch of PCH-encoded module imports that we just need to
|
|
||||||
// replay in handleDeferredImports.
|
|
||||||
Impl.handleDeferredImports(diagLoc);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clang::FileManager &fileManager = Impl.Instance->getFileManager();
|
clang::FileManager &fileManager = Impl.Instance->getFileManager();
|
||||||
@@ -1901,6 +1896,15 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter,
|
|||||||
std::move(sourceBuffer), implicitImport);
|
std::move(sourceBuffer), implicitImport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ClangImporter::bindBridgingHeader(ModuleDecl *adapter, SourceLoc diagLoc) {
|
||||||
|
Impl.ImportedHeaderOwners.push_back(adapter);
|
||||||
|
// We already imported this with -include-pch above, so we should have
|
||||||
|
// collected a bunch of PCH-encoded module imports that we just need to
|
||||||
|
// replay in handleDeferredImports.
|
||||||
|
Impl.handleDeferredImports(diagLoc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static llvm::Expected<llvm::cas::ObjectRef>
|
static llvm::Expected<llvm::cas::ObjectRef>
|
||||||
setupIncludeTreeInput(clang::CompilerInvocation &invocation,
|
setupIncludeTreeInput(clang::CompilerInvocation &invocation,
|
||||||
StringRef headerPath, StringRef pchIncludeTree) {
|
StringRef headerPath, StringRef pchIncludeTree) {
|
||||||
|
|||||||
@@ -165,15 +165,18 @@ ModuleFile::loadDependenciesForFileContext(const FileUnit *file,
|
|||||||
if (dependency.isHeader()) {
|
if (dependency.isHeader()) {
|
||||||
// The path may be empty if the file being loaded is a partial AST,
|
// The path may be empty if the file being loaded is a partial AST,
|
||||||
// and the current compiler invocation is a merge-modules step.
|
// and the current compiler invocation is a merge-modules step.
|
||||||
if (!dependency.Core.RawPath.empty() &&
|
if (!dependency.Core.RawPath.empty()) {
|
||||||
!M->getASTContext().SearchPathOpts.BridgingHeaderChaining) {
|
// If using bridging header chaining, just bind the entire bridging
|
||||||
|
// header pch to the module. Otherwise, import the header.
|
||||||
bool hadError =
|
bool hadError =
|
||||||
clangImporter->importHeader(dependency.Core.RawPath,
|
M->getASTContext().SearchPathOpts.BridgingHeaderChaining
|
||||||
file->getParentModule(),
|
? clangImporter->bindBridgingHeader(file->getParentModule(),
|
||||||
Core->importedHeaderInfo.fileSize,
|
diagLoc)
|
||||||
Core->importedHeaderInfo.fileModTime,
|
: clangImporter->importHeader(
|
||||||
Core->importedHeaderInfo.contents,
|
dependency.Core.RawPath, file->getParentModule(),
|
||||||
diagLoc);
|
Core->importedHeaderInfo.fileSize,
|
||||||
|
Core->importedHeaderInfo.fileModTime,
|
||||||
|
Core->importedHeaderInfo.contents, diagLoc);
|
||||||
if (hadError)
|
if (hadError)
|
||||||
return error(Status::FailedToLoadBridgingHeader);
|
return error(Status::FailedToLoadBridgingHeader);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,6 +180,8 @@ extension A {
|
|||||||
public func testA() {}
|
public func testA() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AB : B {}
|
||||||
|
|
||||||
//--- user2.swift
|
//--- user2.swift
|
||||||
import Test
|
import Test
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user