Skip to content

Commit c2c8cdb

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)
1 parent 18d23ce commit c2c8cdb

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

11721172
Log *log(GetLog(LLDBLog::DataFormatters));
11731173

1174-
if (!valobj.GetTargetSP()->IsSwiftCxxInteropEnabled())
1175-
return nullptr;
1176-
11771174
CompilerType type(valobj.GetCompilerType());
11781175
auto swift_type_system =
11791176
type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
@@ -1203,6 +1200,29 @@ SwiftLanguage::GetHardcodedSynthetics() {
12031200
return nullptr;
12041201
}
12051202

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

12081228
SyntheticChildrenSP synth_sp =

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

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

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

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

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

0 commit comments

Comments
 (0)