@@ -2689,16 +2689,14 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
26892689 return ModuleSP ();
26902690}
26912691
2692- lldb::TypeSystemSP
2693- SwiftASTContext::CreateInstance (const SymbolContext &sc,
2694- TypeSystemSwiftTypeRef &typeref_typesystem,
2695- const char *extra_options) {
2696- bool is_repl = extra_options;
2692+ lldb::TypeSystemSP SwiftASTContext::CreateInstance (
2693+ const SymbolContext &sc, TypeSystemSwiftTypeRef &typeref_typesystem,
2694+ bool repl, bool playground, const char *extra_options) {
26972695 bool for_expressions =
26982696 llvm::isa<TypeSystemSwiftTypeRefForExpressions>(&typeref_typesystem);
26992697 // REPL requires an expression type system.
2700- assert (!is_repl || for_expressions);
2701- if (is_repl && !for_expressions)
2698+ assert (!repl || for_expressions);
2699+ if (repl && !for_expressions)
27022700 return {};
27032701
27042702 if (!ModuleList::GetGlobalModuleListProperties ()
@@ -2707,26 +2705,24 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27072705
27082706 CompileUnit *cu = sc.comp_unit ;
27092707 const char *key = TypeSystemSwiftTypeRef::DeriveKeyFor (sc);
2708+ bool swift_context = cu && cu->GetLanguage () == eLanguageTypeSwift;
27102709 std::string m_description;
27112710 {
27122711 StreamString ss;
27132712 ss << " SwiftASTContext" ;
27142713 if (for_expressions)
27152714 ss << " ForExpressions" ;
27162715 ss << " (module: " << ' "' << key << " \" , " << " cu: " << ' "' ;
2717- if (cu)
2716+ if (cu && swift_context )
27182717 ss << cu->GetPrimaryFile ().GetFilename ();
27192718 else
2720- ss << " null " ;
2719+ ss << " * " ;
27212720 ss << ' "' << ' )' ;
27222721 m_description = ss.GetString ();
27232722 }
27242723
27252724 LLDB_SCOPED_TIMERF (" %s::CreateInstance" , m_description.c_str ());
27262725
2727- if (is_repl)
2728- LOG_PRINTF (GetLog (LLDBLog::Types), " REPL detected" );
2729-
27302726 // This function can either create an expression/scratch/repl context,
27312727 // or a SwiftAST fallback context for a TypeSystemSwiftTyperef.
27322728 // - SwiftASTContexForExpressions: target=non-null, module=null.
@@ -2770,8 +2766,9 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27702766 if (ShouldEnableEmbeddedSwift (cu))
27712767 lang_opts.enableFeature (swift::Feature::Embedded);
27722768 }
2773- auto defer_log = llvm::make_scope_exit (
2774- [swift_ast_sp, is_repl] { swift_ast_sp->LogConfiguration (is_repl); });
2769+ auto defer_log = llvm::make_scope_exit ([swift_ast_sp, repl, playground] {
2770+ swift_ast_sp->LogConfiguration (repl, playground);
2771+ });
27752772
27762773 LOG_PRINTF (GetLog (LLDBLog::Types), " (Target)" );
27772774 auto logError = [&](const char *message) {
@@ -2797,7 +2794,12 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27972794 ModuleList module_module;
27982795 if (!target_sp)
27992796 module_module.Append (module_sp);
2800- ModuleList &modules = target_sp ? target_sp->GetImages () : module_module;
2797+ // Leave modules empty if not in a Swift context to avoid a fragile
2798+ // and expensive scan through all images. Unless this is a Playground, which
2799+ // has a non-Swift executable, and user code in a framework.
2800+ ModuleList &modules = (target_sp && (swift_context || playground))
2801+ ? target_sp->GetImages ()
2802+ : module_module;
28012803 const size_t num_images = modules.GetSize ();
28022804
28032805 // Set the SDK path prior to doing search paths. Otherwise when we
@@ -2869,7 +2871,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
28692871
28702872 ArchSpec preferred_arch;
28712873 llvm::Triple preferred_triple;
2872- if (is_repl ) {
2874+ if (repl ) {
28732875 LOG_PRINTF (GetLog (LLDBLog::Types), " REPL: prefer target triple." );
28742876 preferred_arch = target_arch;
28752877 preferred_triple = target_triple;
@@ -3133,7 +3135,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
31333135 }
31343136 }
31353137 };
3136- scan_module (module_sp, 0 );
3138+ if (swift_context || playground)
3139+ scan_module (module_sp, 0 );
31373140 for (size_t mi = 0 ; mi != num_images; ++mi) {
31383141 auto image_sp = modules.GetModuleAtIndex (mi);
31393142 if (!visited_modules.count (image_sp.get ()))
@@ -5461,7 +5464,7 @@ void SwiftASTContext::ClearModuleDependentCaches() {
54615464 m_negative_type_cache.Clear ();
54625465}
54635466
5464- void SwiftASTContext::LogConfiguration (bool is_repl ) {
5467+ void SwiftASTContext::LogConfiguration (bool repl, bool playground ) {
54655468 // It makes no sense to call VALID_OR_RETURN here. We specifically
54665469 // want the logs in the error case!
54675470 HEALTH_LOG_PRINTF (" (SwiftASTContext*)%p:" , static_cast <void *>(this ));
@@ -5471,8 +5474,10 @@ void SwiftASTContext::LogConfiguration(bool is_repl) {
54715474 HEALTH_LOG_PRINTF (" (no AST context)" );
54725475 return ;
54735476 }
5474- if (is_repl )
5477+ if (repl )
54755478 HEALTH_LOG_PRINTF (" REPL : true" );
5479+ if (playground)
5480+ HEALTH_LOG_PRINTF (" Playground : true" );
54765481 HEALTH_LOG_PRINTF (" Swift/C++ interop : %s" ,
54775482 ast_context->LangOpts .EnableCXXInterop ? " on" : " off" );
54785483 HEALTH_LOG_PRINTF (" Swift/Objective-C interop : %s" ,
0 commit comments