Skip to content

Commit fe06ebc

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
1 parent bb2ca20 commit fe06ebc

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
@@ -1159,9 +1159,6 @@ SwiftLanguage::GetHardcodedSynthetics() {
11591159

11601160
Log *log(GetLog(LLDBLog::DataFormatters));
11611161

1162-
if (!valobj.GetTargetSP()->IsSwiftCxxInteropEnabled())
1163-
return nullptr;
1164-
11651162
CompilerType type(valobj.GetCompilerType());
11661163
auto swift_type_system =
11671164
type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
@@ -1191,6 +1188,29 @@ SwiftLanguage::GetHardcodedSynthetics() {
11911188
return nullptr;
11921189
}
11931190

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

11961216
SyntheticChildrenSP synth_sp =

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

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

22662266
/// Determine whether this CU was compiled with C++ interop enabled.
2267-
static bool ShouldEnableCXXInterop(CompileUnit *cu) {
2267+
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
22682268
AutoBool interop_enabled =
22692269
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
22702270
switch (interop_enabled) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ class SwiftASTContext : public TypeSystemSwift {
208208
CreateInstance(const SymbolContext &sc,
209209
TypeSystemSwiftTypeRefForExpressions &typeref_typesystem);
210210

211+
/// Returns true if Swift C++ interop is enabled for the given compiler unit.
212+
static bool ShouldEnableCXXInterop(CompileUnit *cu);
213+
211214
static void EnumerateSupportedLanguages(
212215
std::set<lldb::LanguageType> &languages_for_types,
213216
std::set<lldb::LanguageType> &languages_for_expressions);

0 commit comments

Comments
 (0)