Skip to content

Commit

Permalink
Merge pull request #8623 from chelcassanova/fix-unspecific-swift-prog…
Browse files Browse the repository at this point in the history
…ress-reports

[lldb][progress] Mitigate non-specific LLDB progress reports in Swift
  • Loading branch information
JDevlieghere committed Apr 29, 2024
2 parents 24f12aa + 21e9d75 commit 9a495dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Expand Up @@ -2162,9 +2162,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
auto on_exit = llvm::make_scope_exit([&]() {
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
[](llvm::StringRef module_name,
swift::ASTContext::ModuleImportKind kind) {
Progress("Importing Swift modules");
});
swift::ASTContext::ModuleImportKind kind) {});
});

swift::ModuleDecl *stdlib =
Expand Down Expand Up @@ -2718,9 +2716,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
auto on_exit = llvm::make_scope_exit([&]() {
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
[](llvm::StringRef module_name,
swift::ASTContext::ModuleImportKind kind) {
Progress("Importing Swift modules");
});
swift::ASTContext::ModuleImportKind kind) {});
});

swift::ModuleDecl *stdlib =
Expand Down Expand Up @@ -3850,20 +3846,22 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,

// Report progress on module importing by using a callback function in
// swift::ASTContext.
Progress progress("Importing Swift modules");
std::unique_ptr<Progress> progress;
ast->SetPreModuleImportCallback(
[&progress](llvm::StringRef module_name,
swift::ASTContext::ModuleImportKind kind) {
if (!progress)
progress = std::make_unique<Progress>("Importing Swift modules");
switch (kind) {
case swift::ASTContext::Module:
progress.Increment(1, module_name.str());
progress->Increment(1, module_name.str());
break;
case swift::ASTContext::Overlay:
progress.Increment(1, module_name.str() + " (overlay)");
progress->Increment(1, module_name.str() + " (overlay)");
break;
case swift::ASTContext::BridgingHeader:
progress.Increment(1,
"Compiling bridging header: " + module_name.str());
progress->Increment(1, "Compiling bridging header: " +
module_name.str());
break;
}
});
Expand All @@ -3873,9 +3871,7 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
auto on_exit = llvm::make_scope_exit([&]() {
ast->SetPreModuleImportCallback(
[](llvm::StringRef module_name,
swift::ASTContext::ModuleImportKind kind) {
Progress("Importing Swift modules");
});
swift::ASTContext::ModuleImportKind kind) {});
});

// Perform the import.
Expand Down
Expand Up @@ -45,12 +45,22 @@ def test_swift_progress_report(self):
"Importing Swift standard library",
]

importing_swift_reports = []
while len(beacons):
event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
ret_args = lldb.SBDebugger.GetProgressFromEvent(event)
if self.TraceOn():
print(ret_args[0])

# When importing Swift modules, make sure that we don't get two reports
# in a row with the title "Importing Swift modules", i.e. there should be
# a report with that title followed by a report with that title and details
# attached.
if ret_args[0] == "Importing Swift modules":
next_event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
next_ret_args = lldb.SBDebugger.GetProgressFromEvent(next_event)
self.assertRegexpMatches(next_ret_args[0], r"Importing Swift modules:+")

for beacon in beacons:
if beacon in ret_args[0]:
beacons.remove(beacon)

0 comments on commit 9a495dd

Please sign in to comment.