Skip to content

[next]Cherry picks C++ interop and embedded Swift #10402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ findSwiftSelf(StackFrame &frame, lldb::VariableSP self_var_sp) {
// 2) If (1) fails, try finding the type of `self` from its Variable.
if (!info.type.IsValid())
if (Type *self_lldb_type = self_var_sp->GetType())
info.type = self_var_sp->GetType()->GetForwardCompilerType();
info.type = self_lldb_type->GetForwardCompilerType();

// 3) If (1) and (2) fail, give up.
if (!info.type.IsValid())
Expand Down
22 changes: 14 additions & 8 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2628,8 +2628,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
return swift_ast_sp;
}

/// Determine whether this CU was compiled with C++ interop enabled.
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
bool SwiftASTContext::CheckFlagInCU(CompileUnit *cu, const char *flag) {
AutoBool interop_enabled =
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
switch (interop_enabled) {
Expand All @@ -2643,8 +2642,6 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
lldb::ModuleSP module = cu->CalculateSymbolContextModule();
if (!module)
return false;
// Look for the "-enable-experimental-cxx-interop" compile flag in the
// args of the compile units this module is composed of.
auto *sym_file = module->GetSymbolFile();
if (!sym_file)
return false;
Expand All @@ -2653,7 +2650,7 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
if (unit.get() == cu) {
if (cu->GetLanguage() == eLanguageTypeSwift)
for (const char *arg : args.GetArgumentArrayRef())
if (strcmp(arg, "-enable-experimental-cxx-interop") == 0)
if (strcmp(arg, flag) == 0)
return true;
return false;
}
Expand All @@ -2663,6 +2660,15 @@ bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
return false;
}

/// Determine whether this CU was compiled with C++ interop enabled.
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
return CheckFlagInCU(cu, "-enable-experimental-cxx-interop");
}

bool SwiftASTContext::ShouldEnableEmbeddedSwift(CompileUnit *cu) {
return CheckFlagInCU(cu, "-enable-embedded-swift");
}

static bool IsUnitTestExecutable(lldb_private::Module &module) {
static ConstString s_xctest("xctest");
static ConstString s_XCTRunner("XCTRunner");
Expand Down Expand Up @@ -2776,7 +2782,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
swift_ast_sp->m_is_scratch_context = true;
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
if (target_sp->IsEmbeddedSwift())
if (ShouldEnableEmbeddedSwift(cu))
lang_opts.enableFeature(swift::Feature::Embedded);
} else {
// Typesystem fallback context.
Expand All @@ -2792,8 +2798,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
swift_ast_sp->m_module = module_sp.get();
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
lang_opts.EnableAccessControl = false;
lang_opts.EnableCXXInterop = module_sp->IsSwiftCxxInteropEnabled();
if (module_sp->IsEmbeddedSwift())
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
if (ShouldEnableEmbeddedSwift(cu))
lang_opts.enableFeature(swift::Feature::Embedded);
}
auto defer_log = llvm::make_scope_exit(
Expand Down
6 changes: 5 additions & 1 deletion lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ class SwiftASTContext : public TypeSystemSwift {
TypeSystemSwiftTypeRef &typeref_typesystem,
const char *extra_options = nullptr);

/// Returns true if Swift C++ interop is enabled for the given compiler unit.
/// Returns true if the given flag is present in the given compile unit.
static bool CheckFlagInCU(CompileUnit *cu, const char *flag);

static bool ShouldEnableCXXInterop(CompileUnit *cu);

static bool ShouldEnableEmbeddedSwift(CompileUnit *cu);

static void EnumerateSupportedLanguages(
std::set<lldb::LanguageType> &languages_for_types,
std::set<lldb::LanguageType> &languages_for_expressions);
Expand Down