summaryrefslogtreecommitdiff
path: root/clang/lib/AST/DynamicRecursiveASTVisitor.cpp
AgeCommit message (Collapse)Author
2025-09-06[Clang] Convert ConstraintRefersToContainingTemplateChecker to using RAV ↵Younan Zhang
(#157062) We previously employed a TreeTransform to perform a task that should have been achieved by RAV. The TreeTransform approach was a bit wasteful, as we discarded the transform result and incurred some incorrect semantic analysis. Fixes https://github.com/llvm/llvm-project/issues/156225
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well: ![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831) This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
2025-01-30Revert "Silence MSVC warnings; NFC"Aaron Ballman
This reverts commit 44c0719e77b37374c89b7fc1320664ebb404323d. It broke several -Werror bots because of misuse of override.
2025-01-30Silence MSVC warnings; NFCAaron Ballman
After the changes to DynamicRecursiveASTVisitor, we started getting several warnings from MSVC like: warning C4661: 'bool clang::DynamicRecursiveASTVisitorBase<false>::WalkUpFromNamedDecl(clang::NamedDecl *)': no suitable definition provided for explicit template instantiation request These changes silence the warnings by providing a definition for those functions.
2025-01-29[Clang] [NFC] Introduce `ConstDynamicRecursiveASTVisitor` (reland) (#124821)Sirraide
This relands #122991 (eeefa72). The last attempt at landing this caused some problems; I’m not entirely sure what happened, but it might have been due to an unnecessary use of the `template` keyword in a few places. This removes that and attempts to land the change again.
2025-01-28Revert "[Clang] [NFC] Introduce `ConstDynamicRecursiveASTVisitor`" (#124667)Sirraide
Reverts llvm/llvm-project#122991 One of the bots is breaking; I’ll have to investigate what the issue is; this might be because I haven’t updated the branch in a while.
2025-01-28[Clang] [NFC] Introduce `ConstDynamicRecursiveASTVisitor` (#122991)Sirraide
After some discussion around #116823, it was decided that it would be nice to have a `const` variant of `DynamicRecursiveASTVisitor`, so this pr does exactly that by making the main DRAV implementation a template with a single `bool` template parameter that turns several function parameters from a `T*` or `T&` to a `const T*` or `const T&`. Since that made the implementation of a bunch of DRAV functions quite a bit more verbose, I’ve moved most of them to be stamped out by a macro, which imo makes it easier to understand what’s actually going on there. For functions which already accepted `const` parameters in the original RAV implementation, the parameter is `const` in both versions (e.g. `TraverseTemplateArgument()` always takes a `const TemplateArgument&`); conversely, parameters that are passed by value (e.g. in `TraverseType()`, which takes a `QualType` by value) are *not* `const` in either variant (i.e. the `QualType` argument is always just a `QualType`, never a `const QualType`). As a sanity check, I’ve also migrated some random visitor in the static analyser to the `const` version (and indeed, it ends up simplifying the code around that particular visitor actually). It would make sense to do a pass over all visitors and change all which can be `const` use the `const` version, but that can be done in a follow-up pr. The [performance impact](https://llvm-compile-time-tracker.com/compare.php?from=e3cd88a7be1dfd912bb6e7c7e888e7b442ffb5de&to=d55c5afe4a485b6d0431386e6f45cb44c1fc8883&stat=instructions:u) of this change seems to be negligible. Clang’s binary size went up by 0.5%, but that’s expected considering that this effectively adds an extra instantiation of `RecursiveASTVisitor`. Fortunately, this is of course a one-time cost.
2024-11-05[Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (#110040)Sirraide
See #105195 as well as the big comment in DynamicRecursiveASTVisitor.cpp for more context.