Skip to content

Commit 80f2f57

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 97f0ff0 commit 80f2f57

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
@@ -70,12 +70,16 @@ ABI Changes in This Version
7070

7171
AST Dumping Potentially Breaking Changes
7272
----------------------------------------
73+
- How nested name specifiers are dumped and printed changes, keeping track of clang AST changes.
7374

7475
Clang Frontend Potentially Breaking Changes
7576
-------------------------------------------
7677

7778
Clang Python Bindings Potentially Breaking Changes
7879
--------------------------------------------------
80+
- TypeKind ``ELABORATED`` is not used anymore, per clang AST changes removing
81+
ElaboratedTypes. The value becomes unused, and all the existing users should
82+
expect the former underlying type to be reported instead.
7983

8084
What's New in Clang |release|?
8185
==============================
@@ -111,13 +115,13 @@ Non-comprehensive list of changes in this release
111115
-------------------------------------------------
112116
- Added ``__builtin_elementwise_minnumnum`` and ``__builtin_elementwise_maxnumnum``.
113117

114-
- Trapping UBSan (e.g. ``-fsanitize-trap=undefined``) now emits a string describing the reason for
115-
trapping into the generated debug info. This feature allows debuggers (e.g. LLDB) to display
116-
the reason for trapping if the trap is reached. The string is currently encoded in the debug
117-
info as an artificial frame that claims to be inlined at the trap location. The function used
118-
for the artificial frame is an artificial function whose name encodes the reason for trapping.
119-
The encoding used is currently the same as ``__builtin_verbose_trap`` but might change in the future.
120-
This feature is enabled by default but can be disabled by compiling with
118+
- Trapping UBSan (e.g. ``-fsanitize-trap=undefined``) now emits a string describing the reason for
119+
trapping into the generated debug info. This feature allows debuggers (e.g. LLDB) to display
120+
the reason for trapping if the trap is reached. The string is currently encoded in the debug
121+
info as an artificial frame that claims to be inlined at the trap location. The function used
122+
for the artificial frame is an artificial function whose name encodes the reason for trapping.
123+
The encoding used is currently the same as ``__builtin_verbose_trap`` but might change in the future.
124+
This feature is enabled by default but can be disabled by compiling with
121125
``-fno-sanitize-annotate-debug-info-traps``.
122126

123127
New Compiler Flags
@@ -143,7 +147,7 @@ Improvements to Clang's diagnostics
143147
Moved the warning for a missing (though implied) attribute on a redeclaration into this group.
144148
Added a new warning in this group for the case where the attribute is missing/implicit on
145149
an override of a virtual method.
146-
- Fixed fix-it hint for fold expressions. Clang now correctly places the suggested right
150+
- Fixed fix-it hint for fold expressions. Clang now correctly places the suggested right
147151
parenthesis when diagnosing malformed fold expressions. (#GH151787)
148152

149153
Improvements to Clang's time-trace
@@ -187,6 +191,9 @@ Bug Fixes to C++ Support
187191

188192
Bug Fixes to AST Handling
189193
^^^^^^^^^^^^^^^^^^^^^^^^^
194+
- Fix incorrect name qualifiers applied to alias CTAD. (#GH136624)
195+
- Fixed ElaboratedTypes appearing within NestedNameSpecifier, which was not a
196+
legal representation. This is fixed because ElaboratedTypes don't exist anymore. (#GH43179) (#GH68670) (#GH92757)
190197

191198
Miscellaneous Bug Fixes
192199
^^^^^^^^^^^^^^^^^^^^^^^
@@ -256,6 +263,8 @@ Fixed Point Support in Clang
256263

257264
AST Matchers
258265
------------
266+
- Removed elaboratedType matchers, and related nested name specifier changes,
267+
following the corresponding changes in the clang AST.
259268
- Ensure ``hasBitWidth`` doesn't crash on bit widths that are dependent on template
260269
parameters.
261270

@@ -280,7 +289,7 @@ New features
280289

281290
Crash and bug fixes
282291
^^^^^^^^^^^^^^^^^^^
283-
- Fixed a crash in the static analyzer that when the expression in an
292+
- Fixed a crash in the static analyzer that when the expression in an
284293
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
285294

286295
Improvements

0 commit comments

Comments
 (0)