Skip to content

Commit 7f45546

Browse files
authored
Merge pull request swiftlang#10402 from augusto2112/cp-010425
[next]Cherry picks C++ interop and embedded Swift
2 parents 525f82c + 8fb2042 commit 7f45546

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ findSwiftSelf(StackFrame &frame, lldb::VariableSP self_var_sp) {
157157
// 2) If (1) fails, try finding the type of `self` from its Variable.
158158
if (!info.type.IsValid())
159159
if (Type *self_lldb_type = self_var_sp->GetType())
160-
info.type = self_var_sp->GetType()->GetForwardCompilerType();
160+
info.type = self_lldb_type->GetForwardCompilerType();
161161

162162
// 3) If (1) and (2) fail, give up.
163163
if (!info.type.IsValid())

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,8 +2628,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
26282628
return swift_ast_sp;
26292629
}
26302630

2631-
/// Determine whether this CU was compiled with C++ interop enabled.
2632-
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
2631+
bool SwiftASTContext::CheckFlagInCU(CompileUnit *cu, const char *flag) {
26332632
AutoBool interop_enabled =
26342633
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
26352634
switch (interop_enabled) {
@@ -2643,8 +2642,6 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26432642
lldb::ModuleSP module = cu->CalculateSymbolContextModule();
26442643
if (!module)
26452644
return false;
2646-
// Look for the "-enable-experimental-cxx-interop" compile flag in the
2647-
// args of the compile units this module is composed of.
26482645
auto *sym_file = module->GetSymbolFile();
26492646
if (!sym_file)
26502647
return false;
@@ -2653,7 +2650,7 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26532650
if (unit.get() == cu) {
26542651
if (cu->GetLanguage() == eLanguageTypeSwift)
26552652
for (const char *arg : args.GetArgumentArrayRef())
2656-
if (strcmp(arg, "-enable-experimental-cxx-interop") == 0)
2653+
if (strcmp(arg, flag) == 0)
26572654
return true;
26582655
return false;
26592656
}
@@ -2663,6 +2660,15 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
26632660
return false;
26642661
}
26652662

2663+
/// Determine whether this CU was compiled with C++ interop enabled.
2664+
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
2665+
return CheckFlagInCU(cu, "-enable-experimental-cxx-interop");
2666+
}
2667+
2668+
bool SwiftASTContext::ShouldEnableEmbeddedSwift(CompileUnit *cu) {
2669+
return CheckFlagInCU(cu, "-enable-embedded-swift");
2670+
}
2671+
26662672
static bool IsUnitTestExecutable(lldb_private::Module &module) {
26672673
static ConstString s_xctest("xctest");
26682674
static ConstString s_XCTRunner("XCTRunner");
@@ -2776,7 +2782,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27762782
swift_ast_sp->m_is_scratch_context = true;
27772783
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27782784
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2779-
if (target_sp->IsEmbeddedSwift())
2785+
if (ShouldEnableEmbeddedSwift(cu))
27802786
lang_opts.enableFeature(swift::Feature::Embedded);
27812787
} else {
27822788
// Typesystem fallback context.
@@ -2792,8 +2798,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27922798
swift_ast_sp->m_module = module_sp.get();
27932799
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27942800
lang_opts.EnableAccessControl = false;
2795-
lang_opts.EnableCXXInterop = module_sp->IsSwiftCxxInteropEnabled();
2796-
if (module_sp->IsEmbeddedSwift())
2801+
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2802+
if (ShouldEnableEmbeddedSwift(cu))
27972803
lang_opts.enableFeature(swift::Feature::Embedded);
27982804
}
27992805
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
@@ -210,9 +210,13 @@ 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.
213+
/// Returns true if the given flag is present in the given compile unit.
214+
static bool CheckFlagInCU(CompileUnit *cu, const char *flag);
215+
214216
static bool ShouldEnableCXXInterop(CompileUnit *cu);
215217

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

0 commit comments

Comments
 (0)