Skip to content

[DNM] [20250402][LLDB] Fix build errors (part 2) #10600

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

Open
wants to merge 1 commit into
base: stable/20250402
Choose a base branch
from
Open
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
61 changes: 38 additions & 23 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,19 @@ CompilerType TypeSystemSwiftTypeRef::GetTypeFromTypeMetadataNode(
TypeSP TypeSystemSwiftTypeRef::LookupClangType(StringRef name_ref) {
llvm::SmallVector<CompilerContext, 2> decl_context;
// Make up a decl context for non-nested types.
decl_context.push_back({CompilerContextKind::AnyModule, ConstString()});
decl_context.push_back({CompilerContextKind::AnyType, ConstString(name_ref)});
return LookupClangType(name_ref, decl_context);
return LookupClangType(name_ref, decl_context, /*ignore_modules=*/true);
}

/// Look up one Clang type in a module.
static TypeSP LookupClangType(Module &m,
llvm::ArrayRef<CompilerContext> decl_context) {
TypeQuery query(decl_context, TypeQueryOptions::e_find_one |
TypeQueryOptions::e_module_search);
llvm::ArrayRef<CompilerContext> decl_context,
bool ignore_modules) {
auto opts = TypeQueryOptions::e_find_one | TypeQueryOptions::e_module_search;
if (ignore_modules) {
opts |= TypeQueryOptions::e_ignore_modules;
}
TypeQuery query(decl_context, opts);
query.SetLanguages(TypeSystemClang::GetSupportedLanguagesForTypes());
TypeResults results;
m.FindTypes(query, results);
Expand All @@ -407,16 +410,17 @@ static TypeSP LookupClangType(Module &m,

TypeSP TypeSystemSwiftTypeRef::LookupClangType(
StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context,
ExecutionContext *exe_ctx) {
bool ignore_modules, ExecutionContext *exe_ctx) {
Module *m = GetModule();
if (!m)
return {};
return ::LookupClangType(const_cast<Module &>(*m), decl_context);
return ::LookupClangType(const_cast<Module &>(*m), decl_context,
ignore_modules);
}

TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType(
StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context,
ExecutionContext *exe_ctx) {
bool ignore_modules, ExecutionContext *exe_ctx) {
// Check the cache first. Negative results are also cached.
TypeSP result;
ConstString name(name_ref);
Expand All @@ -440,7 +444,8 @@ TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType(

// Don't recursively call into LookupClangTypes() to avoid filling
// hundreds of image caches with negative results.
result = ::LookupClangType(const_cast<Module &>(*m), decl_context);
result = ::LookupClangType(const_cast<Module &>(*m), decl_context,
ignore_modules);
// Cache it in the expression context.
if (result)
m_clang_type_cache.Insert(name.AsCString(), result);
Expand All @@ -458,8 +463,9 @@ TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType(

/// Find a Clang type by name in module \p M.
CompilerType TypeSystemSwiftTypeRef::LookupClangForwardType(
StringRef name, llvm::ArrayRef<CompilerContext> decl_context) {
if (TypeSP type = LookupClangType(name, decl_context))
StringRef name, llvm::ArrayRef<CompilerContext> decl_context,
bool ignore_modules) {
if (TypeSP type = LookupClangType(name, decl_context, ignore_modules))
return type->GetForwardCompilerType();
return {};
}
Expand Down Expand Up @@ -939,10 +945,11 @@ GetBuiltinAnyObjectNode(swift::Demangle::Demangler &dem) {
/// Builds the decl context to look up clang types with.
static bool
IsClangImportedType(NodePointer node,
llvm::SmallVectorImpl<CompilerContext> &decl_context) {
llvm::SmallVectorImpl<CompilerContext> &decl_context,
bool &ignore_modules) {
if (node->getKind() == Node::Kind::Module && node->hasText() &&
node->getText() == swift::MANGLING_MODULE_OBJC) {
decl_context.push_back({CompilerContextKind::AnyModule, ConstString()});
ignore_modules = true;
return true;
}

Expand All @@ -954,7 +961,8 @@ IsClangImportedType(NodePointer node,
case Node::Kind::Class:
case Node::Kind::Enum:
case Node::Kind::TypeAlias:
if (!IsClangImportedType(node->getFirstChild(), decl_context))
if (!IsClangImportedType(node->getFirstChild(), decl_context,
ignore_modules))
return false;

// When C++ interop is enabled, Swift enums represent Swift namespaces.
Expand Down Expand Up @@ -996,12 +1004,13 @@ TypeSystemSwiftTypeRef::ResolveTypeAlias(swift::Demangle::Demangler &dem,
auto resolve_clang_type = [&]() -> CompilerType {
// This is an imported Objective-C type; look it up in the debug info.
llvm::SmallVector<CompilerContext, 2> decl_context;
if (!IsClangImportedType(node, decl_context))
bool ignore_modules = false;
if (!IsClangImportedType(node, decl_context, ignore_modules))
return {};

// Resolve the typedef within the Clang debug info.
auto clang_type =
LookupClangForwardType(mangled.GetStringRef(), decl_context);
auto clang_type = LookupClangForwardType(mangled.GetStringRef(),
decl_context, ignore_modules);
if (!clang_type)
return {};

Expand Down Expand Up @@ -1474,12 +1483,14 @@ swift::Demangle::NodePointer TypeSystemSwiftTypeRef::GetSwiftified(
}

llvm::SmallVector<CompilerContext, 2> decl_context;
if (!IsClangImportedType(node, decl_context))
bool ignore_modules = false;
if (!IsClangImportedType(node, decl_context, ignore_modules))
return node;

// This is an imported Objective-C type; look it up in the
// debug info.
TypeSP clang_type = LookupClangType(mangling.result(), decl_context);
TypeSP clang_type =
LookupClangType(mangling.result(), decl_context, ignore_modules);
if (!clang_type)
return node;

Expand Down Expand Up @@ -1856,7 +1867,8 @@ uint32_t TypeSystemSwiftTypeRef::CollectTypeInfo(

// Clang-imported types.
llvm::SmallVector<CompilerContext, 2> decl_context;
if (!IsClangImportedType(node, decl_context))
bool ignore_modules = false;
if (!IsClangImportedType(node, decl_context, ignore_modules))
break;

auto mangling = GetMangledName(dem, node, flavor);
Expand All @@ -1868,7 +1880,8 @@ uint32_t TypeSystemSwiftTypeRef::CollectTypeInfo(
return {};
}
// Resolve the typedef within the Clang debug info.
auto clang_type = LookupClangForwardType(mangling.result(), decl_context);
auto clang_type =
LookupClangForwardType(mangling.result(), decl_context, ignore_modules);
collect_clang_type(clang_type.GetCanonicalType());
return swift_flags;
}
Expand Down Expand Up @@ -4409,10 +4422,12 @@ bool TypeSystemSwiftTypeRef::IsImportedType(opaque_compiler_type_t type,

// This is an imported Objective-C type; look it up in the debug info.
llvm::SmallVector<CompilerContext, 2> decl_context;
if (!IsClangImportedType(node, decl_context))
bool ignore_modules = false;
if (!IsClangImportedType(node, decl_context, ignore_modules))
return false;
if (original_type)
if (TypeSP clang_type = LookupClangType(AsMangledName(type), decl_context))
if (TypeSP clang_type = LookupClangType(AsMangledName(type), decl_context,
ignore_modules))
*original_type = clang_type->GetForwardCompilerType();
return true;
};
Expand Down
17 changes: 9 additions & 8 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
virtual lldb::TypeSP
LookupClangType(llvm::StringRef name_ref,
llvm::ArrayRef<CompilerContext> decl_context,
ExecutionContext *exe_ctx = nullptr);
bool ignore_modules, ExecutionContext *exe_ctx = nullptr);

/// Attempts to convert a Clang type into a Swift type.
/// For example, int is converted to Int32.
Expand Down Expand Up @@ -526,8 +526,10 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
clang::api_notes::APINotesManager *
GetAPINotesManager(ClangExternalASTSourceCallbacks *source, unsigned id);

CompilerType LookupClangForwardType(llvm::StringRef name,
llvm::ArrayRef<CompilerContext> decl_context);
CompilerType
LookupClangForwardType(llvm::StringRef name,
llvm::ArrayRef<CompilerContext> decl_context,
bool ignore_modules);

/// Resolve a type alias node and return a demangle tree for the
/// resolved type. If the type alias resolves to a Clang type, return
Expand Down Expand Up @@ -649,11 +651,10 @@ class TypeSystemSwiftTypeRefForExpressions : public TypeSystemSwiftTypeRef {
unsigned GetGeneration() const { return m_generation; }
/// Performs a target-wide search.
/// \param exe_ctx is a hint for where to look first.
lldb::TypeSP
LookupClangType(llvm::StringRef name_ref,
llvm::ArrayRef<CompilerContext> decl_context,
ExecutionContext *exe_ctx) override;

lldb::TypeSP LookupClangType(llvm::StringRef name_ref,
llvm::ArrayRef<CompilerContext> decl_context,
bool ignore_modules,
ExecutionContext *exe_ctx) override;

friend class SwiftASTContextForExpressions;
protected:
Expand Down