Commit 26b035d
committed
[clang] AST: fix getAs canonicalization of leaf types
Before this patch, the application of getAs and castAs on a leaf type
would always produce a canonical type, which is undesirable because
some of these types can be sugared.
The user expectation is that getAs only removes top level sugar nodes, leaving
all the type sugar on the returned node, but it had an optimization intended
for type nodes with no sugar: for these, we can skip the expensive traversal
of the top level sugar with a simple canonicalization followed by dyn_cast.
The problem is that the concept of leaf type does not map well to what is
correct to apply this optimization to.
This patch replaces the concept of leaf types with 'always canonical' types,
and only applies the canonicalization strategy on them.
In order to avoid the performance regression this would cause, as most current
users do not care about type sugar, this patch also replaces all of these uses
with alternative cast functions which operate through canonicalization.
* Introduces castAs variants to complement the getAsTagDecl and derived
variants.
* Introduces getAsEnumDecl and castAsEnumDecl, complementing the current set, so
that all TagDecls are covered.
* Introduces getAsCanonical and castAsCanonical, for faster casting when only
the canonical type is desired.
The getAsTagDecl and related functions are not provided inline, because
of the circular dependencies that would involve. So this patch causes a
small overall performance regression:
<img width="1461" height="18" alt="image" src="https://github.com/user-attachments/assets/061dfb14-9506-4623-91ec-0f02f585d1dd" />
This will be fixed in a later patch, bringing the whole thing back to a positive
performance improvement overall:
<img width="1462" height="18" alt="image" src="https://github.com/user-attachments/assets/c237e68f-f696-44f4-acc6-a7c7ba5b0976" />1 parent 8b0067d commit 26b035d
File tree
121 files changed
+599
-1015
lines changed- clang-tools-extra
- clang-tidy
- bugprone
- cppcoreguidelines
- misc
- modernize
- readability
- utils
- clangd
- refactor/tweaks
- clang/lib
- AST
- ByteCode
- CIR/CodeGen
- CodeGen
- Targets
- Frontend/Rewrite
- Index
- Interpreter
- Sema
- StaticAnalyzer
- Checkers
- WebKit
- Core
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
121 files changed
+599
-1015
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
997 | 997 | | |
998 | 998 | | |
999 | 999 | | |
1000 | | - | |
| 1000 | + | |
1001 | 1001 | | |
1002 | 1002 | | |
1003 | 1003 | | |
| |||
Lines changed: 2 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 172 | + | |
| 173 | + | |
181 | 174 | | |
182 | 175 | | |
183 | 176 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
417 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
418 | 419 | | |
419 | | - | |
| 420 | + | |
420 | 421 | | |
421 | 422 | | |
422 | 423 | | |
| |||
Lines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 69 | + | |
73 | 70 | | |
74 | 71 | | |
75 | 72 | | |
| |||
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
467 | 466 | | |
468 | 467 | | |
469 | 468 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
457 | | - | |
458 | | - | |
| 457 | + | |
459 | 458 | | |
460 | 459 | | |
461 | 460 | | |
| |||
832 | 831 | | |
833 | 832 | | |
834 | 833 | | |
835 | | - | |
| 834 | + | |
836 | 835 | | |
837 | 836 | | |
838 | 837 | | |
| |||
0 commit comments