diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp index c897b2dc824e6..aebd4738b4f92 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp @@ -389,16 +389,19 @@ CompilerType TypeSystemSwiftTypeRef::GetTypeFromTypeMetadataNode( TypeSP TypeSystemSwiftTypeRef::LookupClangType(StringRef name_ref) { llvm::SmallVector 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 decl_context) { - TypeQuery query(decl_context, TypeQueryOptions::e_find_one | - TypeQueryOptions::e_module_search); + llvm::ArrayRef 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); @@ -407,16 +410,17 @@ static TypeSP LookupClangType(Module &m, TypeSP TypeSystemSwiftTypeRef::LookupClangType( StringRef name_ref, llvm::ArrayRef decl_context, - ExecutionContext *exe_ctx) { + bool ignore_modules, ExecutionContext *exe_ctx) { Module *m = GetModule(); if (!m) return {}; - return ::LookupClangType(const_cast(*m), decl_context); + return ::LookupClangType(const_cast(*m), decl_context, + ignore_modules); } TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType( StringRef name_ref, llvm::ArrayRef 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); @@ -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(*m), decl_context); + result = ::LookupClangType(const_cast(*m), decl_context, + ignore_modules); // Cache it in the expression context. if (result) m_clang_type_cache.Insert(name.AsCString(), result); @@ -458,8 +463,9 @@ TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType( /// Find a Clang type by name in module \p M. CompilerType TypeSystemSwiftTypeRef::LookupClangForwardType( - StringRef name, llvm::ArrayRef decl_context) { - if (TypeSP type = LookupClangType(name, decl_context)) + StringRef name, llvm::ArrayRef decl_context, + bool ignore_modules) { + if (TypeSP type = LookupClangType(name, decl_context, ignore_modules)) return type->GetForwardCompilerType(); return {}; } @@ -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 &decl_context) { + llvm::SmallVectorImpl &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; } @@ -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. @@ -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 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 {}; @@ -1474,12 +1483,14 @@ swift::Demangle::NodePointer TypeSystemSwiftTypeRef::GetSwiftified( } llvm::SmallVector 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; @@ -1856,7 +1867,8 @@ uint32_t TypeSystemSwiftTypeRef::CollectTypeInfo( // Clang-imported types. llvm::SmallVector 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); @@ -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; } @@ -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 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; }; diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h index 26ae85e387597..2308daefb7a2e 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h @@ -427,7 +427,7 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift { virtual lldb::TypeSP LookupClangType(llvm::StringRef name_ref, llvm::ArrayRef 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. @@ -526,8 +526,10 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift { clang::api_notes::APINotesManager * GetAPINotesManager(ClangExternalASTSourceCallbacks *source, unsigned id); - CompilerType LookupClangForwardType(llvm::StringRef name, - llvm::ArrayRef decl_context); + CompilerType + LookupClangForwardType(llvm::StringRef name, + llvm::ArrayRef 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 @@ -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 decl_context, - ExecutionContext *exe_ctx) override; - + lldb::TypeSP LookupClangType(llvm::StringRef name_ref, + llvm::ArrayRef decl_context, + bool ignore_modules, + ExecutionContext *exe_ctx) override; friend class SwiftASTContextForExpressions; protected: