mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #17186 from jrose-apple/bridge-over-troubled-imports
[Serialization] Always list the bridging header before any imports rdar://problem/40471329
This commit is contained in:
@@ -1062,28 +1062,38 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
|
||||
publicImportSet.insert(publicImports.begin(), publicImports.end());
|
||||
|
||||
removeDuplicateImports(allImports);
|
||||
|
||||
auto clangImporter =
|
||||
static_cast<ClangImporter *>(M->getASTContext().getClangModuleLoader());
|
||||
ModuleDecl *importedHeaderModule = clangImporter->getImportedHeaderModule();
|
||||
ModuleDecl *bridgingHeaderModule = clangImporter->getImportedHeaderModule();
|
||||
ModuleDecl::ImportedModule bridgingHeaderImport{{}, bridgingHeaderModule};
|
||||
|
||||
// Make sure the bridging header module is always at the top of the import
|
||||
// list, mimicking how it is processed before any module imports when
|
||||
// compiling source files.
|
||||
if (llvm::is_contained(allImports, bridgingHeaderImport)) {
|
||||
off_t importedHeaderSize = 0;
|
||||
time_t importedHeaderModTime = 0;
|
||||
std::string contents;
|
||||
if (!options.ImportedHeader.empty()) {
|
||||
contents = clangImporter->getBridgingHeaderContents(
|
||||
options.ImportedHeader, importedHeaderSize, importedHeaderModTime);
|
||||
}
|
||||
assert(publicImportSet.count(bridgingHeaderImport));
|
||||
ImportedHeader.emit(ScratchRecord,
|
||||
publicImportSet.count(bridgingHeaderImport),
|
||||
importedHeaderSize, importedHeaderModTime,
|
||||
options.ImportedHeader);
|
||||
if (!contents.empty()) {
|
||||
contents.push_back('\0');
|
||||
ImportedHeaderContents.emit(ScratchRecord, contents);
|
||||
}
|
||||
}
|
||||
|
||||
ModuleDecl *theBuiltinModule = M->getASTContext().TheBuiltinModule;
|
||||
for (auto import : allImports) {
|
||||
if (import.second == theBuiltinModule)
|
||||
continue;
|
||||
|
||||
if (import.second == importedHeaderModule) {
|
||||
off_t importedHeaderSize = 0;
|
||||
time_t importedHeaderModTime = 0;
|
||||
std::string contents;
|
||||
if (!options.ImportedHeader.empty())
|
||||
contents = clangImporter->getBridgingHeaderContents(
|
||||
options.ImportedHeader, importedHeaderSize, importedHeaderModTime);
|
||||
ImportedHeader.emit(ScratchRecord, publicImportSet.count(import),
|
||||
importedHeaderSize, importedHeaderModTime,
|
||||
options.ImportedHeader);
|
||||
if (!contents.empty()) {
|
||||
contents.push_back('\0');
|
||||
ImportedHeaderContents.emit(ScratchRecord, contents);
|
||||
}
|
||||
if (import.second == theBuiltinModule ||
|
||||
import.second == bridgingHeaderModule) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user