121
121
#include " Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
122
122
#include " Plugins/TypeSystem/Clang/TypeSystemClang.h"
123
123
124
+ #include < memory>
124
125
#include < mutex>
125
126
#include < queue>
126
127
#include < set>
@@ -2018,6 +2019,25 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
2018
2019
{
2019
2020
LLDB_SCOPED_TIMERF (" %s (getStdlibModule)" , m_description.c_str ());
2020
2021
const bool can_create = true ;
2022
+
2023
+ // Report progress on module importing by using a callback function in
2024
+ // swift::ASTContext
2025
+ Progress progress (" Importing Swift standard library" );
2026
+ swift_ast_sp->m_ast_context_ap ->SetPreModuleImportCallback (
2027
+ [&progress](llvm::StringRef module_name, bool is_overlay) {
2028
+ progress.Increment (1 , (is_overlay ? module_name.str () + " (overlay)"
2029
+ : module_name.str ()));
2030
+ });
2031
+
2032
+ // Clear the callback function on scope exit to prevent an out-of-scope
2033
+ // access of the progress local variable
2034
+ auto on_exit = llvm::make_scope_exit ([&]() {
2035
+ swift_ast_sp->m_ast_context_ap ->SetPreModuleImportCallback (
2036
+ [](llvm::StringRef module_name, bool is_overlay) {
2037
+ Progress (" Importing Swift modules" );
2038
+ });
2039
+ });
2040
+
2021
2041
swift::ModuleDecl *stdlib =
2022
2042
swift_ast_sp->m_ast_context_ap ->getStdlibModule (can_create);
2023
2043
if (!stdlib || IsDWARFImported (*stdlib)) {
@@ -2511,6 +2531,25 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
2511
2531
{
2512
2532
LLDB_SCOPED_TIMERF (" %s (getStdlibModule)" , m_description.c_str ());
2513
2533
const bool can_create = true ;
2534
+
2535
+ // Report progress on module importing by using a callback function in
2536
+ // swift::ASTContext
2537
+ Progress progress (" Importing Swift standard library" );
2538
+ swift_ast_sp->m_ast_context_ap ->SetPreModuleImportCallback (
2539
+ [&progress](llvm::StringRef module_name, bool is_overlay) {
2540
+ progress.Increment (1 , (is_overlay ? module_name.str () + " (overlay)"
2541
+ : module_name.str ()));
2542
+ });
2543
+
2544
+ // Clear the callback function on scope exit to prevent an out-of-scope
2545
+ // access of the progress local variable
2546
+ auto on_exit = llvm::make_scope_exit ([&]() {
2547
+ swift_ast_sp->m_ast_context_ap ->SetPreModuleImportCallback (
2548
+ [](llvm::StringRef module_name, bool is_overlay) {
2549
+ Progress (" Importing Swift modules" );
2550
+ });
2551
+ });
2552
+
2514
2553
swift::ModuleDecl *stdlib =
2515
2554
swift_ast_sp->m_ast_context_ap ->getStdlibModule (can_create);
2516
2555
if (!stdlib || IsDWARFImported (*stdlib)) {
@@ -3217,7 +3256,7 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
3217
3256
GetLanguageOptions (), GetTypeCheckerOptions (), GetSILOptions (),
3218
3257
GetSearchPathOptions (), GetClangImporterOptions (),
3219
3258
GetSymbolGraphOptions (), GetSourceManager (), GetDiagnosticEngine (),
3220
- /* OutputBackend=*/ nullptr , ReportModuleLoadingProgress ));
3259
+ /* OutputBackend=*/ nullptr ));
3221
3260
3222
3261
if (getenv (" LLDB_SWIFT_DUMP_DIAGS" )) {
3223
3262
// NOTE: leaking a swift::PrintingDiagnosticConsumer() here, but
@@ -3501,15 +3540,6 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
3501
3540
m_swift_module_cache.insert ({ID, module });
3502
3541
}
3503
3542
3504
- bool SwiftASTContext::ReportModuleLoadingProgress (llvm::StringRef module_name,
3505
- bool is_overlay) {
3506
- Progress progress (llvm::formatv (is_overlay ? " Importing overlay module {0}"
3507
- : " Importing module {0}" ,
3508
- module_name)
3509
- .str ());
3510
- return true ;
3511
- }
3512
-
3513
3543
swift::ModuleDecl *SwiftASTContext::GetModule (const SourceModule &module ,
3514
3544
Status &error, bool *cached) {
3515
3545
if (cached)
@@ -3560,6 +3590,24 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
3560
3590
// Create a diagnostic consumer for the diagnostics produced by the import.
3561
3591
auto import_diags = getScopedDiagnosticConsumer ();
3562
3592
3593
+ // Report progress on module importing by using a callback function in
3594
+ // swift::ASTContext
3595
+ Progress progress (" Importing Swift modules" );
3596
+ ast->SetPreModuleImportCallback ([&progress](llvm::StringRef module_name,
3597
+ bool is_overlay) {
3598
+ progress.Increment (
3599
+ 1 , (is_overlay ? module_name.str () + " (overlay)" : module_name.str ()));
3600
+ });
3601
+
3602
+ // Clear the callback function on scope exit to prevent an out-of-scope access
3603
+ // of the progress local variable
3604
+ auto on_exit = llvm::make_scope_exit ([&]() {
3605
+ ast->SetPreModuleImportCallback (
3606
+ [](llvm::StringRef module_name, bool is_overlay) {
3607
+ Progress (" Importing Swift modules" );
3608
+ });
3609
+ });
3610
+
3563
3611
// Perform the import.
3564
3612
swift::ModuleDecl *module_decl = ast->getModuleByName (module_basename_sref);
3565
3613
@@ -4169,6 +4217,7 @@ void SwiftASTContext::ValidateSectionModules(
4169
4217
Progress progress (" Loading Swift module '{0}' dependencies" ,
4170
4218
module .GetFileSpec ().GetFilename ().AsCString (),
4171
4219
module_names.size ());
4220
+
4172
4221
size_t completion = 0 ;
4173
4222
4174
4223
for (const std::string &module_name : module_names) {
@@ -4177,7 +4226,7 @@ void SwiftASTContext::ValidateSectionModules(
4177
4226
4178
4227
// We have to increment the completion value even if we can't get the module
4179
4228
// object to stay in-sync with the total progress reporting.
4180
- progress.Increment (++completion);
4229
+ progress.Increment (++completion, module_name );
4181
4230
if (!GetModule (module_info, error))
4182
4231
module .ReportWarning (" unable to load swift module \" {0}\" ({1})" ,
4183
4232
module_name.c_str (), error.AsCString ());
@@ -8609,10 +8658,7 @@ bool SwiftASTContextForExpressions::CacheUserImports(
8609
8658
8610
8659
auto src_file_imports = source_file.getImports ();
8611
8660
8612
- Progress progress (llvm::formatv (" Caching Swift user imports from '{0}'" ,
8613
- source_file.getFilename ().data ()),
8614
- src_file_imports.size ());
8615
-
8661
+ Progress progress (" Importing modules used in expression" );
8616
8662
size_t completion = 0 ;
8617
8663
8618
8664
// / Find all explicit imports in the expression.
@@ -8630,7 +8676,9 @@ bool SwiftASTContextForExpressions::CacheUserImports(
8630
8676
source_file.walk (import_finder);
8631
8677
8632
8678
for (const auto &attributed_import : src_file_imports) {
8633
- progress.Increment (++completion);
8679
+ progress.Increment (
8680
+ ++completion,
8681
+ attributed_import.module .importedModule ->getModuleFilename ().str ());
8634
8682
swift::ModuleDecl *module = attributed_import.module .importedModule ;
8635
8683
if (module && import_finder.imports .count (module )) {
8636
8684
std::string module_name;
@@ -8749,9 +8797,10 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
8749
8797
Progress progress (" Getting Swift compile unit imports" ,
8750
8798
compile_unit->GetPrimaryFile ().GetFilename ().GetCString (),
8751
8799
cu_imports.size ());
8800
+
8752
8801
size_t completion = 0 ;
8753
8802
for (const SourceModule &module : cu_imports) {
8754
- progress.Increment (++completion);
8803
+ progress.Increment (++completion, module . path . back (). GetStringRef (). str () );
8755
8804
// When building the Swift stdlib with debug info these will
8756
8805
// show up in "Swift.o", but we already imported them and
8757
8806
// manually importing them will fail.
0 commit comments