@@ -8315,8 +8315,8 @@ bool SwiftASTContext::GetImplicitImports(
8315
8315
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
8316
8316
&modules,
8317
8317
Status &error) {
8318
- if (!GetCompileUnitImports (swift_ast_context, sc, stack_frame_wp, modules,
8319
- error)) {
8318
+ if (!swift_ast_context. GetCompileUnitImports (sc, stack_frame_wp, modules,
8319
+ error)) {
8320
8320
return false ;
8321
8321
}
8322
8322
@@ -8388,22 +8388,54 @@ bool SwiftASTContext::CacheUserImports(SwiftASTContext &swift_ast_context,
8388
8388
}
8389
8389
8390
8390
bool SwiftASTContext::GetCompileUnitImports (
8391
- SwiftASTContext &swift_ast_context, SymbolContext &sc,
8392
- lldb::StackFrameWP &stack_frame_wp,
8391
+ SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
8393
8392
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
8394
8393
&modules,
8395
8394
Status &error) {
8395
+ return GetCompileUnitImportsImpl (sc, stack_frame_wp, &modules, error);
8396
+ }
8397
+
8398
+ void SwiftASTContext::PerformCompileUnitImports (
8399
+ SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp, Status &error) {
8400
+ GetCompileUnitImportsImpl (sc, stack_frame_wp, nullptr , error);
8401
+ }
8402
+
8403
+ static std::pair<Module *, lldb::user_id_t >
8404
+ GetCUSignature (CompileUnit &compile_unit) {
8405
+ return {compile_unit.GetModule ().get (), compile_unit.GetID ()};
8406
+ }
8407
+
8408
+ bool SwiftASTContext::GetCompileUnitImportsImpl (
8409
+ SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
8410
+ llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
8411
+ *modules,
8412
+ Status &error) {
8413
+ CompileUnit *compile_unit = sc.comp_unit ;
8414
+ if (compile_unit)
8415
+ // Check the cache if this compile unit's imports were previously
8416
+ // requested. If the caller didn't request the list of imported
8417
+ // modules then there is nothing left to do for subsequent
8418
+ // GetCompileUnitImportsImpl() calls as the previously loaded
8419
+ // modules should still be loaded. The fact the we
8420
+ // unconditionally return true does not matter because the only
8421
+ // way to get here is through void PerformCompileUnitImports(),
8422
+ // which discards the return value.
8423
+ if (!m_cu_imports.insert (GetCUSignature (*compile_unit)).second )
8424
+ // List of imports isn't requested and we already processed this CU?
8425
+ if (!modules)
8426
+ return true ;
8427
+
8396
8428
// Import the Swift standard library and its dependencies.
8397
8429
SourceModule swift_module;
8398
8430
swift_module.path .emplace_back (" Swift" );
8399
8431
auto *stdlib =
8400
- LoadOneModule (swift_module, swift_ast_context , stack_frame_wp, error);
8432
+ LoadOneModule (swift_module, * this , stack_frame_wp, error);
8401
8433
if (!stdlib)
8402
8434
return false ;
8403
8435
8404
- modules.emplace_back (swift::ImportedModule (stdlib));
8436
+ if (modules)
8437
+ modules->emplace_back (swift::ImportedModule (stdlib));
8405
8438
8406
- CompileUnit *compile_unit = sc.comp_unit ;
8407
8439
if (!compile_unit || compile_unit->GetLanguage () != lldb::eLanguageTypeSwift)
8408
8440
return true ;
8409
8441
@@ -8418,11 +8450,12 @@ bool SwiftASTContext::GetCompileUnitImports(
8418
8450
continue ;
8419
8451
8420
8452
auto *loaded_module =
8421
- LoadOneModule (module , swift_ast_context , stack_frame_wp, error);
8453
+ LoadOneModule (module , * this , stack_frame_wp, error);
8422
8454
if (!loaded_module)
8423
8455
return false ;
8424
8456
8425
- modules.emplace_back (swift::ImportedModule (loaded_module));
8457
+ if (modules)
8458
+ modules->emplace_back (swift::ImportedModule (loaded_module));
8426
8459
}
8427
8460
return true ;
8428
8461
}
0 commit comments