Skip to content

Commit 03ee42c

Browse files
committed
[lldb] Check if Embedded Swift is enabled only on the compile unit
Reading debug info of an entire module to check whether embedded Swift is enabled or not can be very slow. This patch replaces that check with only checking the compile unit instead. rdar://147009063
1 parent 234b15b commit 03ee42c

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,8 +2628,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
26282628
return swift_ast_sp;
26292629
}
26302630

2631-
/// Determine whether this CU was compiled with C++ interop enabled.
2632-
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
2631+
bool SwiftASTContext::CheckFlagInCU(CompileUnit *cu, const char *flag) {
26332632
AutoBool interop_enabled =
26342633
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
26352634
switch (interop_enabled) {
@@ -2643,8 +2642,6 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26432642
lldb::ModuleSP module = cu->CalculateSymbolContextModule();
26442643
if (!module)
26452644
return false;
2646-
// Look for the "-enable-experimental-cxx-interop" compile flag in the
2647-
// args of the compile units this module is composed of.
26482645
auto *sym_file = module->GetSymbolFile();
26492646
if (!sym_file)
26502647
return false;
@@ -2653,7 +2650,7 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26532650
if (unit.get() == cu) {
26542651
if (cu->GetLanguage() == eLanguageTypeSwift)
26552652
for (const char *arg : args.GetArgumentArrayRef())
2656-
if (strcmp(arg, "-enable-experimental-cxx-interop") == 0)
2653+
if (strcmp(arg, flag) == 0)
26572654
return true;
26582655
return false;
26592656
}
@@ -2663,6 +2660,15 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26632660
return false;
26642661
}
26652662

2663+
/// Determine whether this CU was compiled with C++ interop enabled.
2664+
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
2665+
return CheckFlagInCU(cu, "-enable-experimental-cxx-interop");
2666+
}
2667+
2668+
bool SwiftASTContext::ShouldEnableEmbeddedSwift(CompileUnit *cu) {
2669+
return CheckFlagInCU(cu, "-enable-embedded-swift");
2670+
}
2671+
26662672
static bool IsUnitTestExecutable(lldb_private::Module &module) {
26672673
static ConstString s_xctest("xctest");
26682674
static ConstString s_XCTRunner("XCTRunner");
@@ -2776,7 +2782,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27762782
swift_ast_sp->m_is_scratch_context = true;
27772783
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27782784
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2779-
if (target_sp->IsEmbeddedSwift())
2785+
if (ShouldEnableEmbeddedSwift(cu))
27802786
lang_opts.enableFeature(swift::Feature::Embedded);
27812787
} else {
27822788
// Typesystem fallback context.
@@ -2793,7 +2799,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27932799
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27942800
lang_opts.EnableAccessControl = false;
27952801
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2796-
if (module_sp->IsEmbeddedSwift())
2802+
if (ShouldEnableEmbeddedSwift(cu))
27972803
lang_opts.enableFeature(swift::Feature::Embedded);
27982804
}
27992805
auto defer_log = llvm::make_scope_exit(

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,13 @@ class SwiftASTContext : public TypeSystemSwift {
210210
TypeSystemSwiftTypeRef &typeref_typesystem,
211211
const char *extra_options = nullptr);
212212

213-
/// Returns true if Swift C++ interop is enabled for the given compiler unit.
213+
/// Returns true if the given flag is present in the given compile unit.
214+
static bool CheckFlagInCU(CompileUnit *cu, const char *flag);
215+
214216
static bool ShouldEnableCXXInterop(CompileUnit *cu);
215217

218+
static bool ShouldEnableEmbeddedSwift(CompileUnit *cu);
219+
216220
static void EnumerateSupportedLanguages(
217221
std::set<lldb::LanguageType> &languages_for_types,
218222
std::set<lldb::LanguageType> &languages_for_expressions);

0 commit comments

Comments
 (0)