2018-08-15 00:03:32 +08:00
|
|
|
//===--- Merge.h -------------------------------------------------*- C++-*-===//
|
2018-01-15 20:33:00 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
2018-08-15 00:03:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-01-15 20:33:00 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
|
2018-08-15 00:03:32 +08:00
|
|
|
|
2018-01-15 20:33:00 +08:00
|
|
|
#include "Index.h"
|
2018-08-15 00:03:32 +08:00
|
|
|
|
2018-01-15 20:33:00 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
|
|
|
// Merge symbols L and R, preferring data from L in case of conflict.
|
|
|
|
// The two symbols must have the same ID.
|
|
|
|
// Returned symbol may contain data owned by either source.
|
2018-08-31 21:55:01 +08:00
|
|
|
Symbol mergeSymbol(const Symbol &L, const Symbol &R);
|
2018-01-15 20:33:00 +08:00
|
|
|
|
2018-10-04 22:20:22 +08:00
|
|
|
// MergedIndex is a composite index based on two provided Indexes:
|
2018-01-15 20:33:00 +08:00
|
|
|
// - the Dynamic index covers few files, but is relatively up-to-date.
|
|
|
|
// - the Static index covers a bigger set of files, but is relatively stale.
|
|
|
|
// The returned index attempts to combine results, and avoid duplicates.
|
2018-09-01 03:53:37 +08:00
|
|
|
//
|
|
|
|
// FIXME: We don't have a mechanism in Index to track deleted symbols and
|
[clangd] SymbolOccurrences -> Refs and cleanup
Summary:
A few things that I noticed while merging the SwapIndex patch:
- SymbolOccurrences and particularly SymbolOccurrenceSlab are unwieldy names,
and these names appear *a lot*. Ref, RefSlab, etc seem clear enough
and read/format much better.
- The asymmetry between SymbolSlab and RefSlab (build() vs freeze()) is
confusing and irritating, and doesn't even save much code.
Avoiding RefSlab::Builder was my idea, but it was a bad one; add it.
- DenseMap<SymbolID, ArrayRef<Ref>> seems like a reasonable compromise for
constructing MemIndex - and means many less wasted allocations than the
current DenseMap<SymbolID, vector<Ref*>> for FileIndex, and none for
slabs.
- RefSlab::find() is not actually used for anything, so we can throw
away the DenseMap and keep the representation much more compact.
- A few naming/consistency fixes: e.g. Slabs,Refs -> Symbols,Refs.
Reviewers: ioeric
Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51605
llvm-svn: 341368
2018-09-04 22:39:56 +08:00
|
|
|
// refs in dirty files, so the merged index may return stale symbols
|
|
|
|
// and refs from Static index.
|
2018-10-04 22:20:22 +08:00
|
|
|
class MergedIndex : public SymbolIndex {
|
|
|
|
const SymbolIndex *Dynamic, *Static;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// The constructor does not access the symbols.
|
|
|
|
// It's safe to inherit from this class and pass pointers to derived members.
|
|
|
|
MergedIndex(const SymbolIndex *Dynamic, const SymbolIndex *Static)
|
|
|
|
: Dynamic(Dynamic), Static(Static) {}
|
|
|
|
|
|
|
|
bool fuzzyFind(const FuzzyFindRequest &,
|
|
|
|
llvm::function_ref<void(const Symbol &)>) const override;
|
|
|
|
void lookup(const LookupRequest &,
|
|
|
|
llvm::function_ref<void(const Symbol &)>) const override;
|
|
|
|
void refs(const RefsRequest &,
|
|
|
|
llvm::function_ref<void(const Ref &)>) const override;
|
|
|
|
size_t estimateMemoryUsage() const override {
|
|
|
|
return Dynamic->estimateMemoryUsage() + Static->estimateMemoryUsage();
|
|
|
|
}
|
|
|
|
};
|
2018-01-15 20:33:00 +08:00
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
2018-08-15 00:03:32 +08:00
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
|