Skip to content

Commit b3452b3

Browse files
authored
Merge pull request #4773 from medismailben/module-loading-callbacks
[lldb/Swift] Add progress report callback when loading a module
2 parents a619373 + 4aadd73 commit b3452b3

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3137,7 +3137,8 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
31373137
m_ast_context_ap.reset(swift::ASTContext::get(
31383138
GetLanguageOptions(), GetTypeCheckerOptions(), GetSILOptions(),
31393139
GetSearchPathOptions(), GetClangImporterOptions(),
3140-
GetSymbolGraphOptions(), GetSourceManager(), GetDiagnosticEngine()));
3140+
GetSymbolGraphOptions(), GetSourceManager(), GetDiagnosticEngine(),
3141+
ReportModuleLoadingProgress));
31413142
m_diagnostic_consumer_ap.reset(new StoringDiagnosticConsumer(*this));
31423143

31433144
if (getenv("LLDB_SWIFT_DUMP_DIAGS")) {
@@ -3407,6 +3408,15 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
34073408
m_swift_module_cache.insert({ID, module});
34083409
}
34093410

3411+
bool SwiftASTContext::ReportModuleLoadingProgress(llvm::StringRef module_name,
3412+
bool is_overlay) {
3413+
Progress progress(llvm::formatv(is_overlay ? "Importing overlay module {0}"
3414+
: "Importing module {0}",
3415+
module_name.data())
3416+
.str());
3417+
return true;
3418+
}
3419+
34103420
swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
34113421
Status &error, bool *cached) {
34123422
if (cached)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ class SwiftASTContext : public TypeSystemSwift {
281281
swift::ModuleDecl *CreateModule(const SourceModule &module, Status &error,
282282
swift::ImplicitImportInfo importInfo);
283283

284+
static bool ReportModuleLoadingProgress(llvm::StringRef module_name,
285+
bool is_overlay);
286+
284287
// This function should only be called when all search paths
285288
// for all items in a swift::ASTContext have been setup to
286289
// allow for imports to happen correctly. Use with caution,

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ def setUp(self):
1717
self.broadcaster = self.dbg.GetBroadcaster()
1818
self.listener = lldbutil.start_listening_from(self.broadcaster,
1919
lldb.SBDebugger.eBroadcastBitProgress)
20+
21+
# Don't run ClangImporter tests if Clangimporter is disabled.
22+
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
23+
@skipUnlessDarwin
2024
@swiftTest
21-
@skipIf(oslist=no_match(["macosx"]))
2225
def test_swift_progress_report(self):
2326
"""Test that we are able to fetch swift type-system progress events"""
2427
self.build()
@@ -32,11 +35,13 @@ def test_swift_progress_report(self):
3235

3336
# Resolve variable to exercise the type-system
3437
self.runCmd("expr boo")
38+
self.runCmd("v s")
3539

3640
beacons = [ "Loading Swift module",
3741
"Caching Swift user imports from",
3842
"Setting up Swift reflection for",
39-
"Getting Swift compile unit imports for"]
43+
"Getting Swift compile unit imports for",
44+
"Importing module", "Importing overlay module"]
4045

4146
while len(beacons):
4247
event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)

lldb/test/API/functionalities/progress_reporting/swift_progress_reporting/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Invisible
2+
import Foundation
23

34
func main() {
45
let boo = Invisible.👻()
6+
let s = NSAttributedString(string: "Hello")
57
print("break here")
68
}
79

0 commit comments

Comments
 (0)