Skip to content

Commit 9a9b252

Browse files
committed
[PATCH 1/7] [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 0206c0f commit 9a9b252

Some content is hidden

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

61 files changed

+2467
-2306
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ ABI Changes in This Version
5050

5151
AST Dumping Potentially Breaking Changes
5252
----------------------------------------
53+
- How nested name specifiers are dumped and printed changes, keeping track of clang AST changes.
5354

5455
Clang Frontend Potentially Breaking Changes
5556
-------------------------------------------
5657

5758
Clang Python Bindings Potentially Breaking Changes
5859
--------------------------------------------------
60+
- TypeKind ``ELABORATED`` is not used anymore, per clang AST changes removing
61+
ElaboratedTypes. The value becomes unused, and all the existing users should
62+
expect the former underlying type to be reported instead.
5963

6064
What's New in Clang |release|?
6165
==============================
@@ -91,13 +95,13 @@ Non-comprehensive list of changes in this release
9195
-------------------------------------------------
9296
- Added ``__builtin_elementwise_minnumnum`` and ``__builtin_elementwise_maxnumnum``.
9397

94-
- Trapping UBSan (e.g. ``-fsanitize-trap=undefined``) now emits a string describing the reason for
95-
trapping into the generated debug info. This feature allows debuggers (e.g. LLDB) to display
96-
the reason for trapping if the trap is reached. The string is currently encoded in the debug
97-
info as an artificial frame that claims to be inlined at the trap location. The function used
98-
for the artificial frame is an artificial function whose name encodes the reason for trapping.
99-
The encoding used is currently the same as ``__builtin_verbose_trap`` but might change in the future.
100-
This feature is enabled by default but can be disabled by compiling with
98+
- Trapping UBSan (e.g. ``-fsanitize-trap=undefined``) now emits a string describing the reason for
99+
trapping into the generated debug info. This feature allows debuggers (e.g. LLDB) to display
100+
the reason for trapping if the trap is reached. The string is currently encoded in the debug
101+
info as an artificial frame that claims to be inlined at the trap location. The function used
102+
for the artificial frame is an artificial function whose name encodes the reason for trapping.
103+
The encoding used is currently the same as ``__builtin_verbose_trap`` but might change in the future.
104+
This feature is enabled by default but can be disabled by compiling with
101105
``-fno-sanitize-annotate-debug-info-traps``.
102106

103107
New Compiler Flags
@@ -123,7 +127,7 @@ Improvements to Clang's diagnostics
123127
Moved the warning for a missing (though implied) attribute on a redeclaration into this group.
124128
Added a new warning in this group for the case where the attribute is missing/implicit on
125129
an override of a virtual method.
126-
- Fixed fix-it hint for fold expressions. Clang now correctly places the suggested right
130+
- Fixed fix-it hint for fold expressions. Clang now correctly places the suggested right
127131
parenthesis when diagnosing malformed fold expressions. (#GH151787)
128132

129133
Improvements to Clang's time-trace
@@ -163,6 +167,9 @@ Bug Fixes to C++ Support
163167

164168
Bug Fixes to AST Handling
165169
^^^^^^^^^^^^^^^^^^^^^^^^^
170+
- Fix incorrect name qualifiers applied to alias CTAD. (#GH136624)
171+
- Fixed ElaboratedTypes appearing within NestedNameSpecifier, which was not a
172+
legal representation. This is fixed because ElaboratedTypes don't exist anymore. (#GH43179) (#GH68670) (#GH92757)
166173

167174
Miscellaneous Bug Fixes
168175
^^^^^^^^^^^^^^^^^^^^^^^
@@ -232,6 +239,8 @@ Fixed Point Support in Clang
232239

233240
AST Matchers
234241
------------
242+
- Removed elaboratedType matchers, and related nested name specifier changes,
243+
following the corresponding changes in the clang AST.
235244
- Ensure ``hasBitWidth`` doesn't crash on bit widths that are dependent on template
236245
parameters.
237246

@@ -256,7 +265,7 @@ New features
256265

257266
Crash and bug fixes
258267
^^^^^^^^^^^^^^^^^^^
259-
- Fixed a crash in the static analyzer that when the expression in an
268+
- Fixed a crash in the static analyzer that when the expression in an
260269
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
261270

262271
Improvements

0 commit comments

Comments
 (0)