Fix caching bug in MemoryBufferSerializedModuleLoader

By populating the memory cache before loading the module, we can avoid a cycle
where a module is imported that is an overlay, which then triggers
ClangImporter, which then (redundantly) triggers the import of the overlay
module, which would reimport the module again, since it's import is still
underway and it hasn't been entered into the cache yet.

rdar://118846313
This commit is contained in:
Adrian Prantl
2024-02-14 17:29:39 -08:00
parent 5ce824f042
commit 543a2cd685
14 changed files with 86 additions and 17 deletions

View File

@@ -381,7 +381,25 @@ int main(int argc, char **argv) {
auto *ClangImporter = static_cast<swift::ClangImporter *>(
CI.getASTContext().getClangModuleLoader());
ClangImporter->setDWARFImporterDelegate(dummyDWARFImporter);
}
}
if (Verbose)
CI.getASTContext().SetPreModuleImportCallback(
[&](llvm::StringRef module_name,
swift::ASTContext::ModuleImportKind kind) {
switch (kind) {
case swift::ASTContext::Module:
llvm::outs() << "Loading " << module_name.str() << "\n";
break;
case swift::ASTContext::Overlay:
llvm::outs() << "Loading (overlay) " << module_name.str() << "\n";
break;
case swift::ASTContext::BridgingHeader:
llvm::outs() << "Compiling bridging header: " << module_name.str()
<< "\n";
break;
}
});
llvm::SmallString<0> error;
llvm::raw_svector_ostream errs(error);
@@ -401,7 +419,7 @@ int main(int argc, char **argv) {
// Attempt to import all modules we found.
for (auto path : modules) {
if (Verbose)
llvm::outs() << "Importing " << path << "... ";
llvm::outs() << "Importing " << path << "...\n";
swift::ImportPath::Module::Builder modulePath;
#ifdef SWIFT_SUPPORTS_SUBMODULES
@@ -420,7 +438,7 @@ int main(int argc, char **argv) {
return 1;
}
if (Verbose)
llvm::outs() << "ok!\n";
llvm::outs() << "Import successful!\n";
if (DumpModule) {
llvm::SmallVector<swift::Decl*, 10> Decls;
Module->getTopLevelDecls(Decls);