@@ -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 ()
@@ -2707,26 +2705,24 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
2707
2705
2708
2706
CompileUnit *cu = sc.comp_unit ;
2709
2707
const char *key = TypeSystemSwiftTypeRef::DeriveKeyFor (sc);
2708
+ bool swift_context = cu && cu->GetLanguage () == eLanguageTypeSwift;
2710
2709
std::string m_description;
2711
2710
{
2712
2711
StreamString ss;
2713
2712
ss << " SwiftASTContext" ;
2714
2713
if (for_expressions)
2715
2714
ss << " ForExpressions" ;
2716
2715
ss << " (module: " << ' "' << key << " \" , " << " cu: " << ' "' ;
2717
- if (cu)
2716
+ if (cu && swift_context )
2718
2717
ss << cu->GetPrimaryFile ().GetFilename ();
2719
2718
else
2720
- ss << " null " ;
2719
+ ss << " * " ;
2721
2720
ss << ' "' << ' )' ;
2722
2721
m_description = ss.GetString ();
2723
2722
}
2724
2723
2725
2724
LLDB_SCOPED_TIMERF (" %s::CreateInstance" , m_description.c_str ());
2726
2725
2727
- if (is_repl)
2728
- LOG_PRINTF (GetLog (LLDBLog::Types), " REPL detected" );
2729
-
2730
2726
// This function can either create an expression/scratch/repl context,
2731
2727
// or a SwiftAST fallback context for a TypeSystemSwiftTyperef.
2732
2728
// - SwiftASTContexForExpressions: target=non-null, module=null.
@@ -2770,8 +2766,9 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
2770
2766
if (ShouldEnableEmbeddedSwift (cu))
2771
2767
lang_opts.enableFeature (swift::Feature::Embedded);
2772
2768
}
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
+ });
2775
2772
2776
2773
LOG_PRINTF (GetLog (LLDBLog::Types), " (Target)" );
2777
2774
auto logError = [&](const char *message) {
@@ -2797,7 +2794,12 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
2797
2794
ModuleList module_module;
2798
2795
if (!target_sp)
2799
2796
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;
2801
2803
const size_t num_images = modules.GetSize ();
2802
2804
2803
2805
// Set the SDK path prior to doing search paths. Otherwise when we
@@ -2869,7 +2871,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
2869
2871
2870
2872
ArchSpec preferred_arch;
2871
2873
llvm::Triple preferred_triple;
2872
- if (is_repl ) {
2874
+ if (repl ) {
2873
2875
LOG_PRINTF (GetLog (LLDBLog::Types), " REPL: prefer target triple." );
2874
2876
preferred_arch = target_arch;
2875
2877
preferred_triple = target_triple;
@@ -3133,7 +3135,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
3133
3135
}
3134
3136
}
3135
3137
};
3136
- scan_module (module_sp, 0 );
3138
+ if (swift_context || playground)
3139
+ scan_module (module_sp, 0 );
3137
3140
for (size_t mi = 0 ; mi != num_images; ++mi) {
3138
3141
auto image_sp = modules.GetModuleAtIndex (mi);
3139
3142
if (!visited_modules.count (image_sp.get ()))
@@ -5461,7 +5464,7 @@ void SwiftASTContext::ClearModuleDependentCaches() {
5461
5464
m_negative_type_cache.Clear ();
5462
5465
}
5463
5466
5464
- void SwiftASTContext::LogConfiguration (bool is_repl ) {
5467
+ void SwiftASTContext::LogConfiguration (bool repl, bool playground ) {
5465
5468
// It makes no sense to call VALID_OR_RETURN here. We specifically
5466
5469
// want the logs in the error case!
5467
5470
HEALTH_LOG_PRINTF (" (SwiftASTContext*)%p:" , static_cast <void *>(this ));
@@ -5471,8 +5474,10 @@ void SwiftASTContext::LogConfiguration(bool is_repl) {
5471
5474
HEALTH_LOG_PRINTF (" (no AST context)" );
5472
5475
return ;
5473
5476
}
5474
- if (is_repl )
5477
+ if (repl )
5475
5478
HEALTH_LOG_PRINTF (" REPL : true" );
5479
+ if (playground)
5480
+ HEALTH_LOG_PRINTF (" Playground : true" );
5476
5481
HEALTH_LOG_PRINTF (" Swift/C++ interop : %s" ,
5477
5482
ast_context->LangOpts .EnableCXXInterop ? " on" : " off" );
5478
5483
HEALTH_LOG_PRINTF (" Swift/Objective-C interop : %s" ,
0 commit comments