Skip to content

Commit 093f680

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 (cherry picked from commit 03ee42c)
1 parent ef04292 commit 093f680

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
@@ -2625,8 +2625,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
26252625
return swift_ast_sp;
26262626
}
26272627

2628-
/// Determine whether this CU was compiled with C++ interop enabled.
2629-
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
2628+
bool SwiftASTContext::CheckFlagInCU(CompileUnit *cu, const char *flag) {
26302629
AutoBool interop_enabled =
26312630
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
26322631
switch (interop_enabled) {
@@ -2640,8 +2639,6 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26402639
lldb::ModuleSP module = cu->CalculateSymbolContextModule();
26412640
if (!module)
26422641
return false;
2643-
// Look for the "-enable-experimental-cxx-interop" compile flag in the
2644-
// args of the compile units this module is composed of.
26452642
auto *sym_file = module->GetSymbolFile();
26462643
if (!sym_file)
26472644
return false;
@@ -2650,7 +2647,7 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26502647
if (unit.get() == cu) {
26512648
if (cu->GetLanguage() == eLanguageTypeSwift)
26522649
for (const char *arg : args.GetArgumentArrayRef())
2653-
if (strcmp(arg, "-enable-experimental-cxx-interop") == 0)
2650+
if (strcmp(arg, flag) == 0)
26542651
return true;
26552652
return false;
26562653
}
@@ -2660,6 +2657,15 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26602657
return false;
26612658
}
26622659

2660+
/// Determine whether this CU was compiled with C++ interop enabled.
2661+
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
2662+
return CheckFlagInCU(cu, "-enable-experimental-cxx-interop");
2663+
}
2664+
2665+
bool SwiftASTContext::ShouldEnableEmbeddedSwift(CompileUnit *cu) {
2666+
return CheckFlagInCU(cu, "-enable-embedded-swift");
2667+
}
2668+
26632669
static bool IsUnitTestExecutable(lldb_private::Module &module) {
26642670
static ConstString s_xctest("xctest");
26652671
static ConstString s_XCTRunner("XCTRunner");
@@ -2773,7 +2779,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27732779
swift_ast_sp->m_is_scratch_context = true;
27742780
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27752781
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2776-
if (target_sp->IsEmbeddedSwift())
2782+
if (ShouldEnableEmbeddedSwift(cu))
27772783
lang_opts.enableFeature(swift::Feature::Embedded);
27782784
} else {
27792785
// Typesystem fallback context.
@@ -2790,7 +2796,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27902796
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27912797
lang_opts.EnableAccessControl = false;
27922798
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2793-
if (module_sp->IsEmbeddedSwift())
2799+
if (ShouldEnableEmbeddedSwift(cu))
27942800
lang_opts.enableFeature(swift::Feature::Embedded);
27952801
}
27962802
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
@@ -209,9 +209,13 @@ class SwiftASTContext : public TypeSystemSwift {
209209
TypeSystemSwiftTypeRef &typeref_typesystem,
210210
const char *extra_options = nullptr);
211211

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

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

0 commit comments

Comments
 (0)