Skip to content

Commit 234b15b

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 e1099ae commit 234b15b

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

12061206
Log *log(GetLog(LLDBLog::DataFormatters));
12071207

1208-
if (!valobj.GetTargetSP()->IsSwiftCxxInteropEnabled())
1209-
return nullptr;
1210-
12111208
CompilerType type(valobj.GetCompilerType());
12121209
auto swift_type_system =
12131210
type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
@@ -1237,6 +1234,29 @@ SwiftLanguage::GetHardcodedSynthetics() {
12371234
return nullptr;
12381235
}
12391236

1237+
// Find the compile unit and module using the frame, because the value
1238+
// object may not have a module in the case of an expression that
1239+
// evaluates to a type.
1240+
if (!valobj.GetFrameSP())
1241+
return nullptr;
1242+
1243+
auto sc = valobj.GetFrameSP()->GetSymbolContext(
1244+
lldb::SymbolContextItem::eSymbolContextCompUnit |
1245+
lldb::SymbolContextItem::eSymbolContextModule);
1246+
1247+
// If there is a compile unit, use that to check if C++ interop should be
1248+
// enabled. If there is no compiler unit, use the module. If neither
1249+
// exist, assume that C++ interop is disabled.
1250+
if (auto *cu = sc.comp_unit) {
1251+
if (!SwiftASTContext::ShouldEnableCXXInterop(cu))
1252+
return nullptr;
1253+
} else if (sc.module_sp) {
1254+
if (!sc.module_sp->IsSwiftCxxInteropEnabled())
1255+
return nullptr;
1256+
} else {
1257+
return nullptr;
1258+
}
1259+
12401260
casted->SetName(ConstString("Clang_Type"));
12411261

12421262
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)