
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 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
193 lines
3.4 KiB
C++
193 lines
3.4 KiB
C++
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++20 %s
|
|
|
|
namespace GH39811 {
|
|
|
|
template<int = 0> class C {};
|
|
|
|
C (a);
|
|
C (b) = C();
|
|
C (c) {};
|
|
C (((((d)))));
|
|
|
|
template<C (e)> class X;
|
|
template<C (...f)> class Y;
|
|
|
|
void test() {
|
|
C (g);
|
|
C (h) = C();
|
|
C (i) {};
|
|
(void)g;
|
|
(void)h;
|
|
(void)i;
|
|
}
|
|
|
|
C* (bad1); // expected-error {{cannot form pointer to deduced class template specialization type}}
|
|
C (*bad2); // expected-error {{cannot form pointer to deduced class template specialization type}}
|
|
|
|
}
|
|
|
|
namespace GH64347 {
|
|
|
|
template<typename X, typename Y> struct A { X x; Y y;};
|
|
void test() {
|
|
A(1, 2);
|
|
new A(1, 2);
|
|
}
|
|
|
|
template<A a>
|
|
void f() { (void)a; }
|
|
void k() {
|
|
// Test CTAD works for non-type template arguments.
|
|
f<A(0, 0)>();
|
|
}
|
|
|
|
} // namespace GH64347
|
|
|
|
namespace GH123591 {
|
|
|
|
|
|
template < typename... _Types >
|
|
struct variant {
|
|
template <int N = sizeof...(_Types)>
|
|
variant(_Types...);
|
|
};
|
|
|
|
template <class T>
|
|
using AstNode = variant<T, T, T>;
|
|
|
|
AstNode tree(42, 43, 44);
|
|
|
|
}
|
|
|
|
namespace GH123591_2 {
|
|
|
|
template <int>
|
|
using enable_if_t = char;
|
|
|
|
template < typename... Types >
|
|
struct variant {
|
|
template < enable_if_t<sizeof...(Types)>>
|
|
variant();
|
|
};
|
|
|
|
template <int>
|
|
using AstNode = variant<>;
|
|
// expected-note@-1 {{couldn't infer template argument ''}} \
|
|
// expected-note@-1 2{{implicit deduction guide declared as}} \
|
|
// expected-note@-1 {{candidate function template not viable}}
|
|
|
|
|
|
AstNode tree; // expected-error {{no viable constructor or deduction guide}}
|
|
|
|
}
|
|
|
|
namespace GH127539 {
|
|
|
|
template <class...>
|
|
struct A {
|
|
template <class... ArgTs>
|
|
A(ArgTs...) {}
|
|
};
|
|
|
|
template <class... ArgTs>
|
|
A(ArgTs...) -> A<typename ArgTs::value_type...>;
|
|
|
|
template <class... Ts>
|
|
using AA = A<Ts..., Ts...>;
|
|
|
|
AA a{};
|
|
|
|
}
|
|
|
|
namespace GH129077 {
|
|
|
|
using size_t = decltype(sizeof(0));
|
|
|
|
struct index_type
|
|
{
|
|
size_t value = 0;
|
|
index_type() = default;
|
|
constexpr index_type(size_t i) noexcept : value(i) {}
|
|
};
|
|
|
|
template <index_type... Extents>
|
|
struct extents
|
|
{
|
|
constexpr extents(decltype(Extents)...) noexcept {}
|
|
};
|
|
|
|
template <class... Extents>
|
|
extents(Extents...) -> extents<(requires { Extents::value; } ? Extents{} : ~0ull)...>;
|
|
|
|
template <index_type... Index>
|
|
using index = extents<Index...>;
|
|
|
|
int main()
|
|
{
|
|
extents i{0,0};
|
|
auto j = extents<64,{}>({}, 42);
|
|
|
|
index k{0,0};
|
|
auto l = index<64,{}>({}, 42);
|
|
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
namespace GH129620 {
|
|
|
|
template <class... Ts>
|
|
struct A {
|
|
constexpr A(Ts...) {}
|
|
};
|
|
|
|
template <class... Ts>
|
|
using Foo = A<Ts...>;
|
|
|
|
template <class T>
|
|
using Bar = Foo<T, T>;
|
|
|
|
Bar a{0, 0};
|
|
|
|
}
|
|
|
|
namespace GH129998 {
|
|
|
|
struct converible_to_one {
|
|
constexpr operator int() const noexcept { return 1; }
|
|
};
|
|
|
|
template <int... Extents>
|
|
struct class_template {
|
|
class_template() = default;
|
|
constexpr class_template(auto&&...) noexcept {}
|
|
};
|
|
|
|
template <class... Extents>
|
|
class_template(Extents...) -> class_template<(true ? 0 : +Extents{})...>;
|
|
|
|
template <int... Extents>
|
|
using alias_template = class_template<Extents...>;
|
|
|
|
alias_template var2{converible_to_one{}, 2};
|
|
|
|
}
|
|
|
|
namespace GH136624 {
|
|
// expected-note@+1 2{{no known conversion}}
|
|
template<typename U> struct A {
|
|
U t;
|
|
};
|
|
|
|
template<typename V> A(V) -> A<V>;
|
|
|
|
namespace foo {
|
|
template<class Y> using Alias = A<Y>;
|
|
}
|
|
|
|
// FIXME: This diagnostic is missing 'foo::Alias', as written.
|
|
foo::Alias t = 0;
|
|
// expected-error@-1 {{no viable conversion from 'int' to 'GH136624::A<int>' (aka 'A<int>')}}
|
|
} // namespace GH136624
|