18 Commits

Author SHA1 Message Date
Kazu Hirata
136b541304
[clang] Replace SmallSet with SmallPtrSet (NFC) (#154262)
This patch replaces SmallSet<T *, N> with SmallPtrSet<T *, N>.  Note
that SmallSet.h "redirects" SmallSet to SmallPtrSet for pointer
element types:

  template <typename PointeeType, unsigned N>
class SmallSet<PointeeType*, N> : public SmallPtrSet<PointeeType*, N>
{};

We only have 30 instances that rely on this "redirection", with about
half of them under clang/.  Since the redirection doesn't improve
readability, this patch replaces SmallSet with SmallPtrSet for pointer
element types.

I'm planning to remove the redirection eventually.
2025-08-19 07:11:39 -07:00
Matheus Izvekov
91cdd35008
[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:

![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 https://github.com/llvm/llvm-project/issues/43179
Fixes https://github.com/llvm/llvm-project/issues/68670
Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-09 05:06:53 -03:00
Nathan Ridge
e64289baa0
[clang][Sema] Unify getPrototypeLoc helpers in SemaCodeComplete and clangd (#143345)
HeuristicResolver houses the unified implementation.

Fixes https://github.com/llvm/llvm-project/issues/143240
2025-07-05 10:59:16 -04:00
Nathan Ridge
fa0498fdae
[clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well (#132576)
This is a follow-up to https://github.com/llvm/llvm-project/pull/131074.

After moving the default argument heuristic to `simplifyType` in that
patch, the heuristic no longer applied to the 
`DependentScopeDeclRefExpr` case, because that wasn't using
`simplifyType`.

This patch fixes that, with an added testcase.
2025-04-11 02:35:04 -04:00
Nathan Ridge
715ad67c80
[clang][CodeComplete] Use HeuristicResolver in getAsRecordDecl() (#130473)
Fixes https://github.com/llvm/llvm-project/issues/130468
2025-04-11 02:02:30 -04:00
Matheus Izvekov
dc17429ae6
[clang] improved preservation of template keyword (#133610) 2025-04-01 17:15:18 -03:00
Nathan Ridge
44573bc152
[clang][HeuristicResolver] Default argument heuristic for template parameters (#132465)
Fixes https://github.com/clangd/clangd/discussions/1056
2025-03-21 19:15:18 -04:00
Nathan Ridge
7a4cb9bac5
[clang-tidy][NFC] Expose HeuristicResolver::lookupDependentName() and use it in StandaloneEmptyCheck (#128391)
The use replaces CXXRecordDecl::lookupDependentName() which
HeuristicResolver aims to supersede.
2025-02-24 11:31:46 -05:00
Nathan Ridge
c7eb5204a6
[clang][HeuristicResolver] Track the expression whose type is being simplified after each step in simplifyType() (#126689)
Fixes https://github.com/llvm/llvm-project/issues/126536
2025-02-11 17:25:15 -05:00
Nathan Ridge
d78b5ceb16
[clang][HeuristicResolver] Additional hardening against an infinite loop in simplifyType() (#126690) 2025-02-11 09:17:41 +01:00
Nathan Ridge
2941fa3941
[clang][HeuristicResolver] Only perform qualifier check for instance methods (#125166)
Fixes https://github.com/llvm/llvm-project/issues/125164
2025-01-31 00:25:53 -05:00
Nathan Ridge
7fd84264ed
[clang][Sema] Handle pointer and reference type more robustly in HeuristicResolver::resolveMemberExpr() (#124451)
Fixes https://github.com/llvm/llvm-project/issues/124450
2025-01-30 01:54:30 -05:00
Nathan Ridge
a4d17c44f1
[clang][Sema] Generalize HeuristicResolver::resolveTypeToRecordDecl() to resolveTypeToTagDecl() (#124699) 2025-01-28 13:37:30 -05:00
Nathan Ridge
194c74e016
[clang][Sema] Null-check type in resolveMemberExpr() before checking for auto type (#124628)
Fixes https://github.com/clangd/clangd/issues/2301
2025-01-27 19:51:30 -05:00
Nathan Ridge
a01e1d4e04
[clang][Sema] Handle dependent qualifier in HeuristicResolver::resolveDeclRefExpr() (#124515) 2025-01-27 03:31:56 -05:00
Nathan Ridge
df9b31f1e0
[clang][Sema] Handle undeduced auto types in HeuristicResolver (#124236)
Fixes https://github.com/clangd/clangd/issues/897
2025-01-24 16:11:18 -05:00
Nathan Ridge
4740e09703
[clang][Sema] Respect qualification of methods in heuristic results (#123551)
Fixes https://github.com/llvm/llvm-project/issues/123549
2025-01-21 03:54:42 -05:00
Nathan Ridge
ae932becb2
[clang][Sema] Upstream HeuristicResolver from clangd (#121314)
Fixes https://github.com/llvm/llvm-project/issues/121310
2025-01-17 17:01:00 -05:00