2017-12-14 19:25:49 +08:00
|
|
|
//===--- MemIndex.h - Dynamic in-memory symbol index. -------------- C++-*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
|
|
|
|
|
|
|
|
#include "Index.h"
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
|
|
|
/// \brief This implements an index for a (relatively small) set of symbols that
|
|
|
|
/// can be easily managed in memory.
|
|
|
|
class MemIndex : public SymbolIndex {
|
|
|
|
public:
|
|
|
|
/// \brief (Re-)Build index for `Symbols`. All symbol pointers must remain
|
|
|
|
/// accessible as long as `Symbols` is kept alive.
|
|
|
|
void build(std::shared_ptr<std::vector<const Symbol *>> Symbols);
|
|
|
|
|
2018-01-10 22:44:34 +08:00
|
|
|
/// \brief Build index from a symbol slab.
|
|
|
|
static std::unique_ptr<SymbolIndex> build(SymbolSlab Slab);
|
|
|
|
|
2017-12-28 22:47:01 +08:00
|
|
|
bool
|
[clangd] Pass Context implicitly using TLS.
Summary:
Instead of passing Context explicitly around, we now have a thread-local
Context object `Context::current()` which is an implicit argument to
every function.
Most manipulation of this should use the WithContextValue helper, which
augments the current Context to add a single KV pair, and restores the
old context on destruction.
Advantages are:
- less boilerplate in functions that just propagate contexts
- reading most code doesn't require understanding context at all, and
using context as values in fewer places still
- fewer options to pass the "wrong" context when it changes within a
scope (e.g. when using Span)
- contexts pass through interfaces we can't modify, such as VFS
- propagating contexts across threads was slightly tricky (e.g.
copy vs move, no move-init in lambdas), and is now encapsulated in
the threadpool
Disadvantages are all the usual TLS stuff - hidden magic, and
potential for higher memory usage on threads that don't use the
context. (In practice, it's just one pointer)
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D42517
llvm-svn: 323872
2018-01-31 21:40:48 +08:00
|
|
|
fuzzyFind(const FuzzyFindRequest &Req,
|
2017-12-28 22:47:01 +08:00
|
|
|
llvm::function_ref<void(const Symbol &)> Callback) const override;
|
2017-12-14 19:25:49 +08:00
|
|
|
|
2018-03-14 17:48:05 +08:00
|
|
|
virtual void
|
|
|
|
lookup(const LookupRequest &Req,
|
|
|
|
llvm::function_ref<void(const Symbol &)> Callback) const override;
|
|
|
|
|
2017-12-14 19:25:49 +08:00
|
|
|
private:
|
|
|
|
std::shared_ptr<std::vector<const Symbol *>> Symbols;
|
|
|
|
// Index is a set of symbols that are deduplicated by symbol IDs.
|
|
|
|
// FIXME: build smarter index structure.
|
|
|
|
llvm::DenseMap<SymbolID, const Symbol *> Index;
|
|
|
|
mutable std::mutex Mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MEMINDEX_H
|