311 Commits

Author SHA1 Message Date
Nikolas Klauser
8dd8e5f7d6
[Clang] Add BuiltinTemplates.td to generate code for builtin templates (#123736)
This makes it significantly easier to add new builtin templates, since
you only have to modify two places instead of a dozen or so.

The `BuiltinTemplates.td` could also be extended to generate
documentation from it in the future.
2025-02-26 16:01:14 +01:00
Alejandro Álvarez Ayllón
26a8399417
[clang][Sema] Fix initialization of NonTypeTemplateParmDecl... (#121768)
...when there are invalid constraints.

When attaching a `TypeConstraint`, in case of error, the trailing
pointer that is supposed to point to the constraint is left
uninitialized.
Sometimes the uninitialized value will be a `nullptr`, but at other
times it will not. If we traverse the AST (for instance, dumping it, or
when writing the BMI), we may get a crash depending on the value that
was left. The serialization may also contain a bogus value.

In this commit, we always initialize the `PlaceholderTypeConstraint`
with `nullptr`, to avoid accessing this uninitialized memory.

This does not affect only modules, but it causes a segfault more
consistently when they are involved.

The test case was reduced from `mp-units`.

---------

Co-authored-by: Erich Keane <ekeane@nvidia.com>
2025-02-19 07:19:31 -08:00
Matheus Izvekov
c94d930a21
[clang] NFC: rename MatchedPackOnParmToNonPackOnArg to StrictPackMatch (#125418)
This rename follows the proposed wording in P3310R5, which introduces
the term 'strict pack match' to refer to the same thing.
2025-02-05 13:16:33 -03:00
Matheus Izvekov
08bda1cc6b
Reland: [clang] fix P3310 overload resolution flag propagation (#125791)
Class templates might be only instantiated when they are required to be
complete, but checking the template args against the primary template is
immediate.

This result is cached so that later when the class is instantiated,
checking against the primary template is not repeated.

The 'MatchedPackOnParmToNonPackOnArg' flag is also produced upon
checking against the primary template, so it needs to be cached in the
specialziation as well.

This fixes a bug which has not been in any release, so there are no
release notes.

Fixes #125290
2025-02-05 12:02:24 -03:00
David Spickett
bae97e1976
Revert "[clang] fix P3310 overload resolution flag propagation" (#125710)
Reverts llvm/llvm-project#125372 due to lldb builds failing:
https://lab.llvm.org/buildbot/#/builders/59/builds/12223

We need to decide how to update LLDB's code.
2025-02-04 16:22:53 +00:00
Matheus Izvekov
f4958723b2
[clang] fix P3310 overload resolution flag propagation (#125372) 2025-02-04 12:17:49 -03:00
Kazu Hirata
986581f6bc
[AST] Migrate away from PointerUnion::dyn_cast (NFC) (#124674)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

This patch migrates uses of PointerUnion::dyn_cast to
dyn_cast_if_present (see the definition of PointerUnion::dyn_cast).
Note that we already have dyn_cast_if_present<T*>(ExplicitInfo)
elsewhere in ClassTemplateSpecializationDecl and
VarTemplateSpecializationDecl, meaning that ExplicitInfo is not
guaranteed to be nonnull in those classes.
2025-01-28 10:56:09 -08:00
Kazu Hirata
ab895ad2bf
[AST] Migrate away from PointerUnion::dyn_cast (NFC) (#124446)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Pattern to be nonnull.
2025-01-26 01:34:41 -08:00
Kazu Hirata
04d5608057
[AST] Migrate away from PointerUnion::dyn_cast (NFC) (#124430)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect P to be nonnull.
2025-01-25 14:05:11 -08:00
Kazu Hirata
563c7c5539
[clang] Migrate away from PointerUnion::dyn_cast (NFC) (#124425)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

This patch migrates uses of PointerUnion::dyn_cast to
dyn_cast_if_present (see the definition of PointerUnion::dyn_cast).
Note that we cannot use dyn_cast in any of the migrations in this
patch; placing

  assert(!X.isNull());

just before any of dyn_cast_if_present in this patch triggers some
failure in check-clang.
2025-01-25 14:05:01 -08:00
Kazu Hirata
c216081e98
[AST] Migrate away from PointerUnion::dyn_cast (NFC) (#124388)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect P to be nonnull.
2025-01-25 01:15:38 -08:00
Chuanqi Xu
20e9049509
[Serialization] Support loading template specializations lazily (#119333)
Reland https://github.com/llvm/llvm-project/pull/83237

---

(Original comments)

Currently all the specializations of a template (including
instantiation, specialization and partial specializations) will be
loaded at once if we want to instantiate another instance for the
template, or find instantiation for the template, or just want to
complete the redecl chain.

This means basically we need to load every specializations for the
template once the template declaration got loaded. This is bad since
when we load a specialization, we need to load all of its template
arguments. Then we have to deserialize a lot of unnecessary
declarations.

For example,

```
// M.cppm
export module M;
export template <class T>
class A {};

export class ShouldNotBeLoaded {};

export class Temp {
   A<ShouldNotBeLoaded> AS;
};

// use.cpp
import M;
A<int> a;
```

We have a specialization ` A<ShouldNotBeLoaded>` in `M.cppm` and we
instantiate the template `A` in `use.cpp`. Then we will deserialize
`ShouldNotBeLoaded` surprisingly when compiling `use.cpp`. And this
patch tries to avoid that.

Given that the templates are heavily used in C++, this is a pain point
for the performance.

This patch adds MultiOnDiskHashTable for specializations in the
ASTReader. Then we will only deserialize the specializations with the
same template arguments. We made that by using ODRHash for the template
arguments as the key of the hash table.

To review this patch, I think `ASTReaderDecl::AddLazySpecializations`
may be a good entry point.
2024-12-11 09:40:47 +08:00
Haowei Wu
12bdeba76e Revert "[Serialization] Support load lazy specialization lazily"
This reverts commit b5bd19211118c6d43bc525a4e3fb65d2c750d61e.
It brokes multiple llvm bots including clang-x64-windows-msvc
2024-12-06 10:33:57 -08:00
Chuanqi Xu
b5bd192111 [Serialization] Support load lazy specialization lazily
Currently all the specializations of a template (including
instantiation, specialization and partial specializations)  will be
loaded at once if we want to instantiate another instance for the
template, or find instantiation for the template, or just want to
complete the redecl chain.

This means basically we need to load every specializations for the
template once the template declaration got loaded. This is bad since
when we load a specialization, we need to load all of its template
arguments. Then we have to deserialize a lot of unnecessary
declarations.

For example,

```
// M.cppm
export module M;
export template <class T>
class A {};

export class ShouldNotBeLoaded {};

export class Temp {
   A<ShouldNotBeLoaded> AS;
};

// use.cpp
import M;
A<int> a;
```

We should a specialization ` A<ShouldNotBeLoaded>` in `M.cppm` and we
instantiate the template `A` in `use.cpp`. Then we will deserialize
`ShouldNotBeLoaded` surprisingly when compiling `use.cpp`. And this
patch tries to avoid that.

Given that the templates are heavily used in C++, this is a pain point
for the performance.

This patch adds MultiOnDiskHashTable for specializations in the
ASTReader. Then we will only deserialize the specializations with the
same template arguments. We made that by using ODRHash for the template
arguments as the key of the hash table.

To review this patch, I think `ASTReaderDecl::AddLazySpecializations`
may be a good entry point.

The patch was reviewed in
https://github.com/llvm/llvm-project/pull/83237 but that PR is a stacked
PR. But I feel the intention of the stacked PRs get lost during the
review process. So I feel it is better to merge the commits into a
single commit instead of merging them in the PR page. It is better for
us to cherry-pick and revert.
2024-12-06 10:52:35 +08:00
Kazu Hirata
63d9ef5e37
[AST] Migrate away from PointerUnion::{is,get} (NFC) (#117469)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
2024-11-24 07:28:20 -08:00
Kazu Hirata
dec6324cb0
[AST] Remove unused includes (NFC) (#116549)
Identified with misc-include-cleaner.
2024-11-17 09:36:48 -08:00
Krystian Stasiowski
44ab3805b5
Revert "Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585, #111173)" (#111852)" (#115159)
This reverts commit 2bb3d3a3f32ffaef3d9b6a27db7f1941f0cb1136.
2024-11-06 09:25:29 -05:00
Krystian Stasiowski
79f4d8f014
Revert "Reapply "[Clang][Sema] Always use latest redeclaration of primary template" (#114569)" (#115156)
This reverts commit b24650e814e55d90acfc40acf045456c98f32b9c.
2024-11-06 08:38:59 -05:00
Krystian Stasiowski
b24650e814
Reapply "[Clang][Sema] Always use latest redeclaration of primary template" (#114569)
This patch reapplies #114258, fixing an infinite recursion bug in
`ASTImporter` that occurs when importing the primary template of a class
template specialization when the latest redeclaration of that template
is a friend declaration in the primary template.
2024-11-01 16:15:33 -04:00
Felipe de Azevedo Piovezan
4afa978756
Revert "[Clang][Sema] Always use latest redeclaration of primary template" (#114304)
Clang importer doesn't seem to work well with this change, see
discussion in the original PR.

Reverts llvm/llvm-project#114258
2024-10-30 14:04:26 -07:00
Krystian Stasiowski
90786adade
[Clang][Sema] Always use latest redeclaration of primary template (#114258)
This patch fixes a couple of regressions introduced in #111852.

Consider:

```
template<typename T>
struct A
{
    template<bool U>
    static constexpr bool f() requires U
    {
        return true;
    }
};

template<>
template<bool U>
constexpr bool A<short>::f() requires U
{
    return A<long>::f<U>();
}

template<>
template<bool U>
constexpr bool A<long>::f() requires U
{
    return true;
}

static_assert(A<short>::f<true>()); // crash here
```

This crashes because when collecting template arguments from the _first_
declaration of `A<long>::f<true>` for constraint checking, we don't add
the template arguments from the enclosing class template specialization
because there exists another redeclaration that is a member
specialization.

This also fixes the following example, which happens for a similar
reason:
```
// input.cppm

export module input;

export template<int N>
constexpr int f();

template<int N>
struct A {
  template<int J>
  friend constexpr int f();
};

template struct A<0>;

template<int N>
constexpr int f() {
  return N;
}
```

```
// input.cpp

import input;

static_assert(f<1>() == 1); // error: static assertion failed
```
2024-10-30 14:50:40 -04:00
Krystian Stasiowski
639a7ac648
[Clang][AST] Store injected template arguments in TemplateParameterList (#113579)
Currently, we store injected template arguments in
`RedeclarableTemplateDecl::CommonBase`. This approach has a couple
problems:
1. We can only access the injected template arguments of
`RedeclarableTemplateDecl` derived types, but other `Decl` kinds still
make use of the injected arguments (e.g.
`ClassTemplatePartialSpecializationDecl`,
`VarTemplatePartialSpecializationDecl`, and `TemplateTemplateParmDecl`).
2. Accessing the injected template arguments requires the common data
structure to be allocated. This may occur before we determine whether a
previous declaration exists (e.g. when comparing constraints), so if the
template _is_ a redeclaration, we end up discarding the common data
structure.

This patch moves the storage and access of injected template arguments
from `RedeclarableTemplateDecl` to `TemplateParameterList`.
2024-10-29 13:36:55 -04:00
Jay Foad
4dd55c567a
[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)
Follow up to #109133.
2024-10-24 10:23:40 +01:00
Krystian Stasiowski
9381c6fd04
[Clang][Sema] Use the correct injected template arguments for partial specializations when collecting multi-level template argument lists (#112381)
After #111852 refactored multi-level template argument list collection,
the following results in a crash:
```
template<typename T, bool B>
struct A;

template<bool B>
struct A<int, B>
{
    void f() requires B;
};

template<bool B>
void A<int, B>::f() requires B { } // crash here
```

This happens because when collecting template arguments for constraint
normalization from a partial specialization, we incorrectly use the
template argument list of the partial specialization. We should be using
the template argument list of the _template-head_ (as defined in
[temp.arg.general] p2). Fixes #112222.
2024-10-16 10:40:03 -04:00
Krystian Stasiowski
2bb3d3a3f3
Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585, #111173)" (#111852)
This patch reapplies #111173, fixing a bug when instantiating dependent
expressions that name a member template that is later explicitly
specialized for a class specialization that is implicitly instantiated.

The bug is addressed by adding the `hasMemberSpecialization` function,
which return `true` if _any_ redeclaration is a member specialization.
This is then used when determining the instantiation pattern for a
specialization of a template, and when collecting template arguments for
a specialization of a template.
2024-10-11 14:08:06 -04:00
Krystian Stasiowski
1dff3309fd
Revert "Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (#111173)" (#111766)
This reverts commit 4da8ac34f76e707ab94380b94f616457cfd2cb83.
2024-10-09 17:49:32 -04:00
Krystian Stasiowski
4da8ac34f7
Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (#111173)
Reapplies #106585, fixing an issue where non-dependent names of member
templates appearing prior to that member template being explicitly
specialized for an implicitly instantiated class template specialization
would incorrectly use the definition of the explicitly specialized
member template.
2024-10-08 10:14:09 -04:00
Nikolas Klauser
f5be5cdaad
[Clang] Add __builtin_common_type (#99473)
This implements the logic of the `common_type` base template as a
builtin alias. If there should be no `type` member, an empty class is
returned. Otherwise a specialization of a `type_identity`-like class is
returned. The base template (i.e. `std::common_type`) as well as the
empty class and `type_identity`-like struct are given as arguments to
the builtin.
2024-09-22 09:25:52 +02:00
Martin Storsjö
1818ca5c4a Revert "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)"
This reverts commit cdd71d61664b63ae57bdba9ee0d891f78ef79c07 (and
30adb43c897a45c18d7dd163fb4ff40c915fc488).

This change broke compiling Qt, see
https://github.com/llvm/llvm-project/pull/106585#issuecomment-2365309463
for details.
2024-09-21 23:24:49 +03:00
Kazu Hirata
30adb43c89 [AST] Fix a warning
This patch fixes:

  clang/lib/AST/DeclTemplate.cpp:466:9: error: unused type alias 'Base'
  [-Werror,-Wunused-local-typedef]
2024-09-20 13:05:04 -07:00
Krystian Stasiowski
cdd71d6166
[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)
Currently, clang rejects the following explicit specialization of `f`
due to the constraints not being equivalent:
```
template<typename T>
struct A
{
    template<bool B>
    void f() requires B;
};

template<>
template<bool B>
void A<int>::f() requires B { }
```
This happens because, in most cases, we do not set the flag indicating
whether a `RedeclarableTemplate` is an explicit specialization of a
member of an implicitly instantiated class template specialization until
_after_ we compare constraints for equivalence. This patch addresses the
issue (and a number of other issues) by:
- storing the flag indicating whether a declaration is a member
specialization on a per declaration basis, and
- significantly refactoring `Sema::getTemplateInstantiationArgs` so we
collect the right set of template argument in all cases.

Many of our declaration matching & constraint evaluation woes can be
traced back to bugs in `Sema::getTemplateInstantiationArgs`. This
change/refactor should fix a lot of them. It also paves the way for
fixing #101330 and #105462 per my suggestion in #102267 (which I have
implemented on top of this patch but will merge in a subsequent PR).
2024-09-20 14:57:40 -04:00
Ilya Biryukov
1c9085e37e
[Sema] Default arguments for template parameters affect ContainsUnexpandedPacks (#99880)
This addresses the FIXME in the code. There will be tests for the new
behavior in an upcoming #86265, which also addresses other bugs that
prevent exposing the wrong results of `ContainsUnexpandedPacks` in the
outputs of the compiler without crashes.
2024-07-23 19:19:16 +02:00
Chuanqi Xu
8af86025af [NFC] [Serialization] Unify how LocalDeclID can be created
Now we can create a LocalDeclID directly with an integer without
verifying. It may be hard to refactor if we want to change the way we
serialize DeclIDs (See https://github.com/llvm/llvm-project/pull/95897).
Also it is hard for us to debug if someday someone construct a
LocalDeclID with an incorrect value.

So in this patch, I tried to unify the way we can construct a
LocalDeclID in ASTReader, where we will construct the LocalDeclID from
the serialized data. Also, now we can verify the constructed LocalDeclID
sooner in the new interface.
2024-06-19 15:18:01 +08:00
Matheus Izvekov
9c4a716c12
[clang] Preserve Qualifiers and type sugar in TemplateNames (#93433)
This patch improves the preservation of qualifiers and loss of type
sugar in TemplateNames.

This problem is analogous to https://reviews.llvm.org/D112374 and this
patch takes a very similar approach to that patch, except the impact
here is much lesser.

When a TemplateName was written bare, without qualifications, we
wouldn't produce a QualifiedTemplate which could be used to disambiguate
it from a Canonical TemplateName. This had effects in the TemplateName
printer, which had workarounds to deal with this, and wouldn't print the
TemplateName as-written in most situations.

There are also some related fixes to help preserve this type sugar along
the way into diagnostics, so that this patch can be properly tested.

- Fix dropping the template keyword.
- Fix type deduction to preserve sugar in TST TemplateNames.
2024-05-29 17:02:15 -03:00
Matheus Izvekov
2bde13cda1
[clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (#92852)
This is an enabler for https://github.com/llvm/llvm-project/pull/92855

This allows an NTTP default argument to be set as an arbitrary
TemplateArgument, not just an expression.
This allows template parameter packs to have default arguments in the
AST, even though the language proper doesn't support the syntax for it.

This allows NTTP default arguments to be other kinds of arguments, like
packs, integral constants, and such.
2024-05-22 12:18:44 -03:00
Matheus Izvekov
e42b799bb2
[clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (#92854)
This is an enabler for a future patch.

This allows an type-parameter default argument to be set as an arbitrary
TemplateArgument, not just a type.
This allows template parameter packs to have default arguments in the
AST, even though the language proper doesn't support the syntax for it.

This will be used in a later patch which synthesizes template parameter
lists with arbitrary default arguments taken from template
specializations.

There are a few places we used SubsType, because we only had a type, now
we use SubstTemplateArgument.
SubstTemplateArgument was missing arguments for setting Instantiation
location and entity names.
Adding those is needed so we don't regress in diagnostics.
2024-05-21 20:27:50 -03:00
Vlad Serebrennikov
6677aef285
[clang][NFC] Remove const-qualification from FunctionTemplateSpecializationInfo::TemplateArguments (#92500)
This patch remove const-qualification from pointee type of
`FunctionTemplateSpecializationInfo::TemplateArguments`, because it's
(eventually) used to initialize `MultiLevelTemplateArgumentList`, which
can actually mutate the arguments via

f42f57b52d/clang/include/clang/Sema/Template.h (L197-L204)
Mutation seems to be required to correctly handle packs:

9144553207/clang/lib/Sema/SemaTemplateInstantiate.cpp (L1440-L1469)
2024-05-17 17:49:50 +04:00
Krystian Stasiowski
1202837302
Reapply "[Clang] Unify interface for accessing template arguments as written for class/variable template specializations (#81642)" (#91393)
Reapplies #81642, fixing the crash which occurs when running the lldb test suite.
2024-05-14 16:09:57 -04:00
Adrian Prantl
c6855ab24e Revert "[Clang] Unify interface for accessing template arguments as written for class/variable template specializations (#81642)"
This reverts commit 7115ed0fff027b65fa76fdfae215ed1382ed1473.

This commit broke several LLDB tests.

https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/3480/
2024-05-07 13:03:14 -07:00
Krystian Stasiowski
7115ed0fff
[Clang] Unify interface for accessing template arguments as written for class/variable template specializations (#81642)
Our current method of storing the template arguments as written for
`(Class/Var)Template(Partial)SpecializationDecl` suffers from a number
of flaws:
- We use `TypeSourceInfo` to store `TemplateArgumentLocs` for class
template/variable template partial/explicit specializations. For
variable template specializations, this is a rather unintuitive hack (as
we store a non-type specialization as a type). Moreover, we don't ever
*need* the type as written -- in almost all cases, we only want the
template arguments (e.g. in tooling use-cases).
- The template arguments as written are stored in a number of redundant
data members. For example, `(Class/Var)TemplatePartialSpecialization`
have their own `ArgsAsWritten` member that stores an
`ASTTemplateArgumentListInfo` (the template arguments).
`VarTemplateSpecializationDecl` has yet _another_ redundant member
"`TemplateArgsInfo`" that also stores an `ASTTemplateArgumentListInfo`.

This patch eliminates all
`(Class/Var)Template(Partial)SpecializationDecl` members which store the
template arguments as written, and turns the `ExplicitInfo` member into
a `llvm::PointerUnion<const ASTTemplateArgumentListInfo*,
ExplicitInstantiationInfo*>` (to avoid unnecessary allocations when the
declaration isn't an explicit instantiation). The template arguments as
written are now accessed via `getTemplateArgsWritten` in all cases.

The "most breaking" change is to AST Matchers, insofar that `hasTypeLoc`
will no longer match class template specializations (since they no
longer store the type as written).
2024-05-07 14:45:52 -04:00
Chuanqi Xu
d86cc73bbf [NFC] [Serialization] Avoid using DeclID directly as much as possible
This patch tries to remove all the direct use of DeclID except the real
low level reading and writing. All the use of DeclID is converted to
the use of LocalDeclID or GlobalDeclID. This is helpful to increase the
readability and type safety.
2024-04-25 14:59:09 +08:00
Chuanqi Xu
72b58146b1 Revert "[NFC] [Serialization] Avoid using DeclID directly as much as possible"
This reverts commit 42070a5c092ed420bf92ebf38229c594885e94c7.

I forgot to touch lldb.
2024-04-25 14:26:07 +08:00
Chuanqi Xu
42070a5c09 [NFC] [Serialization] Avoid using DeclID directly as much as possible
This patch tries to remove all the direct use of DeclID except the real
low level reading and writing. All the use of DeclID is converted to
the use of LocalDeclID or GlobalDeclID. This is helpful to increase the
readability and type safety.
2024-04-25 14:14:05 +08:00
Chuanqi Xu
c2a98fdeb3
[NFC] Move DeclID from serialization/ASTBitCodes.h to AST/DeclID.h (#89873)
Previously, the DeclID is defined in serialization/ASTBitCodes.h under
clang::serialization namespace. However, actually the DeclID is not
purely used in serialization part. The DeclID is already widely used in
AST and all around the clang project via classes like `LazyPtrDecl` or
calling `ExternalASTSource::getExernalDecl()`. All such uses are via the
raw underlying type of `DeclID` as `uint32_t`. This is not pretty good.

This patch moves the DeclID class family to a new header `AST/DeclID.h`
so that the whole project can use the wrapped class `DeclID`,
`GlobalDeclID` and `LocalDeclID` instead of the raw underlying type.
This can improve the readability and the type safety.
2024-04-25 13:53:22 +08:00
Chuanqi Xu
07b1177eed [NFC] [Serialization] Use semantical type DeclID instead of raw type 'uint32_t'
This patch tries to use DeclID in the code bases to avoid use the raw
type 'uint32_t'. It is problematic to use the raw type 'uint32_t' if we
want to change the type of DeclID some day.
2024-04-23 12:44:00 +08:00
Chuanqi Xu
aac695da42 [NFC] [Serialization] Use semantical type 'DeclID' for 'CreateDeserialized'
Previously we use 'unsigned' as the type of ID in 'CreateDeserialized'.

And the type of `DeclID` in serialization is 'uint32_t', so there is
minor inconsistency.

Also more importantly, if we want to extend the type of DeclID from
uint32_t to uint64_t, we may be in trouble due to we forgot updating the
a lot of 'CreateDeserialized'.

So this patch tries to use semantical type 'DeclID' for
'*Decl::CreateDeserialized' to make sure it is tightly consistent.
2024-04-19 16:24:47 +08:00
Krystian Stasiowski
4e6d18f406
[Clang][AST] Track whether template template parameters used the 'typename' keyword (#88139)
This patch adds a `Typename` bit-field to `TemplateTemplateParmDecl`
which stores whether the template template parameter was declared with
the `typename` keyword.
2024-04-11 13:20:05 -04:00
Bill Wendling
fca51911d4
[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)
The IdentifierInfo isn't typically modified. Use 'const' wherever
possible.
2024-04-11 00:33:40 +00:00
Krystian Stasiowski
4739a97fae
[Clang][NFC] Remove TemplateArgumentList::OnStack (#79760)
This patch removes on-stack `TemplateArgumentList`'s. They were primary used
to pass an `ArrayRef<TemplateArgument>` to
`Sema::getTemplateInstantiationArgs`, which had a `const
TemplateArgumentList*` parameter for the innermost template argument
list. Changing this parameter to an
`std::optional<ArrayRef<TemplateArgument>>` eliminates the need for
on-stack `TemplateArgumentList`'s, which in turn eliminates the need for
`TemplateArgumentList` to store a pointer to its template argument
storage (which is redundant in almost all cases, as it is an AST
allocated type).
2024-02-01 11:50:50 -05:00
Younan Zhang
ab70ac605e
[concepts] Push a CurContext before substituting into out-of-line constraints for comparison (#79985) 2024-01-31 12:17:41 +08:00