Skip to content

Commit 9489bf4

Browse files
committed
Merge from 'main' to 'sycl-web' (intel#24)
CONFLICT (content): Merge conflict in clang/include/clang/Parse/Parser.h
2 parents d4d9b41 + 45ccfd9 commit 9489bf4

69 files changed

Lines changed: 4636 additions & 762 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static bool isTypedefTypeMatching(const TypedefType *const Typedef,
228228
/// Get the unqualified, dereferenced type of an argument.
229229
///
230230
/// \param CE call expression
231-
/// \param idx argument index
231+
/// \param Idx argument index
232232
///
233233
/// \returns type of the argument
234234
static const Type *argumentType(const CallExpr *const CE, const size_t Idx) {

clang-tools-extra/clangd/index/Background.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ BackgroundIndex::BackgroundIndex(
9797
BackgroundIndexStorage::Factory IndexStorageFactory, Options Opts)
9898
: SwapIndex(std::make_unique<MemIndex>()), TFS(TFS), CDB(CDB),
9999
ContextProvider(std::move(Opts.ContextProvider)),
100+
IndexedSymbols(IndexContents::All),
100101
Rebuilder(this, &IndexedSymbols, Opts.ThreadPoolSize),
101102
IndexStorageFactory(std::move(IndexStorageFactory)),
102103
Queue(std::move(Opts.OnProgress)),

clang-tools-extra/clangd/index/FileIndex.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ SlabTuple indexHeaderSymbols(llvm::StringRef Version, ASTContext &AST,
236236
/*CollectMainFileRefs=*/false);
237237
}
238238

239+
FileSymbols::FileSymbols(IndexContents IdxContents)
240+
: IdxContents(IdxContents) {}
241+
239242
void FileSymbols::update(llvm::StringRef Key,
240243
std::unique_ptr<SymbolSlab> Symbols,
241244
std::unique_ptr<RefSlab> Refs,
@@ -376,14 +379,14 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle,
376379
case IndexType::Light:
377380
return std::make_unique<MemIndex>(
378381
llvm::make_pointee_range(AllSymbols), std::move(AllRefs),
379-
std::move(AllRelations), std::move(Files),
382+
std::move(AllRelations), std::move(Files), IdxContents,
380383
std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
381384
std::move(RefsStorage), std::move(SymsStorage)),
382385
StorageSize);
383386
case IndexType::Heavy:
384387
return std::make_unique<dex::Dex>(
385388
llvm::make_pointee_range(AllSymbols), std::move(AllRefs),
386-
std::move(AllRelations), std::move(Files),
389+
std::move(AllRelations), std::move(Files), IdxContents,
387390
std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
388391
std::move(RefsStorage), std::move(SymsStorage)),
389392
StorageSize);
@@ -412,7 +415,9 @@ void FileSymbols::profile(MemoryTree &MT) const {
412415

413416
FileIndex::FileIndex()
414417
: MergedIndex(&MainFileIndex, &PreambleIndex),
418+
PreambleSymbols(IndexContents::Symbols | IndexContents::Relations),
415419
PreambleIndex(std::make_unique<MemIndex>()),
420+
MainFileSymbols(IndexContents::All),
416421
MainFileIndex(std::make_unique<MemIndex>()) {}
417422

418423
void FileIndex::updatePreamble(PathRef Path, llvm::StringRef Version,

clang-tools-extra/clangd/index/FileIndex.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ enum class DuplicateHandling {
7171
/// locking when we swap or obtain references to snapshots.
7272
class FileSymbols {
7373
public:
74+
FileSymbols(IndexContents IdxContents);
7475
/// Updates all slabs associated with the \p Key.
7576
/// If either is nullptr, corresponding data for \p Key will be removed.
7677
/// If CountReferences is true, \p Refs will be used for counting references
@@ -91,6 +92,8 @@ class FileSymbols {
9192
void profile(MemoryTree &MT) const;
9293

9394
private:
95+
IndexContents IdxContents;
96+
9497
struct RefSlabAndCountReferences {
9598
std::shared_ptr<RefSlab> Slab;
9699
bool CountReferences = false;

clang-tools-extra/clangd/index/Index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void SwapIndex::relations(
7676
return snapshot()->relations(R, CB);
7777
}
7878

79-
llvm::unique_function<bool(llvm::StringRef) const>
79+
llvm::unique_function<IndexContents(llvm::StringRef) const>
8080
SwapIndex::indexedFiles() const {
8181
// The index snapshot should outlive this method return value.
8282
auto SnapShot = snapshot();

clang-tools-extra/clangd/index/Index.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ struct RelationsRequest {
8282
llvm::Optional<uint32_t> Limit;
8383
};
8484

85+
/// Describes what data is covered by an index.
86+
///
87+
/// Indexes may contain symbols but not references from a file, etc.
88+
/// This affects merging: if a staler index contains a reference but a fresher
89+
/// one does not, we want to trust the fresher index *only* if it actually
90+
/// includes references in general.
91+
enum class IndexContents : uint8_t {
92+
None = 0,
93+
Symbols = 1 << 1,
94+
References = 1 << 2,
95+
Relations = 1 << 3,
96+
All = Symbols | References | Relations
97+
};
98+
99+
inline constexpr IndexContents operator&(IndexContents L, IndexContents R) {
100+
return static_cast<IndexContents>(static_cast<uint8_t>(L) &
101+
static_cast<uint8_t>(R));
102+
}
103+
104+
inline constexpr IndexContents operator|(IndexContents L, IndexContents R) {
105+
return static_cast<IndexContents>(static_cast<uint8_t>(L) |
106+
static_cast<uint8_t>(R));
107+
}
108+
85109
/// Interface for symbol indexes that can be used for searching or
86110
/// matching symbols among a set of symbols based on names or unique IDs.
87111
class SymbolIndex {
@@ -125,7 +149,7 @@ class SymbolIndex {
125149

126150
/// Returns function which checks if the specified file was used to build this
127151
/// index or not. The function must only be called while the index is alive.
128-
virtual llvm::unique_function<bool(llvm::StringRef) const>
152+
virtual llvm::unique_function<IndexContents(llvm::StringRef) const>
129153
indexedFiles() const = 0;
130154

131155
/// Returns estimated size of index (in bytes).
@@ -152,7 +176,7 @@ class SwapIndex : public SymbolIndex {
152176
llvm::function_ref<void(const SymbolID &, const Symbol &)>)
153177
const override;
154178

155-
llvm::unique_function<bool(llvm::StringRef) const>
179+
llvm::unique_function<IndexContents(llvm::StringRef) const>
156180
indexedFiles() const override;
157181

158182
size_t estimateMemoryUsage() const override;

clang-tools-extra/clangd/index/MemIndex.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ void MemIndex::relations(
109109
}
110110
}
111111

112-
llvm::unique_function<bool(llvm::StringRef) const>
112+
llvm::unique_function<IndexContents(llvm::StringRef) const>
113113
MemIndex::indexedFiles() const {
114114
return [this](llvm::StringRef FileURI) {
115115
auto Path = URI::resolve(FileURI);
116116
if (!Path) {
117117
llvm::consumeError(Path.takeError());
118-
return false;
118+
return IndexContents::None;
119119
}
120-
return Files.contains(*Path);
120+
return Files.contains(*Path) ? IdxContents : IndexContents::None;
121121
};
122122
}
123123

clang-tools-extra/clangd/index/MemIndex.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ class MemIndex : public SymbolIndex {
4848
template <typename SymbolRange, typename RefRange, typename RelationRange,
4949
typename FileRange, typename Payload>
5050
MemIndex(SymbolRange &&Symbols, RefRange &&Refs, RelationRange &&Relations,
51-
FileRange &&Files, Payload &&BackingData, size_t BackingDataSize)
51+
FileRange &&Files, IndexContents IdxContents, Payload &&BackingData,
52+
size_t BackingDataSize)
5253
: MemIndex(std::forward<SymbolRange>(Symbols),
5354
std::forward<RefRange>(Refs),
5455
std::forward<RelationRange>(Relations),
5556
std::forward<Payload>(BackingData), BackingDataSize) {
5657
this->Files = std::forward<FileRange>(Files);
58+
this->IdxContents = IdxContents;
5759
}
5860

5961
/// Builds an index from slabs. The index takes ownership of the data.
@@ -74,7 +76,7 @@ class MemIndex : public SymbolIndex {
7476
llvm::function_ref<void(const SymbolID &, const Symbol &)>
7577
Callback) const override;
7678

77-
llvm::unique_function<bool(llvm::StringRef) const>
79+
llvm::unique_function<IndexContents(llvm::StringRef) const>
7880
indexedFiles() const override;
7981

8082
size_t estimateMemoryUsage() const override;
@@ -90,6 +92,8 @@ class MemIndex : public SymbolIndex {
9092
llvm::DenseMap<std::pair<SymbolID, uint8_t>, std::vector<SymbolID>> Relations;
9193
// Set of files which were used during this index build.
9294
llvm::StringSet<> Files;
95+
// Contents of the index (symbols, references, etc.)
96+
IndexContents IdxContents;
9397
std::shared_ptr<void> KeepAlive; // poor man's move-only std::any
9498
// Size of memory retained by KeepAlive.
9599
size_t BackingDataSize = 0;

clang-tools-extra/clangd/index/Merge.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ bool MergedIndex::fuzzyFind(
4949
More |= Static->fuzzyFind(Req, [&](const Symbol &S) {
5050
// We expect the definition to see the canonical declaration, so it seems
5151
// to be enough to check only the definition if it exists.
52-
if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
53-
: S.CanonicalDeclaration.FileURI))
52+
if ((DynamicContainsFile(S.Definition ? S.Definition.FileURI
53+
: S.CanonicalDeclaration.FileURI) &
54+
IndexContents::Symbols) != IndexContents::None)
5455
return;
5556
auto DynS = Dyn.find(S.ID);
5657
++StaticCount;
@@ -84,8 +85,9 @@ void MergedIndex::lookup(
8485
Static->lookup(Req, [&](const Symbol &S) {
8586
// We expect the definition to see the canonical declaration, so it seems
8687
// to be enough to check only the definition if it exists.
87-
if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
88-
: S.CanonicalDeclaration.FileURI))
88+
if ((DynamicContainsFile(S.Definition ? S.Definition.FileURI
89+
: S.CanonicalDeclaration.FileURI) &
90+
IndexContents::Symbols) != IndexContents::None)
8991
return;
9092
const Symbol *Sym = B.find(S.ID);
9193
RemainingIDs.erase(S.ID);
@@ -121,7 +123,8 @@ bool MergedIndex::refs(const RefsRequest &Req,
121123
// We return less than Req.Limit if static index returns more refs for dirty
122124
// files.
123125
bool StaticHadMore = Static->refs(Req, [&](const Ref &O) {
124-
if (DynamicContainsFile(O.Location.FileURI))
126+
if ((DynamicContainsFile(O.Location.FileURI) & IndexContents::References) !=
127+
IndexContents::None)
125128
return; // ignore refs that have been seen from dynamic index.
126129
if (Remaining == 0) {
127130
More = true;
@@ -133,11 +136,11 @@ bool MergedIndex::refs(const RefsRequest &Req,
133136
return More || StaticHadMore;
134137
}
135138

136-
llvm::unique_function<bool(llvm::StringRef) const>
139+
llvm::unique_function<IndexContents(llvm::StringRef) const>
137140
MergedIndex::indexedFiles() const {
138141
return [DynamicContainsFile{Dynamic->indexedFiles()},
139142
StaticContainsFile{Static->indexedFiles()}](llvm::StringRef FileURI) {
140-
return DynamicContainsFile(FileURI) || StaticContainsFile(FileURI);
143+
return DynamicContainsFile(FileURI) | StaticContainsFile(FileURI);
141144
};
142145
}
143146

clang-tools-extra/clangd/index/Merge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MergedIndex : public SymbolIndex {
4141
void relations(const RelationsRequest &,
4242
llvm::function_ref<void(const SymbolID &, const Symbol &)>)
4343
const override;
44-
llvm::unique_function<bool(llvm::StringRef) const>
44+
llvm::unique_function<IndexContents(llvm::StringRef) const>
4545
indexedFiles() const override;
4646
size_t estimateMemoryUsage() const override {
4747
return Dynamic->estimateMemoryUsage() + Static->estimateMemoryUsage();

0 commit comments

Comments
 (0)