Skip to content

Commit bc2590d

Browse files
[lldb] Improve swift clang importer when explicit module missing
Instead of dropping all explicit modules when found one module is missing, only drop the ones that are missing. In this case, the implicit build will only fill in the missing ones, rather than rebuild everything. (cherry picked from commit 90f1e38)
1 parent 1b3ee32 commit bc2590d

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

+18-21
Original file line numberDiff line numberDiff line change
@@ -1912,29 +1912,26 @@ void SwiftASTContext::AddExtraClangCC1Args(
19121912
GetCompilerInvocation().getClangModuleCachePath().str();
19131913

19141914
// Remove non-existing modules in a systematic way.
1915-
bool module_missing = false;
1916-
auto CheckFileExists = [&](const char *file) {
1917-
if (!llvm::sys::fs::exists(file)) {
1918-
std::string warn;
1919-
llvm::raw_string_ostream(warn)
1920-
<< "Nonexistent explicit module file " << file;
1921-
AddDiagnostic(eSeverityWarning, warn);
1922-
module_missing = true;
1923-
}
1915+
auto CheckFileExists = [&](const std::string &file) -> bool {
1916+
if (llvm::sys::fs::exists(file))
1917+
return true;
1918+
std::string warn;
1919+
llvm::raw_string_ostream(warn)
1920+
<< "Nonexistent explicit module file " << file;
1921+
AddDiagnostic(eSeverityWarning, warn);
1922+
return false;
19241923
};
1925-
llvm::for_each(invocation.getHeaderSearchOpts().PrebuiltModuleFiles,
1926-
[&](const auto &mod) { CheckFileExists(mod.second.c_str()); });
1927-
llvm::for_each(invocation.getFrontendOpts().ModuleFiles,
1928-
[&](const auto &mod) { CheckFileExists(mod.c_str()); });
1929-
1930-
// If missing, clear all the prebuilt module options and switch to implicit
1931-
// modules build.
1932-
if (module_missing) {
1933-
invocation.getHeaderSearchOpts().PrebuiltModuleFiles.clear();
1934-
invocation.getFrontendOpts().ModuleFiles.clear();
1935-
invocation.getLangOpts().ImplicitModules = true;
1936-
invocation.getHeaderSearchOpts().ImplicitModuleMaps = true;
1924+
for (auto it = invocation.getHeaderSearchOpts().PrebuiltModuleFiles.begin();
1925+
it != invocation.getHeaderSearchOpts().PrebuiltModuleFiles.end();) {
1926+
if (!CheckFileExists(it->second))
1927+
it = invocation.getHeaderSearchOpts().PrebuiltModuleFiles.erase(it);
1928+
else
1929+
++it;
19371930
}
1931+
invocation.getFrontendOpts().ModuleFiles.erase(
1932+
llvm::remove_if(invocation.getFrontendOpts().ModuleFiles,
1933+
[&](const auto &mod) { return !CheckFileExists(mod); }),
1934+
invocation.getFrontendOpts().ModuleFiles.end());
19381935

19391936
invocation.generateCC1CommandLine(
19401937
[&](const llvm::Twine &arg) { dest.push_back(arg.str()); });

0 commit comments

Comments
 (0)