@@ -2689,16 +2689,14 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
2689
2689
return ModuleSP ();
2690
2690
}
2691
2691
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) {
2697
2695
bool for_expressions =
2698
2696
llvm::isa<TypeSystemSwiftTypeRefForExpressions>(&typeref_typesystem);
2699
2697
// 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)
2702
2700
return {};
2703
2701
2704
2702
if (!ModuleList::GetGlobalModuleListProperties ()
@@ -2725,9 +2723,6 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
2725
2723
2726
2724
LLDB_SCOPED_TIMERF (" %s::CreateInstance" , m_description.c_str ());
2727
2725
2728
- if (is_repl)
2729
- LOG_PRINTF (GetLog (LLDBLog::Types), " REPL detected" );
2730
-
2731
2726
// This function can either create an expression/scratch/repl context,
2732
2727
// or a SwiftAST fallback context for a TypeSystemSwiftTyperef.
2733
2728
// - SwiftASTContexForExpressions: target=non-null, module=null.
@@ -2771,8 +2766,9 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
2771
2766
if (ShouldEnableEmbeddedSwift (cu))
2772
2767
lang_opts.enableFeature (swift::Feature::Embedded);
2773
2768
}
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
+ });
2776
2772
2777
2773
LOG_PRINTF (GetLog (LLDBLog::Types), " (Target)" );
2778
2774
auto logError = [&](const char *message) {
@@ -2798,8 +2794,12 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
2798
2794
ModuleList module_module;
2799
2795
if (!target_sp)
2800
2796
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;
2803
2803
const size_t num_images = modules.GetSize ();
2804
2804
2805
2805
// Set the SDK path prior to doing search paths. Otherwise when we
@@ -2871,7 +2871,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
2871
2871
2872
2872
ArchSpec preferred_arch;
2873
2873
llvm::Triple preferred_triple;
2874
- if (is_repl ) {
2874
+ if (repl ) {
2875
2875
LOG_PRINTF (GetLog (LLDBLog::Types), " REPL: prefer target triple." );
2876
2876
preferred_arch = target_arch;
2877
2877
preferred_triple = target_triple;
@@ -3135,7 +3135,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
3135
3135
}
3136
3136
}
3137
3137
};
3138
- if (swift_context)
3138
+ if (swift_context || playground )
3139
3139
scan_module (module_sp, 0 );
3140
3140
for (size_t mi = 0 ; mi != num_images; ++mi) {
3141
3141
auto image_sp = modules.GetModuleAtIndex (mi);
@@ -5464,7 +5464,7 @@ void SwiftASTContext::ClearModuleDependentCaches() {
5464
5464
m_negative_type_cache.Clear ();
5465
5465
}
5466
5466
5467
- void SwiftASTContext::LogConfiguration (bool is_repl ) {
5467
+ void SwiftASTContext::LogConfiguration (bool repl, bool playground ) {
5468
5468
// It makes no sense to call VALID_OR_RETURN here. We specifically
5469
5469
// want the logs in the error case!
5470
5470
HEALTH_LOG_PRINTF (" (SwiftASTContext*)%p:" , static_cast <void *>(this ));
@@ -5474,8 +5474,10 @@ void SwiftASTContext::LogConfiguration(bool is_repl) {
5474
5474
HEALTH_LOG_PRINTF (" (no AST context)" );
5475
5475
return ;
5476
5476
}
5477
- if (is_repl )
5477
+ if (repl )
5478
5478
HEALTH_LOG_PRINTF (" REPL : true" );
5479
+ if (playground)
5480
+ HEALTH_LOG_PRINTF (" Playground : true" );
5479
5481
HEALTH_LOG_PRINTF (" Swift/C++ interop : %s" ,
5480
5482
ast_context->LangOpts .EnableCXXInterop ? " on" : " off" );
5481
5483
HEALTH_LOG_PRINTF (" Swift/Objective-C interop : %s" ,
0 commit comments