Skip to content

Commit 84e7e51

Browse files
committed
[lldb][progress] Mitigate non-specific LLDB progress reports in Swift
When LLDB reports progress on importing Swift modules, it was delivering non-specific progress reports with only the title of "Importing Swift modules" and no details. To report progress on activity within Swift, LLDB first creates a progress report then updates that progress report using a callback that LLDB sets and the Swift compiler invokes when performing a full import. When LLDB triggers Swift to import modules that were already imported before, Swift will not perform a full import. Since the progress report would've already been displayed, but the callback is never invoked, this leads to the non-specific messages that were being displayed when importing Swift modules. This commit sets a unique pointer to create a progress report from within the callback function instead of creating the report before setting the callback. It also clears the callback on scope exit instead of setting it to a new progress report.
1 parent 59fbb17 commit 84e7e51

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,9 +2162,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
21622162
auto on_exit = llvm::make_scope_exit([&]() {
21632163
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
21642164
[](llvm::StringRef module_name,
2165-
swift::ASTContext::ModuleImportKind kind) {
2166-
Progress("Importing Swift modules");
2167-
});
2165+
swift::ASTContext::ModuleImportKind kind) {});
21682166
});
21692167

21702168
swift::ModuleDecl *stdlib =
@@ -2718,9 +2716,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
27182716
auto on_exit = llvm::make_scope_exit([&]() {
27192717
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
27202718
[](llvm::StringRef module_name,
2721-
swift::ASTContext::ModuleImportKind kind) {
2722-
Progress("Importing Swift modules");
2723-
});
2719+
swift::ASTContext::ModuleImportKind kind) {});
27242720
});
27252721

27262722
swift::ModuleDecl *stdlib =
@@ -3781,20 +3777,22 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
37813777

37823778
// Report progress on module importing by using a callback function in
37833779
// swift::ASTContext.
3784-
Progress progress("Importing Swift modules");
3780+
std::unique_ptr<Progress> progress;
37853781
ast->SetPreModuleImportCallback(
37863782
[&progress](llvm::StringRef module_name,
37873783
swift::ASTContext::ModuleImportKind kind) {
3784+
if (!progress)
3785+
progress = std::make_unique<Progress>("Importing Swift modules");
37883786
switch (kind) {
37893787
case swift::ASTContext::Module:
3790-
progress.Increment(1, module_name.str());
3788+
progress->Increment(1, module_name.str());
37913789
break;
37923790
case swift::ASTContext::Overlay:
3793-
progress.Increment(1, module_name.str() + " (overlay)");
3791+
progress->Increment(1, module_name.str() + " (overlay)");
37943792
break;
37953793
case swift::ASTContext::BridgingHeader:
3796-
progress.Increment(1,
3797-
"Compiling bridging header: " + module_name.str());
3794+
progress->Increment(1, "Compiling bridging header: " +
3795+
module_name.str());
37983796
break;
37993797
}
38003798
});
@@ -3804,9 +3802,7 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
38043802
auto on_exit = llvm::make_scope_exit([&]() {
38053803
ast->SetPreModuleImportCallback(
38063804
[](llvm::StringRef module_name,
3807-
swift::ASTContext::ModuleImportKind kind) {
3808-
Progress("Importing Swift modules");
3809-
});
3805+
swift::ASTContext::ModuleImportKind kind) {});
38103806
});
38113807

38123808
// Perform the import.

0 commit comments

Comments
 (0)