119
119
#include " Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
120
120
#include " Plugins/TypeSystem/Clang/TypeSystemClang.h"
121
121
122
+ #include < memory>
122
123
#include < mutex>
123
124
#include < queue>
124
125
#include < set>
@@ -2008,6 +2009,25 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
2008
2009
{
2009
2010
LLDB_SCOPED_TIMERF (" %s (getStdlibModule)" , m_description.c_str ());
2010
2011
const bool can_create = true ;
2012
+
2013
+ // Report progress on module importing by using a callback function in
2014
+ // swift::ASTContext
2015
+ Progress progress (" Importing Swift standard library" );
2016
+ swift_ast_sp->m_ast_context_ap ->SetPreModuleImportCallback (
2017
+ [&progress](llvm::StringRef module_name, bool is_overlay) {
2018
+ progress.Increment (1 , (is_overlay ? module_name.str () + " (overlay)"
2019
+ : module_name.str ()));
2020
+ });
2021
+
2022
+ // Clear the callback function on scope exit to prevent an out-of-scope
2023
+ // access of the progress local variable
2024
+ auto on_exit = llvm::make_scope_exit ([&]() {
2025
+ swift_ast_sp->m_ast_context_ap ->SetPreModuleImportCallback (
2026
+ [](llvm::StringRef module_name, bool is_overlay) {
2027
+ Progress (" Importing Swift modules" );
2028
+ });
2029
+ });
2030
+
2011
2031
swift::ModuleDecl *stdlib =
2012
2032
swift_ast_sp->m_ast_context_ap ->getStdlibModule (can_create);
2013
2033
if (!stdlib || IsDWARFImported (*stdlib)) {
@@ -2499,6 +2519,25 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
2499
2519
{
2500
2520
LLDB_SCOPED_TIMERF (" %s (getStdlibModule)" , m_description.c_str ());
2501
2521
const bool can_create = true ;
2522
+
2523
+ // Report progress on module importing by using a callback function in
2524
+ // swift::ASTContext
2525
+ Progress progress (" Importing Swift standard library" );
2526
+ swift_ast_sp->m_ast_context_ap ->SetPreModuleImportCallback (
2527
+ [&progress](llvm::StringRef module_name, bool is_overlay) {
2528
+ progress.Increment (1 , (is_overlay ? module_name.str () + " (overlay)"
2529
+ : module_name.str ()));
2530
+ });
2531
+
2532
+ // Clear the callback function on scope exit to prevent an out-of-scope
2533
+ // access of the progress local variable
2534
+ auto on_exit = llvm::make_scope_exit ([&]() {
2535
+ swift_ast_sp->m_ast_context_ap ->SetPreModuleImportCallback (
2536
+ [](llvm::StringRef module_name, bool is_overlay) {
2537
+ Progress (" Importing Swift modules" );
2538
+ });
2539
+ });
2540
+
2502
2541
swift::ModuleDecl *stdlib =
2503
2542
swift_ast_sp->m_ast_context_ap ->getStdlibModule (can_create);
2504
2543
if (!stdlib || IsDWARFImported (*stdlib)) {
@@ -3203,7 +3242,7 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
3203
3242
GetLanguageOptions (), GetTypeCheckerOptions (), GetSILOptions (),
3204
3243
GetSearchPathOptions (), GetClangImporterOptions (),
3205
3244
GetSymbolGraphOptions (), GetSourceManager (), GetDiagnosticEngine (),
3206
- /* OutputBackend=*/ nullptr , ReportModuleLoadingProgress ));
3245
+ /* OutputBackend=*/ nullptr ));
3207
3246
3208
3247
if (getenv (" LLDB_SWIFT_DUMP_DIAGS" )) {
3209
3248
// NOTE: leaking a swift::PrintingDiagnosticConsumer() here, but
@@ -3486,15 +3525,6 @@ void SwiftASTContext::CacheModule(swift::ModuleDecl *module) {
3486
3525
m_swift_module_cache.insert ({ID, module });
3487
3526
}
3488
3527
3489
- bool SwiftASTContext::ReportModuleLoadingProgress (llvm::StringRef module_name,
3490
- bool is_overlay) {
3491
- Progress progress (llvm::formatv (is_overlay ? " Importing overlay module {0}"
3492
- : " Importing module {0}" ,
3493
- module_name)
3494
- .str ());
3495
- return true ;
3496
- }
3497
-
3498
3528
swift::ModuleDecl *SwiftASTContext::GetModule (const SourceModule &module ,
3499
3529
Status &error, bool *cached) {
3500
3530
if (cached)
@@ -3545,6 +3575,24 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
3545
3575
// Create a diagnostic consumer for the diagnostics produced by the import.
3546
3576
auto import_diags = getScopedDiagnosticConsumer ();
3547
3577
3578
+ // Report progress on module importing by using a callback function in
3579
+ // swift::ASTContext
3580
+ Progress progress (" Importing Swift modules" );
3581
+ ast->SetPreModuleImportCallback ([&progress](llvm::StringRef module_name,
3582
+ bool is_overlay) {
3583
+ progress.Increment (
3584
+ 1 , (is_overlay ? module_name.str () + " (overlay)" : module_name.str ()));
3585
+ });
3586
+
3587
+ // Clear the callback function on scope exit to prevent an out-of-scope access
3588
+ // of the progress local variable
3589
+ auto on_exit = llvm::make_scope_exit ([&]() {
3590
+ ast->SetPreModuleImportCallback (
3591
+ [](llvm::StringRef module_name, bool is_overlay) {
3592
+ Progress (" Importing Swift modules" );
3593
+ });
3594
+ });
3595
+
3548
3596
// Perform the import.
3549
3597
swift::ModuleDecl *module_decl = ast->getModuleByName (module_basename_sref);
3550
3598
@@ -4152,10 +4200,9 @@ void SwiftASTContext::ValidateSectionModules(
4152
4200
Status error;
4153
4201
4154
4202
Progress progress (
4155
- llvm::formatv (" Loading Swift module {0}" ,
4203
+ llvm::formatv (" Loading Swift module ' {0}' dependencies " ,
4156
4204
module .GetFileSpec ().GetFilename ().AsCString ()),
4157
4205
module_names.size ());
4158
-
4159
4206
size_t completion = 0 ;
4160
4207
4161
4208
for (const std::string &module_name : module_names) {
@@ -4164,7 +4211,7 @@ void SwiftASTContext::ValidateSectionModules(
4164
4211
4165
4212
// We have to increment the completion value even if we can't get the module
4166
4213
// object to stay in-sync with the total progress reporting.
4167
- progress.Increment (++completion);
4214
+ progress.Increment (++completion, module_name );
4168
4215
if (!GetModule (module_info, error))
4169
4216
module .ReportWarning (" unable to load swift module \" {0}\" ({1})" ,
4170
4217
module_name.c_str (), error.AsCString ());
@@ -8596,10 +8643,7 @@ bool SwiftASTContextForExpressions::CacheUserImports(
8596
8643
8597
8644
auto src_file_imports = source_file.getImports ();
8598
8645
8599
- Progress progress (llvm::formatv (" Caching Swift user imports from '{0}'" ,
8600
- source_file.getFilename ().data ()),
8601
- src_file_imports.size ());
8602
-
8646
+ Progress progress (" Importing modules used in expression" );
8603
8647
size_t completion = 0 ;
8604
8648
8605
8649
// / Find all explicit imports in the expression.
@@ -8617,7 +8661,9 @@ bool SwiftASTContextForExpressions::CacheUserImports(
8617
8661
source_file.walk (import_finder);
8618
8662
8619
8663
for (const auto &attributed_import : src_file_imports) {
8620
- progress.Increment (++completion);
8664
+ progress.Increment (
8665
+ ++completion,
8666
+ attributed_import.module .importedModule ->getModuleFilename ().str ());
8621
8667
swift::ModuleDecl *module = attributed_import.module .importedModule ;
8622
8668
if (module && import_finder.imports .count (module )) {
8623
8669
std::string module_name;
@@ -8737,10 +8783,9 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
8737
8783
llvm::formatv (" Getting Swift compile unit imports for '{0}'" ,
8738
8784
compile_unit->GetPrimaryFile ().GetFilename ()),
8739
8785
cu_imports.size ());
8740
-
8741
8786
size_t completion = 0 ;
8742
8787
for (const SourceModule &module : cu_imports) {
8743
- progress.Increment (++completion);
8788
+ progress.Increment (++completion, module . path . back (). GetStringRef (). str () );
8744
8789
// When building the Swift stdlib with debug info these will
8745
8790
// show up in "Swift.o", but we already imported them and
8746
8791
// manually importing them will fail.
0 commit comments