[clang] 8e97ebb - [NFC][clang] Move LazyVector to Sema (#219188)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 28 00:13:02 PDT 2026
Author: Jonas Hahnfeld
Date: 2026-08-28T09:12:58+02:00
New Revision: 8e97ebbe3c02888748dd457a2e876f40f2f2b7e2
URL: https://github.com/llvm/llvm-project/commit/8e97ebbe3c02888748dd457a2e876f40f2f2b7e2
DIFF: https://github.com/llvm/llvm-project/commit/8e97ebbe3c02888748dd457a2e876f40f2f2b7e2.diff
LOG: [NFC][clang] Move LazyVector to Sema (#219188)
It is only used there.
Added:
Modified:
clang/include/clang/AST/ExternalASTSource.h
clang/include/clang/Sema/ExternalSemaSource.h
clang/include/clang/Sema/Sema.h
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ExternalASTSource.h b/clang/include/clang/AST/ExternalASTSource.h
index b277ce5812cdc..8696cd3334ee2 100644
--- a/clang/include/clang/AST/ExternalASTSource.h
+++ b/clang/include/clang/AST/ExternalASTSource.h
@@ -523,90 +523,6 @@ template <> struct PointerLikeTypeTraits<clang::LazyGenerationalDeclPtr> {
namespace clang {
-/// Represents a lazily-loaded vector of data.
-///
-/// The lazily-loaded vector of data contains data that is partially loaded
-/// from an external source and partially added by local translation. The
-/// items loaded from the external source are loaded lazily, when needed for
-/// iteration over the complete vector.
-template<typename T, typename Source,
- void (Source::*Loader)(SmallVectorImpl<T>&),
- unsigned LoadedStorage = 2, unsigned LocalStorage = 4>
-class LazyVector {
- SmallVector<T, LoadedStorage> Loaded;
- SmallVector<T, LocalStorage> Local;
-
-public:
- /// Iteration over the elements in the vector.
- ///
- /// In a complete iteration, the iterator walks the range [-M, N),
- /// where negative values are used to indicate elements
- /// loaded from the external source while non-negative values are used to
- /// indicate elements added via \c push_back().
- /// However, to provide iteration in source order (for, e.g., chained
- /// precompiled headers), dereferencing the iterator flips the negative
- /// values (corresponding to loaded entities), so that position -M
- /// corresponds to element 0 in the loaded entities vector, position -M+1
- /// corresponds to element 1 in the loaded entities vector, etc. This
- /// gives us a reasonably efficient, source-order walk.
- ///
- /// We define this as a wrapping iterator around an int. The
- /// iterator_adaptor_base class forwards the iterator methods to basic integer
- /// arithmetic.
- class iterator
- : public llvm::iterator_adaptor_base<
- iterator, int, std::random_access_iterator_tag, T, int, T *, T &> {
- friend class LazyVector;
-
- LazyVector *Self;
-
- iterator(LazyVector *Self, int Position)
- : iterator::iterator_adaptor_base(Position), Self(Self) {}
-
- bool isLoaded() const { return this->I < 0; }
-
- public:
- iterator() : iterator(nullptr, 0) {}
-
- typename iterator::reference operator*() const {
- if (isLoaded())
- return Self->Loaded.end()[this->I];
- return Self->Local.begin()[this->I];
- }
- };
-
- iterator begin(Source *source, bool LocalOnly = false) {
- if (LocalOnly)
- return iterator(this, 0);
-
- if (source)
- (source->*Loader)(Loaded);
- return iterator(this, -(int)Loaded.size());
- }
-
- iterator end() {
- return iterator(this, Local.size());
- }
-
- void push_back(const T& LocalValue) {
- Local.push_back(LocalValue);
- }
-
- void erase(iterator From, iterator To) {
- if (From.isLoaded() && To.isLoaded()) {
- Loaded.erase(&*From, &*To);
- return;
- }
-
- if (From.isLoaded()) {
- Loaded.erase(&*From, Loaded.end());
- From = begin(nullptr, true);
- }
-
- Local.erase(&*From, &*To);
- }
-};
-
/// A lazy pointer to a statement.
using LazyDeclStmtPtr =
LazyOffsetPtr<Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt>;
diff --git a/clang/include/clang/Sema/ExternalSemaSource.h b/clang/include/clang/Sema/ExternalSemaSource.h
index 03e8e8a66d148..0122beff53df9 100644
--- a/clang/include/clang/Sema/ExternalSemaSource.h
+++ b/clang/include/clang/Sema/ExternalSemaSource.h
@@ -249,6 +249,85 @@ class ExternalSemaSource : public ExternalASTSource {
/// \}
};
+/// Represents a lazily-loaded vector of data.
+///
+/// The lazily-loaded vector of data contains data that is partially loaded
+/// from an external source and partially added by local translation. The
+/// items loaded from the external source are loaded lazily, when needed for
+/// iteration over the complete vector.
+template <typename T, void (ExternalSemaSource::*Loader)(SmallVectorImpl<T> &),
+ unsigned LoadedStorage = 2, unsigned LocalStorage = 4>
+class LazyVector {
+ SmallVector<T, LoadedStorage> Loaded;
+ SmallVector<T, LocalStorage> Local;
+
+public:
+ /// Iteration over the elements in the vector.
+ ///
+ /// In a complete iteration, the iterator walks the range [-M, N),
+ /// where negative values are used to indicate elements
+ /// loaded from the external source while non-negative values are used to
+ /// indicate elements added via \c push_back().
+ /// However, to provide iteration in source order (for, e.g., chained
+ /// precompiled headers), dereferencing the iterator flips the negative
+ /// values (corresponding to loaded entities), so that position -M
+ /// corresponds to element 0 in the loaded entities vector, position -M+1
+ /// corresponds to element 1 in the loaded entities vector, etc. This
+ /// gives us a reasonably efficient, source-order walk.
+ ///
+ /// We define this as a wrapping iterator around an int. The
+ /// iterator_adaptor_base class forwards the iterator methods to basic integer
+ /// arithmetic.
+ class iterator
+ : public llvm::iterator_adaptor_base<
+ iterator, int, std::random_access_iterator_tag, T, int, T *, T &> {
+ friend class LazyVector;
+
+ LazyVector *Self;
+
+ iterator(LazyVector *Self, int Position)
+ : iterator::iterator_adaptor_base(Position), Self(Self) {}
+
+ bool isLoaded() const { return this->I < 0; }
+
+ public:
+ iterator() : iterator(nullptr, 0) {}
+
+ typename iterator::reference operator*() const {
+ if (isLoaded())
+ return Self->Loaded.end()[this->I];
+ return Self->Local.begin()[this->I];
+ }
+ };
+
+ iterator begin(ExternalSemaSource *source, bool LocalOnly = false) {
+ if (LocalOnly)
+ return iterator(this, 0);
+
+ if (source)
+ (source->*Loader)(Loaded);
+ return iterator(this, -(int)Loaded.size());
+ }
+
+ iterator end() { return iterator(this, Local.size()); }
+
+ void push_back(const T &LocalValue) { Local.push_back(LocalValue); }
+
+ void erase(iterator From, iterator To) {
+ if (From.isLoaded() && To.isLoaded()) {
+ Loaded.erase(&*From, &*To);
+ return;
+ }
+
+ if (From.isLoaded()) {
+ Loaded.erase(&*From, Loaded.end());
+ From = begin(nullptr, true);
+ }
+
+ Local.erase(&*From, &*To);
+ }
+};
+
} // end namespace clang
#endif
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index dcf112fd8eaa4..8fdc320562c00 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3617,7 +3617,7 @@ class Sema final : public SemaBase {
void getSortedUnusedLocalTypedefNameCandidates(
SmallVectorImpl<const TypedefNameDecl *> &Sorted) const;
- typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
+ typedef LazyVector<const DeclaratorDecl *,
&ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
UnusedFileScopedDeclsType;
@@ -3625,8 +3625,8 @@ class Sema final : public SemaBase {
/// and must warn if not used. Only contains the first declaration.
UnusedFileScopedDeclsType UnusedFileScopedDecls;
- typedef LazyVector<VarDecl *, ExternalSemaSource,
- &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
+ typedef LazyVector<VarDecl *, &ExternalSemaSource::ReadTentativeDefinitions,
+ 2, 2>
TentativeDefinitionsType;
/// All the tentative definitions encountered in the TU.
@@ -4960,8 +4960,8 @@ class Sema final : public SemaBase {
/// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls
SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
- typedef LazyVector<TypedefNameDecl *, ExternalSemaSource,
- &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
+ typedef LazyVector<TypedefNameDecl *, &ExternalSemaSource::ReadExtVectorDecls,
+ 2, 2>
ExtVectorDeclsType;
/// ExtVectorDecls - This is a list all the extended vector types. This allows
@@ -6537,7 +6537,7 @@ class Sema final : public SemaBase {
/// same list more than once.
std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet;
- typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
+ typedef LazyVector<CXXConstructorDecl *,
&ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
DelegatingCtorDeclsType;
More information about the cfe-commits
mailing list