Skip to content

Commit 7b74782

Browse files
committed
[PATCH 1/4] [clang] Improve nested name specifier AST representation
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 #147000
1 parent 8a7c973 commit 7b74782

File tree

91 files changed

+4918
-4657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4918
-4657
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ ABI Changes in This Version
8484
AST Dumping Potentially Breaking Changes
8585
----------------------------------------
8686

87+
- How nested name specifiers are dumped and printed changes, keeping track of clang AST changes.
8788
- Added support for dumping template arguments of structural value kinds.
8889

8990
Clang Frontend Potentially Breaking Changes
@@ -481,6 +482,7 @@ Improvements to Clang's diagnostics
481482
under the subgroup ``-Wunsafe-buffer-usage-in-libc-call``.
482483
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
483484
``-Wno-error=parentheses``.
485+
- Fix duplicate diagnostics for incomplete type in nested name specifier. (#GH147000)
484486
- Similarly, fold expressions over a comparison operator are now an error by default.
485487
- Clang now better preserves the sugared types of pointers to member.
486488
- Clang now better preserves the presence of the template keyword with dependent
@@ -662,7 +664,7 @@ Improvements to Clang's diagnostics
662664
#GH142457, #GH139913, #GH138850, #GH137867, #GH137860, #GH107840, #GH93308,
663665
#GH69470, #GH59391, #GH58172, #GH46215, #GH45915, #GH45891, #GH44490,
664666
#GH36703, #GH32903, #GH23312, #GH69874.
665-
667+
666668
- Clang no longer emits a spurious -Wdangling-gsl warning in C++23 when
667669
iterating over an element of a temporary container in a range-based
668670
for loop.(#GH109793, #GH145164)
@@ -950,8 +952,11 @@ Bug Fixes to AST Handling
950952
- Fixed a malformed printout of ``CXXParenListInitExpr`` in certain contexts.
951953
- Fixed a malformed printout of certain calling convention function attributes. (#GH143160)
952954
- Fixed dependency calculation for TypedefTypes (#GH89774)
955+
- Fix incorrect name qualifiers applied to alias CTAD. (#GH136624)
953956
- The ODR checker now correctly hashes the names of conversion operators. (#GH143152)
954957
- Fixed the right parenthesis source location of ``CXXTemporaryObjectExpr``. (#GH143711)
958+
- Fixed ElaboratedTypes appearing within NestedNameSpecifier, which was not a
959+
legal representation. This is fixed because ElaboratedTypes don't exist anymore. (#GH43179) (#GH68670) (#GH92757)
955960
- Fixed a crash when performing an ``IgnoreUnlessSpelledInSource`` traversal of ASTs containing ``catch(...)`` statements. (#GH146103)
956961

957962
Miscellaneous Bug Fixes
@@ -1103,6 +1108,8 @@ AST Matchers
11031108
------------
11041109

11051110
- Ensure ``isDerivedFrom`` matches the correct base in case more than one alias exists.
1111+
- Removed elaboratedType matchers, and related nested name specifier changes,
1112+
following the corresponding changes in the clang AST.
11061113
- Extend ``templateArgumentCountIs`` to support function and variable template
11071114
specialization.
11081115

clang/include/clang/AST/ASTConcept.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define LLVM_CLANG_AST_ASTCONCEPT_H
1616

1717
#include "clang/AST/DeclarationName.h"
18-
#include "clang/AST/NestedNameSpecifier.h"
18+
#include "clang/AST/NestedNameSpecifierBase.h"
1919
#include "clang/AST/TemplateBase.h"
2020
#include "clang/Basic/SourceLocation.h"
2121
#include "clang/Basic/UnsignedOrNone.h"
@@ -175,12 +175,7 @@ class ConceptReference {
175175

176176
SourceLocation getLocation() const { return getConceptNameLoc(); }
177177

178-
SourceLocation getBeginLoc() const LLVM_READONLY {
179-
// Note that if the qualifier is null the template KW must also be null.
180-
if (auto QualifierLoc = getNestedNameSpecifierLoc())
181-
return QualifierLoc.getBeginLoc();
182-
return getConceptNameInfo().getBeginLoc();
183-
}
178+
SourceLocation getBeginLoc() const LLVM_READONLY;
184179

185180
SourceLocation getEndLoc() const LLVM_READONLY {
186181
return getTemplateArgsAsWritten() &&

0 commit comments

Comments
 (0)