hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
Move the RelationKind from Serialization.h to Relation.h. This patch doesn't
introduce any breaking changes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68981
Files:
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/index/Index.h
clang-tools-extra/clangd/index/MemIndex.h
clang-tools-extra/clangd/index/Relation.cpp
clang-tools-extra/clangd/index/Relation.h
clang-tools-extra/clangd/index/Serialization.cpp
clang-tools-extra/clangd/index/Serialization.h
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/index/YAMLSerialization.cpp
clang-tools-extra/clangd/index/dex/Dex.h
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/DexTests.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp
clang-tools-extra/clangd/unittests/IndexTests.cpp
clang-tools-extra/clangd/unittests/SerializationTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -482,7 +482,7 @@
std::vector<SymbolID> Result;
RelationsRequest Req;
Req.Subjects.insert(Subject);
- Req.Predicate = index::SymbolRole::RelationBaseOf;
+ Req.Predicate = RelationKind::BaseOf;
Index->relations(Req,
[&Result](const SymbolID &Subject, const Symbol &Object) {
Result.push_back(Object.ID);
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -673,8 +673,7 @@
const Symbol &Base = findSymbol(Symbols, "Base");
const Symbol &Derived = findSymbol(Symbols, "Derived");
EXPECT_THAT(Relations,
- Contains(Relation{Base.ID, index::SymbolRole::RelationBaseOf,
- Derived.ID}));
+ Contains(Relation{Base.ID, RelationKind::BaseOf, Derived.ID}));
}
TEST_F(SymbolCollectorTest, References) {
Index: clang-tools-extra/clangd/unittests/SerializationTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SerializationTests.cpp
+++ clang-tools-extra/clangd/unittests/SerializationTests.cpp
@@ -152,9 +152,9 @@
SymbolID Base = cantFail(SymbolID::fromStr("6481EE7AF2841756"));
SymbolID Derived = cantFail(SymbolID::fromStr("6512AEC512EA3A2D"));
ASSERT_TRUE(bool(ParsedYAML->Relations));
- EXPECT_THAT(*ParsedYAML->Relations,
- UnorderedElementsAre(
- Relation{Base, index::SymbolRole::RelationBaseOf, Derived}));
+ EXPECT_THAT(
+ *ParsedYAML->Relations,
+ UnorderedElementsAre(Relation{Base, RelationKind::BaseOf, Derived}));
}
std::vector<std::string> YAMLFromSymbols(const SymbolSlab &Slab) {
Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -83,20 +83,15 @@
SymbolID D{"D"};
RelationSlab::Builder Builder;
- Builder.insert(Relation{A, index::SymbolRole::RelationBaseOf, B});
- Builder.insert(Relation{A, index::SymbolRole::RelationBaseOf, C});
- Builder.insert(Relation{B, index::SymbolRole::RelationBaseOf, D});
- Builder.insert(Relation{C, index::SymbolRole::RelationBaseOf, D});
- Builder.insert(Relation{B, index::SymbolRole::RelationChildOf, A});
- Builder.insert(Relation{C, index::SymbolRole::RelationChildOf, A});
- Builder.insert(Relation{D, index::SymbolRole::RelationChildOf, B});
- Builder.insert(Relation{D, index::SymbolRole::RelationChildOf, C});
+ Builder.insert(Relation{A, RelationKind::BaseOf, B});
+ Builder.insert(Relation{A, RelationKind::BaseOf, C});
+ Builder.insert(Relation{B, RelationKind::BaseOf, D});
+ Builder.insert(Relation{C, RelationKind::BaseOf, D});
RelationSlab Slab = std::move(Builder).build();
- EXPECT_THAT(
- Slab.lookup(A, index::SymbolRole::RelationBaseOf),
- UnorderedElementsAre(Relation{A, index::SymbolRole::RelationBaseOf, B},
- Relation{A, index::SymbolRole::RelationBaseOf, C}));
+ EXPECT_THAT(Slab.lookup(A, RelationKind::BaseOf),
+ UnorderedElementsAre(Relation{A, RelationKind::BaseOf, B},
+ Relation{A, RelationKind::BaseOf, C}));
}
TEST(RelationSlab, Duplicates) {
@@ -105,14 +100,13 @@
SymbolID C{"C"};
RelationSlab::Builder Builder;
- Builder.insert(Relation{A, index::SymbolRole::RelationBaseOf, B});
- Builder.insert(Relation{A, index::SymbolRole::RelationBaseOf, C});
- Builder.insert(Relation{A, index::SymbolRole::RelationBaseOf, B});
+ Builder.insert(Relation{A, RelationKind::BaseOf, B});
+ Builder.insert(Relation{A, RelationKind::BaseOf, C});
+ Builder.insert(Relation{A, RelationKind::BaseOf, B});
RelationSlab Slab = std::move(Builder).build();
- EXPECT_THAT(Slab, UnorderedElementsAre(
- Relation{A, index::SymbolRole::RelationBaseOf, B},
- Relation{A, index::SymbolRole::RelationBaseOf, C}));
+ EXPECT_THAT(Slab, UnorderedElementsAre(Relation{A, RelationKind::BaseOf, B},
+ Relation{A, RelationKind::BaseOf, C}));
}
TEST(SwapIndexTest, OldIndexRecycled) {
Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -364,7 +364,7 @@
uint32_t Results = 0;
RelationsRequest Req;
Req.Subjects.insert(A);
- Req.Predicate = index::SymbolRole::RelationBaseOf;
+ Req.Predicate = RelationKind::BaseOf;
Index.relations(Req, [&](const SymbolID &, const Symbol &) { ++Results; });
EXPECT_EQ(Results, 1u);
}
Index: clang-tools-extra/clangd/unittests/DexTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DexTests.cpp
+++ clang-tools-extra/clangd/unittests/DexTests.cpp
@@ -705,16 +705,15 @@
std::vector<Symbol> Symbols{Parent, Child1, Child2};
- std::vector<Relation> Relations{
- {Parent.ID, index::SymbolRole::RelationBaseOf, Child1.ID},
- {Parent.ID, index::SymbolRole::RelationBaseOf, Child2.ID}};
+ std::vector<Relation> Relations{{Parent.ID, RelationKind::BaseOf, Child1.ID},
+ {Parent.ID, RelationKind::BaseOf, Child2.ID}};
Dex I{Symbols, RefSlab(), Relations};
std::vector<SymbolID> Results;
RelationsRequest Req;
Req.Subjects.insert(Parent.ID);
- Req.Predicate = index::SymbolRole::RelationBaseOf;
+ Req.Predicate = RelationKind::BaseOf;
I.relations(Req, [&](const SymbolID &Subject, const Symbol &Object) {
Results.push_back(Object.ID);
});
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -239,9 +239,8 @@
// containing the definition of the subject (A_CC)
SymbolID A = findSymbol(*ShardHeader->Symbols, "A_CC").ID;
SymbolID B = findSymbol(*ShardSource->Symbols, "B_CC").ID;
- EXPECT_THAT(
- *ShardHeader->Relations,
- UnorderedElementsAre(Relation{A, index::SymbolRole::RelationBaseOf, B}));
+ EXPECT_THAT(*ShardHeader->Relations,
+ UnorderedElementsAre(Relation{A, RelationKind::BaseOf, B}));
// (and not in the file containing the definition of the object (B_CC)).
EXPECT_EQ(ShardSource->Relations->size(), 0u);
}
Index: clang-tools-extra/clangd/index/dex/Dex.h
===================================================================
--- clang-tools-extra/clangd/index/dex/Dex.h
+++ clang-tools-extra/clangd/index/dex/Dex.h
@@ -26,6 +26,7 @@
#include "Trigram.h"
#include "index/Index.h"
#include "index/MemIndex.h"
+#include "index/Relation.h"
#include "index/SymbolCollector.h"
namespace clang {
@@ -106,7 +107,7 @@
llvm::DenseMap<Token, PostingList> InvertedIndex;
dex::Corpus Corpus;
llvm::DenseMap<SymbolID, llvm::ArrayRef<Ref>> Refs;
- llvm::DenseMap<std::pair<SymbolID, index::SymbolRole>, std::vector<SymbolID>>
+ llvm::DenseMap<std::pair<SymbolID, RelationKind>, std::vector<SymbolID>>
Relations;
std::shared_ptr<void> KeepAlive; // poor man's move-only std::any
// Size of memory retained by KeepAlive.
Index: clang-tools-extra/clangd/index/YAMLSerialization.cpp
===================================================================
--- clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -282,14 +282,11 @@
struct NormalizedSymbolRole {
NormalizedSymbolRole(IO &) {}
- NormalizedSymbolRole(IO &IO, SymbolRole R) {
- Kind = static_cast<uint8_t>(clang::clangd::symbolRoleToRelationKind(R));
+ NormalizedSymbolRole(IO &IO, RelationKind R) {
+ Kind = static_cast<uint8_t>(R);
}
- SymbolRole denormalize(IO &IO) {
- return clang::clangd::relationKindToSymbolRole(
- static_cast<RelationKind>(Kind));
- }
+ RelationKind denormalize(IO &IO) { return static_cast<RelationKind>(Kind); }
uint8_t Kind = 0;
};
@@ -303,7 +300,7 @@
template <> struct MappingTraits<Relation> {
static void mapping(IO &IO, Relation &Relation) {
- MappingNormalization<NormalizedSymbolRole, SymbolRole> NRole(
+ MappingNormalization<NormalizedSymbolRole, RelationKind> NRole(
IO, Relation.Predicate);
IO.mapRequired("Subject", Relation.Subject);
IO.mapRequired("Predicate", NRole->Kind);
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===================================================================
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -445,8 +445,7 @@
// in the index and find nothing, but that's a situation they
// probably need to handle for other reasons anyways.
// We currently do (B) because it's simpler.
- this->Relations.insert(
- Relation{ID, index::SymbolRole::RelationBaseOf, *ObjectID});
+ this->Relations.insert(Relation{ID, RelationKind::BaseOf, *ObjectID});
}
}
Index: clang-tools-extra/clangd/index/Serialization.h
===================================================================
--- clang-tools-extra/clangd/index/Serialization.h
+++ clang-tools-extra/clangd/index/Serialization.h
@@ -83,11 +83,6 @@
std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef Filename,
bool UseDex = true);
-// Used for serializing SymbolRole as used in Relation.
-enum class RelationKind : uint8_t { BaseOf };
-RelationKind symbolRoleToRelationKind(index::SymbolRole);
-index::SymbolRole relationKindToSymbolRole(RelationKind);
-
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/index/Serialization.cpp
===================================================================
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -395,15 +395,13 @@
void writeRelation(const Relation &R, llvm::raw_ostream &OS) {
OS << R.Subject.raw();
- RelationKind Kind = symbolRoleToRelationKind(R.Predicate);
- OS.write(static_cast<uint8_t>(Kind));
+ OS.write(static_cast<uint8_t>(R.Predicate));
OS << R.Object.raw();
}
Relation readRelation(Reader &Data) {
SymbolID Subject = Data.consumeID();
- index::SymbolRole Predicate =
- relationKindToSymbolRole(static_cast<RelationKind>(Data.consume8()));
+ RelationKind Predicate = static_cast<RelationKind>(Data.consume8());
SymbolID Object = Data.consumeID();
return {Subject, Predicate, Object};
}
Index: clang-tools-extra/clangd/index/Relation.h
===================================================================
--- clang-tools-extra/clangd/index/Relation.h
+++ clang-tools-extra/clangd/index/Relation.h
@@ -19,12 +19,16 @@
namespace clang {
namespace clangd {
+enum class RelationKind : uint8_t {
+ BaseOf,
+};
+
/// Represents a relation between two symbols.
/// For an example "A is a base class of B" may be represented
/// as { Subject = A, Predicate = RelationBaseOf, Object = B }.
struct Relation {
SymbolID Subject;
- index::SymbolRole Predicate;
+ RelationKind Predicate;
SymbolID Object;
bool operator==(const Relation &Other) const {
@@ -59,7 +63,7 @@
/// Lookup all relations matching the given subject and predicate.
llvm::iterator_range<iterator> lookup(const SymbolID &Subject,
- index::SymbolRole Predicate) const;
+ RelationKind Predicate) const;
/// RelationSlab::Builder is a mutable container that can 'freeze' to
/// RelationSlab.
@@ -87,25 +91,19 @@
namespace llvm {
-// Support index::SymbolRole as a DenseMap key for the purpose of looking up
-// relations.
-template <> struct DenseMapInfo<clang::index::SymbolRole> {
- static inline clang::index::SymbolRole getEmptyKey() {
- // Choose an enumerator that's not a relation.
- return clang::index::SymbolRole::Declaration;
+// Support RelationKind as a DenseMap key for the purpose of looking up.
+template <> struct DenseMapInfo<clang::clangd::RelationKind> {
+ static inline clang::clangd::RelationKind getEmptyKey() {
+ return clang::clangd::RelationKind(-1);
}
-
- static inline clang::index::SymbolRole getTombstoneKey() {
- // Choose another enumerator that's not a relation.
- return clang::index::SymbolRole::Definition;
+ static inline clang::clangd::RelationKind getTombstoneKey() {
+ return clang::clangd::RelationKind(-2);
}
-
- static unsigned getHashValue(const clang::index::SymbolRole &Key) {
- return hash_value(Key);
+ static unsigned getHashValue(const clang::clangd::RelationKind &Sym) {
+ return hash_value(Sym);
}
-
- static bool isEqual(const clang::index::SymbolRole &LHS,
- const clang::index::SymbolRole &RHS) {
+ static bool isEqual(const clang::clangd::RelationKind &LHS,
+ const clang::clangd::RelationKind &RHS) {
return LHS == RHS;
}
};
Index: clang-tools-extra/clangd/index/Relation.cpp
===================================================================
--- clang-tools-extra/clangd/index/Relation.cpp
+++ clang-tools-extra/clangd/index/Relation.cpp
@@ -14,8 +14,7 @@
namespace clangd {
llvm::iterator_range<RelationSlab::iterator>
-RelationSlab::lookup(const SymbolID &Subject,
- index::SymbolRole Predicate) const {
+RelationSlab::lookup(const SymbolID &Subject, RelationKind Predicate) const {
auto IterPair = std::equal_range(Relations.begin(), Relations.end(),
Relation{Subject, Predicate, SymbolID{}},
[](const Relation &A, const Relation &B) {
Index: clang-tools-extra/clangd/index/MemIndex.h
===================================================================
--- clang-tools-extra/clangd/index/MemIndex.h
+++ clang-tools-extra/clangd/index/MemIndex.h
@@ -69,7 +69,7 @@
// A map from symbol ID to symbol refs, support query by IDs.
llvm::DenseMap<SymbolID, llvm::ArrayRef<Ref>> Refs;
// A map from (subject, predicate) pair to objects.
- llvm::DenseMap<std::pair<SymbolID, index::SymbolRole>, std::vector<SymbolID>>
+ llvm::DenseMap<std::pair<SymbolID, RelationKind>, std::vector<SymbolID>>
Relations;
std::shared_ptr<void> KeepAlive; // poor man's move-only std::any
// Size of memory retained by KeepAlive.
Index: clang-tools-extra/clangd/index/Index.h
===================================================================
--- clang-tools-extra/clangd/index/Index.h
+++ clang-tools-extra/clangd/index/Index.h
@@ -75,7 +75,7 @@
struct RelationsRequest {
llvm::DenseSet<SymbolID> Subjects;
- index::SymbolRole Predicate;
+ RelationKind Predicate;
/// If set, limit the number of relations returned from the index.
llvm::Optional<uint32_t> Limit;
};
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -18,6 +18,7 @@
#include "URI.h"
#include "index/Index.h"
#include "index/Merge.h"
+#include "index/Relation.h"
#include "index/SymbolCollector.h"
#include "index/SymbolLocation.h"
#include "clang/AST/ASTContext.h"
@@ -1107,7 +1108,7 @@
const SymbolIndex *Index, int Levels, PathRef TUPath) {
RelationsRequest Req;
Req.Subjects.insert(ID);
- Req.Predicate = index::SymbolRole::RelationBaseOf;
+ Req.Predicate = RelationKind::BaseOf;
Index->relations(Req, [&](const SymbolID &Subject, const Symbol &Object) {
if (Optional<TypeHierarchyItem> ChildSym =
symbolToTypeHierarchyItem(Object, Index, TUPath)) {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits