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