-
Notifications
You must be signed in to change notification settings - Fork 342
[lldb][progress] Improve Swift progress reporting #7769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
3fd19ad
b4a9c1d
d835247
4f8f84c
9358d76
88d21f2
b6678ff
fd64915
60a2bc6
8fc06aa
92c47f3
d33265b
a59e387
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -119,6 +119,7 @@ | |||||||
#include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h" | ||||||||
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h" | ||||||||
|
||||||||
#include <memory> | ||||||||
#include <mutex> | ||||||||
#include <queue> | ||||||||
#include <set> | ||||||||
|
@@ -1989,6 +1990,25 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module, | |||||||
{ | ||||||||
LLDB_SCOPED_TIMERF("%s (getStdlibModule)", m_description.c_str()); | ||||||||
const bool can_create = true; | ||||||||
|
||||||||
// Report progress on module importing by using a callback function in | ||||||||
// swift::ASTContext | ||||||||
Progress progress("Importing Swift standard library modules"); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there multiple standard library modules or is there one? I know it might be pulling in other modules as dependencies. I guess we could sidestep this by omitting "modules" at the end. @adrian-prantl WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @chelcassanova There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Modules" can be omitted here for clarity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand ... you say it can be omitted but it's still in the PR 🧐 ...
Suggested change
|
||||||||
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback( | ||||||||
[&progress](llvm::StringRef module_name, bool is_overlay) { | ||||||||
progress.Increment(1, (is_overlay ? module_name.str() + " (overlay)" | ||||||||
: module_name.str())); | ||||||||
}); | ||||||||
|
||||||||
// Clear the callback function on scope exit to prevent an out-of-scope | ||||||||
// access of the progress local variable | ||||||||
auto on_exit = llvm::make_scope_exit([&]() { | ||||||||
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback( | ||||||||
[](llvm::StringRef module_name, bool is_overlay) { | ||||||||
Progress progress("Importing Swift modules"); | ||||||||
}); | ||||||||
}); | ||||||||
|
||||||||
swift::ModuleDecl *stdlib = | ||||||||
swift_ast_sp->m_ast_context_ap->getStdlibModule(can_create); | ||||||||
if (!stdlib || IsDWARFImported(*stdlib)) { | ||||||||
|
@@ -2479,6 +2499,25 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance( | |||||||
{ | ||||||||
LLDB_SCOPED_TIMERF("%s (getStdlibModule)", m_description.c_str()); | ||||||||
const bool can_create = true; | ||||||||
|
||||||||
// Report progress on module importing by using a callback function in | ||||||||
// swift::ASTContext | ||||||||
Progress progress("Importing Swift standard library modules"); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, drop the "modules" part.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how I missed both of these, thanks for the correction! |
||||||||
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback( | ||||||||
[&progress](llvm::StringRef module_name, bool is_overlay) { | ||||||||
progress.Increment(1, (is_overlay ? module_name.str() + " (overlay)" | ||||||||
: module_name.str())); | ||||||||
}); | ||||||||
|
||||||||
// Clear the callback function on scope exit to prevent an out-of-scope | ||||||||
// access of the progress local variable | ||||||||
auto on_exit = llvm::make_scope_exit([&]() { | ||||||||
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback( | ||||||||
[](llvm::StringRef module_name, bool is_overlay) { | ||||||||
Progress progress("Importing Swift modules"); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just call the constructor here, I don't think you need to create a
Suggested change
|
||||||||
}); | ||||||||
}); | ||||||||
|
||||||||
swift::ModuleDecl *stdlib = | ||||||||
swift_ast_sp->m_ast_context_ap->getStdlibModule(can_create); | ||||||||
if (!stdlib || IsDWARFImported(*stdlib)) { | ||||||||
|
@@ -2921,7 +2960,7 @@ swift::ASTContext *SwiftASTContext::GetASTContext() { | |||||||
GetLanguageOptions(), GetTypeCheckerOptions(), GetSILOptions(), | ||||||||
GetSearchPathOptions(), GetClangImporterOptions(), | ||||||||
GetSymbolGraphOptions(), GetSourceManager(), GetDiagnosticEngine(), | ||||||||
/*OutputBackend=*/nullptr, ReportModuleLoadingProgress)); | ||||||||
/*OutputBackend=*/nullptr)); | ||||||||
|
||||||||
if (getenv("LLDB_SWIFT_DUMP_DIAGS")) { | ||||||||
// NOTE: leaking a swift::PrintingDiagnosticConsumer() here, but | ||||||||
|
@@ -3203,15 +3242,6 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) { | |||||||
m_swift_module_cache.insert({ID, module}); | ||||||||
} | ||||||||
|
||||||||
bool SwiftASTContext::ReportModuleLoadingProgress(llvm::StringRef module_name, | ||||||||
bool is_overlay) { | ||||||||
Progress progress(llvm::formatv(is_overlay ? "Importing overlay module {0}" | ||||||||
: "Importing module {0}", | ||||||||
module_name) | ||||||||
.str()); | ||||||||
return true; | ||||||||
} | ||||||||
|
||||||||
swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module, | ||||||||
Status &error, bool *cached) { | ||||||||
if (cached) | ||||||||
|
@@ -3262,6 +3292,24 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module, | |||||||
// Create a diagnostic consumer for the diagnostics produced by the import. | ||||||||
auto import_diags = getScopedDiagnosticConsumer(); | ||||||||
|
||||||||
// Report progress on module importing by using a callback function in | ||||||||
// swift::ASTContext | ||||||||
Progress progress("Importing Swift modules"); | ||||||||
ast->SetPreModuleImportCallback([&progress](llvm::StringRef module_name, | ||||||||
bool is_overlay) { | ||||||||
progress.Increment( | ||||||||
1, (is_overlay ? module_name.str() + " (overlay)" : module_name.str())); | ||||||||
}); | ||||||||
|
||||||||
// Clear the callback function on scope exit to prevent an out-of-scope access | ||||||||
// of the progress local variable | ||||||||
auto on_exit = llvm::make_scope_exit([&]() { | ||||||||
ast->SetPreModuleImportCallback( | ||||||||
[](llvm::StringRef module_name, bool is_overlay) { | ||||||||
Progress progress("Importing Swift modules"); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto.
Suggested change
|
||||||||
}); | ||||||||
}); | ||||||||
|
||||||||
// Perform the import. | ||||||||
swift::ModuleDecl *module_decl = ast->getModuleByName(module_basename_sref); | ||||||||
|
||||||||
|
@@ -3868,11 +3916,7 @@ void SwiftASTContext::ValidateSectionModules( | |||||||
|
||||||||
Status error; | ||||||||
|
||||||||
Progress progress( | ||||||||
llvm::formatv("Loading Swift module {0}", | ||||||||
module.GetFileSpec().GetFilename().AsCString()), | ||||||||
module_names.size()); | ||||||||
|
||||||||
Progress progress("Loading Swift module", module_names.size()); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should experiment and see changing the progress title here is actually a good thing. Now you don't know what parent module are we loading the submodule for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or |
||||||||
size_t completion = 0; | ||||||||
|
||||||||
for (const std::string &module_name : module_names) { | ||||||||
|
@@ -3881,7 +3925,8 @@ void SwiftASTContext::ValidateSectionModules( | |||||||
|
||||||||
// We have to increment the completion value even if we can't get the module | ||||||||
// object to stay in-sync with the total progress reporting. | ||||||||
progress.Increment(++completion); | ||||||||
progress.Increment(++completion, | ||||||||
module.GetFileSpec().GetFilename().AsCString()); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks wrong, you need to re-use the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I reused the original implementation grabbed the module name from its FileSpec so that's how I missed this |
||||||||
if (!GetModule(module_info, error)) | ||||||||
module.ReportWarning("unable to load swift module \"{0}\" ({1})", | ||||||||
module_name.c_str(), error.AsCString()); | ||||||||
|
@@ -8318,10 +8363,7 @@ bool SwiftASTContextForExpressions::CacheUserImports( | |||||||
|
||||||||
auto src_file_imports = source_file.getImports(); | ||||||||
|
||||||||
Progress progress(llvm::formatv("Caching Swift user imports from '{0}'", | ||||||||
source_file.getFilename().data()), | ||||||||
src_file_imports.size()); | ||||||||
|
||||||||
Progress progress("Importing module used in expression"); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
size_t completion = 0; | ||||||||
|
||||||||
/// Find all explicit imports in the expression. | ||||||||
|
@@ -8339,7 +8381,9 @@ bool SwiftASTContextForExpressions::CacheUserImports( | |||||||
source_file.walk(import_finder); | ||||||||
|
||||||||
for (const auto &attributed_import : src_file_imports) { | ||||||||
progress.Increment(++completion); | ||||||||
progress.Increment( | ||||||||
++completion, | ||||||||
attributed_import.module.importedModule->getModuleFilename().str()); | ||||||||
swift::ModuleDecl *module = attributed_import.module.importedModule; | ||||||||
if (module && import_finder.imports.count(module)) { | ||||||||
std::string module_name; | ||||||||
|
@@ -8456,10 +8500,9 @@ bool SwiftASTContext::GetCompileUnitImportsImpl( | |||||||
llvm::formatv("Getting Swift compile unit imports for '{0}'", | ||||||||
compile_unit->GetPrimaryFile().GetFilename()), | ||||||||
cu_imports.size()); | ||||||||
|
||||||||
size_t completion = 0; | ||||||||
for (const SourceModule &module : cu_imports) { | ||||||||
progress.Increment(++completion); | ||||||||
progress.Increment(++completion, module.path.back().GetStringRef().str()); | ||||||||
// When building the Swift stdlib with debug info these will | ||||||||
// show up in "Swift.o", but we already imported them and | ||||||||
// manually importing them will fail. | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,6 +293,9 @@ class SwiftASTContext : public TypeSystemSwift { | |
swift::ModuleDecl *CreateModule(const SourceModule &module, Status &error, | ||
swift::ImplicitImportInfo importInfo); | ||
|
||
/// Generic callback function used for progress reporting that gets | ||
/// invoked by the Swift compiler and gets set upon scope exit when | ||
/// a more detailed progress report was used as the callback | ||
static bool ReportModuleLoadingProgress(llvm::StringRef module_name, | ||
bool is_overlay); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just delete this if you replace it by an empty lambda. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still here ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed, I thought I took this out of the header 😓 |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this go upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chelcassanova This should go upstream, before you land this patch otherwise, you could get a merge conflict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on llvm#73605. @chelcassanova make sure to cherrypick here the merge commit after you land it upstream ;)