
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
95 lines
3.1 KiB
C++
95 lines
3.1 KiB
C++
// RUN: %check_clang_tidy -std=c++11-or-later %s portability-std-allocator-const %t -- -- -fno-delayed-template-parsing
|
|
|
|
namespace std {
|
|
typedef unsigned size_t;
|
|
|
|
template <class T>
|
|
class allocator {};
|
|
template <class T>
|
|
class hash {};
|
|
template <class T>
|
|
class equal_to {};
|
|
template <class T>
|
|
class less {};
|
|
|
|
template <class T, class A = std::allocator<T>>
|
|
class deque {};
|
|
template <class T, class A = std::allocator<T>>
|
|
class forward_list {};
|
|
template <class T, class A = std::allocator<T>>
|
|
class list {};
|
|
template <class T, class A = std::allocator<T>>
|
|
class vector {};
|
|
|
|
template <class K, class C = std::less<K>, class A = std::allocator<K>>
|
|
class multiset {};
|
|
template <class K, class C = std::less<K>, class A = std::allocator<K>>
|
|
class set {};
|
|
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
|
|
class unordered_multiset {};
|
|
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
|
|
class unordered_set {};
|
|
|
|
template <class T, class C = std::deque<T>>
|
|
class stack {};
|
|
} // namespace std
|
|
|
|
namespace absl {
|
|
template <class K, class H = std::hash<K>, class Eq = std::equal_to<K>, class A = std::allocator<K>>
|
|
class flat_hash_set {};
|
|
} // namespace absl
|
|
|
|
template <class T>
|
|
class allocator {};
|
|
|
|
void simple(const std::vector<const char> &v, std::deque<const short> *d) {
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:19: warning: container using std::allocator<const T> is a deprecated libc++ extension; remove const for compatibility with other standard libraries
|
|
// CHECK-MESSAGES: [[#@LINE-2]]:47: warning: container
|
|
std::list<const long> l;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container
|
|
|
|
std::multiset<int *const> ms;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container
|
|
std::set<const std::hash<int>> s;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container
|
|
std::unordered_multiset<int *const> ums;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container
|
|
std::unordered_set<const int> us;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container
|
|
|
|
absl::flat_hash_set<const int> fhs;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container
|
|
|
|
using my_vector = std::vector<const int>;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:21: warning: container
|
|
my_vector v1;
|
|
using my_vector2 = my_vector;
|
|
|
|
std::vector<int> neg1;
|
|
std::vector<const int *> neg2; // not const T
|
|
std::vector<const int, allocator<const int>> neg3; // not use std::allocator<const T>
|
|
std::allocator<const int> a; // not caught, but rare
|
|
std::forward_list<const int> forward; // not caught, but rare
|
|
std::stack<const int> stack; // not caught, but rare
|
|
}
|
|
|
|
template <class T>
|
|
void temp1() {
|
|
std::vector<const T> v;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container
|
|
|
|
std::vector<T> neg1;
|
|
std::forward_list<const T> neg2;
|
|
}
|
|
void use_temp1() { temp1<int>(); }
|
|
|
|
template <class T>
|
|
void temp2() {
|
|
// Match std::vector<const dependent> for the uninstantiated temp2.
|
|
std::vector<const T> v;
|
|
// CHECK-MESSAGES: [[#@LINE-1]]:3: warning: container
|
|
|
|
std::vector<T> neg1;
|
|
std::forward_list<const T> neg2;
|
|
}
|