Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (intel#20)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGClass.cpp
  • Loading branch information
sndmitriev committed Oct 17, 2019
2 parents 820f77c + af6248c commit a3b83b5
Show file tree
Hide file tree
Showing 96 changed files with 2,376 additions and 688 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ canOverloadedOperatorArgsBeModified(const FunctionDecl *OperatorDecl,
// These functions must be declared const in order to not be able to modify
// the instance of the class they are called through.
if (ParamCount == 1 &&
!OperatorDecl->getType()->getAs<FunctionType>()->isConst())
!OperatorDecl->getType()->castAs<FunctionType>()->isConst())
return true;

if (isNonConstReferenceType(OperatorDecl->getParamDecl(0)->getType()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static StringRef getValueOfValueInit(const QualType InitType) {
return "false";

case Type::STK_Integral:
switch (InitType->getAs<BuiltinType>()->getKind()) {
switch (InitType->castAs<BuiltinType>()->getKind()) {
case BuiltinType::Char_U:
case BuiltinType::UChar:
case BuiltinType::Char_S:
Expand All @@ -47,7 +47,7 @@ static StringRef getValueOfValueInit(const QualType InitType) {
}

case Type::STK_Floating:
switch (InitType->getAs<BuiltinType>()->getKind()) {
switch (InitType->castAs<BuiltinType>()->getKind()) {
case BuiltinType::Half:
case BuiltinType::Float:
return "0.0f";
Expand All @@ -58,10 +58,10 @@ static StringRef getValueOfValueInit(const QualType InitType) {
case Type::STK_FloatingComplex:
case Type::STK_IntegralComplex:
return getValueOfValueInit(
InitType->getAs<ComplexType>()->getElementType());
InitType->castAs<ComplexType>()->getElementType());

case Type::STK_FixedPoint:
switch (InitType->getAs<BuiltinType>()->getKind()) {
switch (InitType->castAs<BuiltinType>()->getKind()) {
case BuiltinType::ShortAccum:
case BuiltinType::SatShortAccum:
return "0.0hk";
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clangd/XRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1107,7 +1108,7 @@ static void fillSubTypes(const SymbolID &ID,
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)) {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/index/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct RefsRequest {

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;
};
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clangd/index/MemIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void MemIndex::relations(
Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
for (const SymbolID &Subject : Req.Subjects) {
LookupRequest LookupReq;
auto It = Relations.find(std::make_pair(Subject, Req.Predicate));
auto It = Relations.find(
std::make_pair(Subject, static_cast<uint8_t>(Req.Predicate)));
if (It != Relations.end()) {
for (const auto &Obj : It->second) {
if (Remaining > 0) {
Expand Down
10 changes: 6 additions & 4 deletions clang-tools-extra/clangd/index/MemIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class MemIndex : public SymbolIndex {
for (const std::pair<SymbolID, llvm::ArrayRef<Ref>> &R : Refs)
this->Refs.try_emplace(R.first, R.second.begin(), R.second.end());
for (const Relation &R : Relations)
this->Relations[std::make_pair(R.Subject, R.Predicate)].push_back(
R.Object);
this->Relations[std::make_pair(R.Subject,
static_cast<uint8_t>(R.Predicate))]
.push_back(R.Object);
}
// Symbols are owned by BackingData, Index takes ownership.
template <typename SymbolRange, typename RefRange, typename RelationRange,
Expand Down Expand Up @@ -69,8 +70,9 @@ class MemIndex : public SymbolIndex {
// 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>>
Relations;
static_assert(sizeof(RelationKind) == sizeof(uint8_t),
"RelationKind should be of same size as a uint8_t");
llvm::DenseMap<std::pair<SymbolID, uint8_t>, std::vector<SymbolID>> Relations;
std::shared_ptr<void> KeepAlive; // poor man's move-only std::any
// Size of memory retained by KeepAlive.
size_t BackingDataSize = 0;
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clangd/index/Relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace clang {
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) {
Expand Down
37 changes: 7 additions & 30 deletions clang-tools-extra/clangd/index/Relation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 }.
/// as { Subject = A, Predicate = BaseOf, Object = B }.
struct Relation {
SymbolID Subject;
index::SymbolRole Predicate;
RelationKind Predicate;
SymbolID Object;

bool operator==(const Relation &Other) const {
Expand Down Expand Up @@ -59,7 +63,7 @@ class RelationSlab {

/// 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.
Expand All @@ -85,31 +89,4 @@ class RelationSlab {
} // namespace clangd
} // namespace clang

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;
}

static inline clang::index::SymbolRole getTombstoneKey() {
// Choose another enumerator that's not a relation.
return clang::index::SymbolRole::Definition;
}

static unsigned getHashValue(const clang::index::SymbolRole &Key) {
return hash_value(Key);
}

static bool isEqual(const clang::index::SymbolRole &LHS,
const clang::index::SymbolRole &RHS) {
return LHS == RHS;
}
};

} // namespace llvm

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_RELATION_H
29 changes: 2 additions & 27 deletions clang-tools-extra/clangd/index/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,6 @@ llvm::Error makeError(const llvm::Twine &Msg) {
return llvm::make_error<llvm::StringError>(Msg,
llvm::inconvertibleErrorCode());
}
} // namespace

RelationKind symbolRoleToRelationKind(index::SymbolRole Role) {
// SymbolRole is used to record relations in the index.
// Only handle the relations we actually store currently.
// If we start storing more relations, this list can be expanded.
switch (Role) {
case index::SymbolRole::RelationBaseOf:
return RelationKind::BaseOf;
default:
llvm_unreachable("Unsupported symbol role");
}
}

index::SymbolRole relationKindToSymbolRole(RelationKind Kind) {
switch (Kind) {
case RelationKind::BaseOf:
return index::SymbolRole::RelationBaseOf;
}
llvm_unreachable("Invalid relation kind");
}

namespace {

// IO PRIMITIVES
// We use little-endian 32 bit ints, sometimes with variable-length encoding.
Expand Down Expand Up @@ -395,15 +372,13 @@ readRefs(Reader &Data, llvm::ArrayRef<llvm::StringRef> Strings) {

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};
}
Expand Down
5 changes: 0 additions & 5 deletions clang-tools-extra/clangd/index/Serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ std::string toYAML(const Relation &);
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

Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clangd/index/SymbolCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ void SymbolCollector::processRelations(
// 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});
}
}

Expand Down
11 changes: 4 additions & 7 deletions clang-tools-extra/clangd/index/YAMLSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,11 @@ template <> struct MappingTraits<Ref> {

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;
};
Expand All @@ -303,7 +300,7 @@ template <> struct MappingTraits<SymbolID> {

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);
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clangd/index/dex/Dex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ void Dex::relations(
Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
for (const SymbolID &Subject : Req.Subjects) {
LookupRequest LookupReq;
auto It = Relations.find(std::make_pair(Subject, Req.Predicate));
auto It = Relations.find(
std::make_pair(Subject, static_cast<uint8_t>(Req.Predicate)));
if (It != Relations.end()) {
for (const auto &Object : It->second) {
if (Remaining > 0) {
Expand Down
11 changes: 7 additions & 4 deletions clang-tools-extra/clangd/index/dex/Dex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -49,8 +50,9 @@ class Dex : public SymbolIndex {
for (auto &&Ref : Refs)
this->Refs.try_emplace(Ref.first, Ref.second);
for (auto &&Rel : Relations)
this->Relations[std::make_pair(Rel.Subject, Rel.Predicate)].push_back(
Rel.Object);
this->Relations[std::make_pair(Rel.Subject,
static_cast<uint8_t>(Rel.Predicate))]
.push_back(Rel.Object);
buildIndex();
}
// Symbols and Refs are owned by BackingData, Index takes ownership.
Expand Down Expand Up @@ -106,8 +108,9 @@ class Dex : public SymbolIndex {
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>>
Relations;
static_assert(sizeof(RelationKind) == sizeof(uint8_t),
"RelationKind should be of same size as a uint8_t");
llvm::DenseMap<std::pair<SymbolID, uint8_t>, std::vector<SymbolID>> Relations;
std::shared_ptr<void> KeepAlive; // poor man's move-only std::any
// Size of memory retained by KeepAlive.
size_t BackingDataSize = 0;
Expand Down
5 changes: 2 additions & 3 deletions clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ TEST_F(BackgroundIndexTest, ShardStorageTest) {
// 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);
}
Expand Down
7 changes: 3 additions & 4 deletions clang-tools-extra/clangd/unittests/DexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,16 +705,15 @@ TEST(DexTests, Relations) {

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);
});
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/FileIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ TEST(FileIndexTest, Relations) {
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);
}
Expand Down
30 changes: 12 additions & 18 deletions clang-tools-extra/clangd/unittests/IndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,15 @@ TEST(RelationSlab, Lookup) {
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) {
Expand All @@ -105,14 +100,13 @@ TEST(RelationSlab, Duplicates) {
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) {
Expand Down
Loading

0 comments on commit a3b83b5

Please sign in to comment.