Skip to content

Commit 2cf0120

Browse files
[lldb][progress] Mitigate non-specific LLDB progress reports in Swift (#8664)
* [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. (cherry picked from commit 84e7e51) * Update test for Swift progress reports Updates the test for Swift progress reporting by checking that the "Importing Swift modules" message only appears twice on its own as the rest of the reports for this category will have details attached. (cherry picked from commit 21e9d75)
1 parent 11d1236 commit 2cf0120

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,9 +2160,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
21602160
auto on_exit = llvm::make_scope_exit([&]() {
21612161
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
21622162
[](llvm::StringRef module_name,
2163-
swift::ASTContext::ModuleImportKind kind) {
2164-
Progress("Importing Swift modules");
2165-
});
2163+
swift::ASTContext::ModuleImportKind kind) {});
21662164
});
21672165

21682166
swift::ModuleDecl *stdlib =
@@ -2716,9 +2714,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
27162714
auto on_exit = llvm::make_scope_exit([&]() {
27172715
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
27182716
[](llvm::StringRef module_name,
2719-
swift::ASTContext::ModuleImportKind kind) {
2720-
Progress("Importing Swift modules");
2721-
});
2717+
swift::ASTContext::ModuleImportKind kind) {});
27222718
});
27232719

27242720
swift::ModuleDecl *stdlib =
@@ -3825,20 +3821,22 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
38253821

38263822
// Report progress on module importing by using a callback function in
38273823
// swift::ASTContext.
3828-
Progress progress("Importing Swift modules");
3824+
std::unique_ptr<Progress> progress;
38293825
ast->SetPreModuleImportCallback(
38303826
[&progress](llvm::StringRef module_name,
38313827
swift::ASTContext::ModuleImportKind kind) {
3828+
if (!progress)
3829+
progress = std::make_unique<Progress>("Importing Swift modules");
38323830
switch (kind) {
38333831
case swift::ASTContext::Module:
3834-
progress.Increment(1, module_name.str());
3832+
progress->Increment(1, module_name.str());
38353833
break;
38363834
case swift::ASTContext::Overlay:
3837-
progress.Increment(1, module_name.str() + " (overlay)");
3835+
progress->Increment(1, module_name.str() + " (overlay)");
38383836
break;
38393837
case swift::ASTContext::BridgingHeader:
3840-
progress.Increment(1,
3841-
"Compiling bridging header: " + module_name.str());
3838+
progress->Increment(1, "Compiling bridging header: " +
3839+
module_name.str());
38423840
break;
38433841
}
38443842
});
@@ -3848,9 +3846,7 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
38483846
auto on_exit = llvm::make_scope_exit([&]() {
38493847
ast->SetPreModuleImportCallback(
38503848
[](llvm::StringRef module_name,
3851-
swift::ASTContext::ModuleImportKind kind) {
3852-
Progress("Importing Swift modules");
3853-
});
3849+
swift::ASTContext::ModuleImportKind kind) {});
38543850
});
38553851

38563852
// Perform the import.

lldb/test/API/functionalities/progress_reporting/swift_progress_reporting/TestSwiftProgressReporting.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,22 @@ def test_swift_progress_report(self):
4545
"Importing Swift standard library",
4646
]
4747

48+
importing_swift_reports = []
4849
while len(beacons):
4950
event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
5051
ret_args = lldb.SBDebugger.GetProgressFromEvent(event)
5152
if self.TraceOn():
5253
print(ret_args[0])
5354

55+
# When importing Swift modules, make sure that we don't get two reports
56+
# in a row with the title "Importing Swift modules", i.e. there should be
57+
# a report with that title followed by a report with that title and details
58+
# attached.
59+
if ret_args[0] == "Importing Swift modules":
60+
next_event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
61+
next_ret_args = lldb.SBDebugger.GetProgressFromEvent(next_event)
62+
self.assertRegexpMatches(next_ret_args[0], r"Importing Swift modules:+")
63+
5464
for beacon in beacons:
5565
if beacon in ret_args[0]:
5666
beacons.remove(beacon)

0 commit comments

Comments
 (0)