summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
AgeCommit message (Collapse)Author
2025-01-17[AST] Add OriginalDC argument to ↵Chuanqi Xu
ExternalASTSource::FindExternalVisibleDeclsByName (#123152) Part for relanding https://github.com/llvm/llvm-project/pull/122887. I split this to test where the performance regession comes from if modules are not used.
2025-01-16Revert "[C++20] [Modules] Support module level lookup (#122887)"Chuanqi Xu
This reverts commit 7201cae106260aeb3e9bbbb7d5291ff30f05076a.
2025-01-15[C++20] [Modules] Support module level lookup (#122887)Chuanqi Xu
Close https://github.com/llvm/llvm-project/issues/90154 This patch is also an optimization to the lookup process to utilize the information provided by `export` keyword. Previously, in the lookup process, the `export` keyword only takes part in the check part, it doesn't get involved in the lookup process. That said, previously, in a name lookup for 'name', we would load all of declarations with the name 'name' and check if these declarations are valid or not. It works well. But it is inefficient since it may load declarations that may not be wanted. Note that this patch actually did a trick in the lookup process instead of bring module information to DeclarationName or considering module information when deciding if two declarations are the same. So it may not be a surprise to me if there are missing cases. But it is not a regression. It should be already the case. Issue reports are welcomed. In this patch, I tried to split the big lookup table into a lookup table as before and a module local lookup table, which takes a combination of the ID of the DeclContext and hash value of the primary module name as the key. And refactored `DeclContext::lookup()` method to take the module information. So that a lookup in a DeclContext won't load declarations that are local to **other** modules. And also I think it is already beneficial to split the big lookup table since it may reduce the conflicts during lookups in the hash table. BTW, this patch introduced a **regression** for a reachability rule in C++20 but it was false-negative. See 'clang/test/CXX/module/module.interface/p7.cpp' for details. This patch is not expected to introduce any other regressions for non-c++20-modules users since the module local lookup table should be empty for them. --- On the API side, this patch unfortunately add a maybe-confusing argument `Module *NamedModule` to `ExternalASTSource::FindExternalVisibleDeclsByName()`. People may think we can get the information from the first argument `const DeclContext *DC`. But sadly there are declarations (e.g., namespace) can appear in multiple different modules as a single declaration. So we have to add additional information to indicate this.
2024-06-03[clang][Modules] Move `ASTSourceDescriptor` into its own file (#67930)David Stone
2023-01-07[lldb] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to clean up the "using" declarations, #include "llvm/ADT/Optional.h", etc. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07[lldb] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2020-05-27[lldb] Don't complete ObjCInterfaceDecls in ↵Raphael Isemann
ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName Summary: For ObjCInterfaceDecls, LLDB iterates over the `methods` of the interface in FindExternalVisibleDeclsByName since commit ef423a3ba57045f80b0fcafce72121449a8b54d4 . However, when LLDB calls `oid->methods()` in that function, Clang will pull in all declarations in the current DeclContext from the current ExternalASTSource (which is again, `ClangExternalASTSourceCallbacks`). The reason for that is that `methods()` is just a wrapper for `decls()` which is supposed to provide a list of *all* (both currently loaded and external) decls in the DeclContext. However, `ClangExternalASTSourceCallbacks::FindExternalLexicalDecls` doesn't implement support for ObjCInterfaceDecl, so we don't actually add any declarations and just mark the ObjCInterfaceDecl as having no ExternalLexicalStorage. As LLDB uses the ExternalLexicalStorage to see if it can complete a type with the ExternalASTSource, this causes that LLDB thinks our class can't be completed any further by the ExternalASTSource and will from on no longer make any CompleteType/FindExternalLexicalDecls calls to that decl. This essentially renders those types unusable in the expression parser as they will always be considered incomplete. This patch just changes the call to `methods` (which is just a `decls()` wrapper), to some ad-hoc `noload_methods` call which is wrapping `noload_decls()`. `noload_decls()` won't trigger any calls to the ExternalASTSource, so this prevents that ExternalLexicalStorage will be set to false. The test for this is just adding a method to an ObjC interface. Before this patch, this unset the ExternalLexicalStorage flag and put the interface into the state described above. In a normal user session this situation was triggered by setting a breakpoint in a method of some ObjC class. This caused LLDB to create the MethodDecl for that specific method and put it into the the ObjCInterfaceDecl. Also `ObjCLanguageRuntime::LookupInCompleteClassCache` needs to be unable to resolve the type do an actual definition when the breakpoint is set (I'm not sure how exactly this can happen, but we just found no Type instance that had the `TypePayloadClang::IsCompleteObjCClass` flag set in its payload in the situation where this happens. This however doesn't seem to be a regression as logic wasn't changed from what I can see). The module-ownership.mm test had to be changed as the only reason why the ObjC interface in that test had it's ExternalLexicalStorage flag set to false was because of this unintended side effect. What actually happens in the test is that ExternalLexicalStorage is first set to false in `DWARFASTParserClang::CompleteTypeFromDWARF` when we try to complete the `SomeClass` interface, but is then the flag is set back to true once we add the last ivar of `SomeClass` (see `SetMemberOwningModule` in `TypeSystemClang.cpp` which is called when we add the ivar). I'll fix the code for that in a follow-up patch. I think some of the code here needs some rethinking. LLDB and Clang shouldn't infer anything about the ExternalASTSource and its ability to complete the current type form the `ExternalLexicalStorage` flag. We probably should also actually provide any declarations when we get asked for the lexical decls of an ObjCInterfaceDecl. But both of those changes are bigger (and most likely would cause us to eagerly complete more types), so those will be follow up patches and this patch just brings us back to the state before commit ef423a3ba57045f80b0fcafce72121449a8b54d4 . Fixes rdar://63584164 Reviewers: aprantl, friss, shafik Reviewed By: aprantl, shafik Subscribers: arphaman, abidh, JDevlieghere Differential Revision: https://reviews.llvm.org/D80556
2020-04-24Add Objective-C property accessors loaded from Clang module DWARF to lookupAdrian Prantl
This patch fixes a bug when synthesizing an ObjC property from -gmodules debug info. Because the method declaration that is injected via the non-modular property implementation is not added to the ObjCInterfaceDecl's lookup pointer, a second copy of the accessor would be generated when processing the ObjCPropertyDecl. This can be avoided by finding the existing method decl in ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName() and adding it to the LookupPtr. Differential Revision: https://reviews.llvm.org/D78333
2020-04-09Preserve the owning module information from DWARF in the synthesized ASTAdrian Prantl
Types that came from a Clang module are nested in DW_TAG_module tags in DWARF. This patch recreates the Clang module hierarchy in LLDB and 1;95;0csets the owning module information accordingly. My primary motivation is to facilitate looking up per-module APINotes for individual declarations, but this likely also has other applications. This reapplies the previously reverted commit, but without support for ClassTemplateSpecializations, which I'm going to look into separately. rdar://problem/59634380 Differential Revision: https://reviews.llvm.org/D75488
2020-04-01Revert "Preserve the owning module information from DWARF in the synthesized ↵Adrian Prantl
AST" This reverts commit 4354dfbdf5c8510a7ddff10ae67a28e16cf7cc79 while investigating bot fallout.
2020-04-01Preserve the owning module information from DWARF in the synthesized ASTAdrian Prantl
Types that came from a Clang module are nested in DW_TAG_module tags in DWARF. This patch recreates the Clang module hierarchy in LLDB and sets the owning module information accordingly. My primary motivation is to facilitate looking up per-module APINotes for individual declarations, but this likely also has other applications. rdar://problem/59634380 Differential Revision: https://reviews.llvm.org/D75488
2020-01-31[lldb] Move clang-based files out of SymbolAlex Langford
Summary: This change represents the move of ClangASTImporter, ClangASTMetadata, ClangExternalASTSourceCallbacks, ClangUtil, CxxModuleHandler, and TypeSystemClang from lldbSource to lldbPluginExpressionParserClang.h This explicitly removes knowledge of clang internals from lldbSymbol, moving towards a more generic core implementation of lldb. Reviewers: JDevlieghere, davide, aprantl, teemperor, clayborg, labath, jingham, shafik Subscribers: emaste, mgorny, arphaman, jfb, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73661