@@ -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 ()
@@ -2725,9 +2723,6 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27252723
27262724 LLDB_SCOPED_TIMERF (" %s::CreateInstance" , m_description.c_str ());
27272725
2728- if (is_repl)
2729- LOG_PRINTF (GetLog (LLDBLog::Types), " REPL detected" );
2730-
27312726 // This function can either create an expression/scratch/repl context,
27322727 // or a SwiftAST fallback context for a TypeSystemSwiftTyperef.
27332728 // - SwiftASTContexForExpressions: target=non-null, module=null.
@@ -2771,8 +2766,9 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27712766 if (ShouldEnableEmbeddedSwift (cu))
27722767 lang_opts.enableFeature (swift::Feature::Embedded);
27732768 }
2774- auto defer_log = llvm::make_scope_exit (
2775- [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+ });
27762772
27772773 LOG_PRINTF (GetLog (LLDBLog::Types), " (Target)" );
27782774 auto logError = [&](const char *message) {
@@ -2798,8 +2794,12 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27982794 ModuleList module_module;
27992795 if (!target_sp)
28002796 module_module.Append (module_sp);
2801- ModuleList &modules =
2802- (target_sp && swift_context) ? 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;
28032803 const size_t num_images = modules.GetSize ();
28042804
28052805 // Set the SDK path prior to doing search paths. Otherwise when we
@@ -2871,7 +2871,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
28712871
28722872 ArchSpec preferred_arch;
28732873 llvm::Triple preferred_triple;
2874- if (is_repl ) {
2874+ if (repl ) {
28752875 LOG_PRINTF (GetLog (LLDBLog::Types), " REPL: prefer target triple." );
28762876 preferred_arch = target_arch;
28772877 preferred_triple = target_triple;
@@ -3135,7 +3135,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
31353135 }
31363136 }
31373137 };
3138- if (swift_context)
3138+ if (swift_context || playground )
31393139 scan_module (module_sp, 0 );
31403140 for (size_t mi = 0 ; mi != num_images; ++mi) {
31413141 auto image_sp = modules.GetModuleAtIndex (mi);
@@ -5464,7 +5464,7 @@ void SwiftASTContext::ClearModuleDependentCaches() {
54645464 m_negative_type_cache.Clear ();
54655465}
54665466
5467- void SwiftASTContext::LogConfiguration (bool is_repl ) {
5467+ void SwiftASTContext::LogConfiguration (bool repl, bool playground ) {
54685468 // It makes no sense to call VALID_OR_RETURN here. We specifically
54695469 // want the logs in the error case!
54705470 HEALTH_LOG_PRINTF (" (SwiftASTContext*)%p:" , static_cast <void *>(this ));
@@ -5474,8 +5474,10 @@ void SwiftASTContext::LogConfiguration(bool is_repl) {
54745474 HEALTH_LOG_PRINTF (" (no AST context)" );
54755475 return ;
54765476 }
5477- if (is_repl )
5477+ if (repl )
54785478 HEALTH_LOG_PRINTF (" REPL : true" );
5479+ if (playground)
5480+ HEALTH_LOG_PRINTF (" Playground : true" );
54795481 HEALTH_LOG_PRINTF (" Swift/C++ interop : %s" ,
54805482 ast_context->LangOpts .EnableCXXInterop ? " on" : " off" );
54815483 HEALTH_LOG_PRINTF (" Swift/Objective-C interop : %s" ,
0 commit comments