Skip to content

Commit ef04292

Browse files
committed
[lldb] Check if interop is enabled only on compile unit
When deciding whether to format a C++ type as a Swiftified type or not, checking if Swift/C++ interop is enabled on the entire target can be very expensive for big projects, and may not swiftify types that should be. rdar://117708944 (cherry picked from commit fe06ebc) (cherry picked from commit 234b15b)
1 parent 517274e commit ef04292

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,9 +1165,6 @@ SwiftLanguage::GetHardcodedSynthetics() {
11651165

11661166
Log *log(GetLog(LLDBLog::DataFormatters));
11671167

1168-
if (!valobj.GetTargetSP()->IsSwiftCxxInteropEnabled())
1169-
return nullptr;
1170-
11711168
CompilerType type(valobj.GetCompilerType());
11721169
auto swift_type_system =
11731170
type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
@@ -1197,6 +1194,29 @@ SwiftLanguage::GetHardcodedSynthetics() {
11971194
return nullptr;
11981195
}
11991196

1197+
// Find the compile unit and module using the frame, because the value
1198+
// object may not have a module in the case of an expression that
1199+
// evaluates to a type.
1200+
if (!valobj.GetFrameSP())
1201+
return nullptr;
1202+
1203+
auto sc = valobj.GetFrameSP()->GetSymbolContext(
1204+
lldb::SymbolContextItem::eSymbolContextCompUnit |
1205+
lldb::SymbolContextItem::eSymbolContextModule);
1206+
1207+
// If there is a compile unit, use that to check if C++ interop should be
1208+
// enabled. If there is no compiler unit, use the module. If neither
1209+
// exist, assume that C++ interop is disabled.
1210+
if (auto *cu = sc.comp_unit) {
1211+
if (!SwiftASTContext::ShouldEnableCXXInterop(cu))
1212+
return nullptr;
1213+
} else if (sc.module_sp) {
1214+
if (!sc.module_sp->IsSwiftCxxInteropEnabled())
1215+
return nullptr;
1216+
} else {
1217+
return nullptr;
1218+
}
1219+
12001220
casted->SetName(ConstString("Clang_Type"));
12011221

12021222
SyntheticChildrenSP synth_sp =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2626,7 +2626,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
26262626
}
26272627

26282628
/// Determine whether this CU was compiled with C++ interop enabled.
2629-
static bool ShouldEnableCXXInterop(CompileUnit *cu) {
2629+
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26302630
AutoBool interop_enabled =
26312631
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
26322632
switch (interop_enabled) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ 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.
213+
static bool ShouldEnableCXXInterop(CompileUnit *cu);
214+
212215
static void EnumerateSupportedLanguages(
213216
std::set<lldb::LanguageType> &languages_for_types,
214217
std::set<lldb::LanguageType> &languages_for_expressions);

0 commit comments

Comments
 (0)