Skip to content

Commit 89df8d4

Browse files
committed
SwiftASTContext: Sink module context diagnostic collection into process_one_module (NFC)
1 parent 044c2db commit 89df8d4

File tree

1 file changed

+30
-45
lines changed

1 file changed

+30
-45
lines changed

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

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,50 +2015,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
20152015
pool.wait();
20162016
}
20172017

2018-
for (size_t mi = 0; mi != num_images; ++mi) {
2019-
ModuleSP module_sp = target.GetImages().GetModuleAtIndex(mi);
2020-
2021-
// Skip images without a serialized Swift AST. This avoids
2022-
// spurious warning messages.
2023-
if (!HasSwiftModules(*module_sp))
2024-
continue;
2025-
2026-
auto type_system_or_err =
2027-
module_sp->GetTypeSystemForLanguage(lldb::eLanguageTypeSwift);
2028-
if (!type_system_or_err) {
2029-
llvm::consumeError(type_system_or_err.takeError());
2030-
continue;
2031-
}
2032-
2033-
auto *module_swift_ast =
2034-
llvm::dyn_cast_or_null<SwiftASTContext>(&*type_system_or_err);
2035-
if (module_swift_ast && !module_swift_ast->HasFatalErrors() &&
2036-
module_swift_ast->GetClangImporter())
2037-
continue;
2038-
// Make sure we warn about this module load failure, the one
2039-
// that comes from loading types often gets swallowed up and not
2040-
// seen, this is the only reliable point where we can show this.
2041-
// But only do it once per UUID so we don't overwhelm the user
2042-
// with warnings.
2043-
UUID module_uuid(module_sp->GetUUID());
2044-
bool unique_message =
2045-
target.RegisterSwiftContextMessageKey(module_uuid.GetAsString());
2046-
if (!unique_message)
2047-
continue;
2048-
std::string buf;
2049-
{
2050-
llvm::raw_string_ostream ss(buf);
2051-
module_sp->GetDescription(ss, eDescriptionLevelBrief);
2052-
if (module_swift_ast && module_swift_ast->HasFatalErrors())
2053-
ss << ": "
2054-
<< module_swift_ast->GetFatalErrors().AsCString("unknown error");
2055-
}
2056-
target.GetDebugger().GetErrorStreamSP()->Printf(
2057-
"Error while loading Swift module:\n%s\n"
2058-
"Debug info from this module will be unavailable in the debugger.\n\n",
2059-
buf.c_str());
2060-
}
2061-
20622018
if (!handled_sdk_path) {
20632019
for (size_t mi = 0; mi != num_images; ++mi) {
20642020
ModuleSP module_sp = target.GetImages().GetModuleAtIndex(mi);
@@ -2259,7 +2215,36 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
22592215

22602216
SwiftASTContext *ast_context =
22612217
llvm::dyn_cast_or_null<SwiftASTContext>(&*type_system_or_err);
2262-
if (ast_context && !ast_context->HasErrors()) {
2218+
2219+
if (!ast_context || ast_context->HasFatalErrors() ||
2220+
!ast_context->GetClangImporter()) {
2221+
// Make sure we warn about this module load failure, the one
2222+
// that comes from loading types often gets swallowed up and not
2223+
// seen, this is the only reliable point where we can show this.
2224+
// But only do it once per UUID so we don't overwhelm the user
2225+
// with warnings.
2226+
UUID module_uuid(module_sp->GetUUID());
2227+
bool unique_message =
2228+
target.RegisterSwiftContextMessageKey(module_uuid.GetAsString());
2229+
if (!unique_message)
2230+
return;
2231+
std::string buf;
2232+
{
2233+
llvm::raw_string_ostream ss(buf);
2234+
module_sp->GetDescription(ss, eDescriptionLevelBrief);
2235+
if (ast_context && ast_context->HasFatalErrors())
2236+
ss << ": "
2237+
<< ast_context->GetFatalErrors().AsCString("unknown error");
2238+
}
2239+
target.GetDebugger().GetErrorStreamSP()->Printf(
2240+
"Error while loading Swift module:\n%s\n"
2241+
"Debug info from this module will be unavailable in the "
2242+
"debugger.\n\n",
2243+
buf.c_str());
2244+
return;
2245+
}
2246+
2247+
if (!ast_context->HasErrors()) {
22632248
if (use_all_compiler_flags ||
22642249
target.GetExecutableModulePointer() == module_sp.get()) {
22652250

0 commit comments

Comments
 (0)