Commit 91cdd35
authored
[clang] Improve nested name specifier AST representation (#147835)
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:

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 #43179
Fixes #68670
Fixes #927571 parent fc44a4f commit 91cdd35
File tree
539 files changed
+11195
-10586
lines changed- clang-tools-extra
- clang-change-namespace
- clang-doc
- clang-include-fixer/find-all-symbols
- clang-tidy
- bugprone
- cppcoreguidelines
- fuchsia
- google
- misc
- modernize
- performance
- portability
- readability
- utils
- clangd
- refactor/tweaks
- unittests
- include-cleaner/lib
- test/clang-tidy/checkers
- bugprone
- portability
- clang
- bindings/python/tests/cindex
- docs
- include/clang
- ASTMatchers
- AST
- Analysis/FlowSensitive
- Basic
- ExtractAPI
- Sema
- Serialization
- Tooling/Refactoring
- lib
- ASTMatchers
- Dynamic
- AST
- ByteCode
- Analysis
- FlowSensitive
- CodeGen
- Targets
- ExtractAPI
- Frontend
- Index
- InstallAPI
- Interpreter
- Parse
- Sema
- Serialization
- StaticAnalyzer
- Checkers
- WebKit
- Core
- Tooling
- ASTDiff
- Refactoring
- Rename
- Syntax
- Transformer
- test
- ASTSYCL
- AST
- HLSL
- Analysis
- CXX
- basic/basic.lookup/basic.lookup.qual/class.qual
- class.access
- class.derived/class.derived.general
- class/class.mem/class.mem.general
- dcl.dcl/dcl.spec/dcl.type/dcl.type.elab
- dcl.decl
- dcl.init/dcl.init.ref
- dcl.meaning/dcl.mptr
- dcl/dcl.fct
- drs
- expr/expr.prim/expr.prim.req
- over/over.match/over.match.funcs/over.match.class.deduct
- temp
- temp.arg/temp.arg.nontype
- temp.constr/temp.constr.decl
- temp.decls/temp.class.spec
- temp.fct.spec/temp.deduct/temp.deduct.call
- temp.param
- temp.res/temp.dep/temp.dep.type
- CodeGen
- Index
- Core
- skip-parsed-bodies
- Misc
- Modules
- OpenMP
- PCH
- Parser
- SemaCXX
- SemaObjCXX
- Inputs
- SemaOpenACC
- SemaTemplate
- tools/libclang
- unittests
- ASTMatchers
- AST
- Analysis/FlowSensitive
- CodeGen
- Index
- Sema
- StaticAnalyzer
- Tooling
- RecursiveASTVisitorTests
- libcxx/test
- libcxx/atomics/atomics.types.operations/atomics.types.operations.req
- std
- containers
- associative
- map/map.nonmember
- multimap/multimap.nonmember
- sequences/array/array.overview
- numerics/rand/rand.eng/rand.eng.lcong
- thread/futures/futures.task/futures.task.members
- utilities/utility/pairs/pairs.pair
- lldb
- source/Plugins
- ExpressionParser/Clang
- Language/ObjC
- RegisterTypeBuilder
- SymbolFile
- NativePDB
- PDB
- TypeSystem/Clang
- test
- API
- functionalities/data-formatter/data-formatter-stl/generic/string
- tools/lldb-dap/completions
- Shell/SymbolFile/DWARF/x86
- tools/lldb-rpc-gen
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
539 files changed
+11195
-10586
lines changedLines changed: 17 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 34 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 35 | + | |
| 36 | + | |
52 | 37 | | |
53 | 38 | | |
54 | 39 | | |
| |||
550 | 535 | | |
551 | 536 | | |
552 | 537 | | |
553 | | - | |
554 | | - | |
| 538 | + | |
| 539 | + | |
555 | 540 | | |
556 | 541 | | |
557 | 542 | | |
| |||
562 | 547 | | |
563 | 548 | | |
564 | 549 | | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
578 | 560 | | |
579 | 561 | | |
580 | 562 | | |
| |||
588 | 570 | | |
589 | 571 | | |
590 | 572 | | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
595 | 576 | | |
596 | 577 | | |
597 | 578 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
902 | 902 | | |
903 | 903 | | |
904 | 904 | | |
905 | | - | |
906 | | - | |
| 905 | + | |
| 906 | + | |
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
220 | | - | |
| 219 | + | |
221 | 220 | | |
222 | 221 | | |
223 | 222 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
| 537 | + | |
537 | 538 | | |
538 | 539 | | |
539 | 540 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | | - | |
| 59 | + | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
Lines changed: 8 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
580 | | - | |
| 580 | + | |
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
| |||
1040 | 1040 | | |
1041 | 1041 | | |
1042 | 1042 | | |
1043 | | - | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
1044 | 1046 | | |
1045 | 1047 | | |
1046 | 1048 | | |
| |||
1072 | 1074 | | |
1073 | 1075 | | |
1074 | 1076 | | |
1075 | | - | |
| 1077 | + | |
1076 | 1078 | | |
1077 | | - | |
| 1079 | + | |
1078 | 1080 | | |
1079 | 1081 | | |
1080 | 1082 | | |
| |||
1219 | 1221 | | |
1220 | 1222 | | |
1221 | 1223 | | |
1222 | | - | |
| 1224 | + | |
1223 | 1225 | | |
1224 | 1226 | | |
1225 | 1227 | | |
| |||
1270 | 1272 | | |
1271 | 1273 | | |
1272 | 1274 | | |
1273 | | - | |
| 1275 | + | |
1274 | 1276 | | |
1275 | 1277 | | |
1276 | 1278 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
| |||
119 | 118 | | |
120 | 119 | | |
121 | 120 | | |
122 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
| |||
Lines changed: 7 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 36 | + | |
| 37 | + | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
51 | 47 | | |
52 | 48 | | |
53 | 49 | | |
| |||
Lines changed: 8 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
45 | 42 | | |
46 | 43 | | |
47 | 44 | | |
48 | 45 | | |
49 | | - | |
50 | | - | |
51 | 46 | | |
52 | 47 | | |
53 | 48 | | |
54 | 49 | | |
55 | | - | |
| 50 | + | |
56 | 51 | | |
57 | 52 | | |
58 | 53 | | |
| |||
62 | 57 | | |
63 | 58 | | |
64 | 59 | | |
| 60 | + | |
| 61 | + | |
65 | 62 | | |
66 | | - | |
| 63 | + | |
67 | 64 | | |
68 | 65 | | |
69 | 66 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
| 77 | + | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
0 commit comments