Commit Graph

3658 Commits

Author SHA1 Message Date
Sam McCall 47feb57bb6 [clangd] Avoid enum class+enumValN to avoid GCC bug(?), and use consistent style.
llvm-svn: 341459
2018-09-05 10:39:58 +00:00
Sam McCall d445f17614 [clangd] Implement findReferences function
clangd will use findReferences to provide LSP's reference feature.

llvm-svn: 341458
2018-09-05 10:33:36 +00:00
Fangrui Song 445bdd171f [clangd] Fix typo. NFC
llvm-svn: 341452
2018-09-05 08:01:37 +00:00
Sam McCall d85264bf53 [clangd] Fix buildbot failures on older compilers from r341375
llvm-svn: 341451
2018-09-05 07:52:49 +00:00
Eric Liu f592d281a7 [clangd] Tune macro quality scoring for code completion.
x0.2 seems to be too much penalty, macros might be wanted in some cases;
changing to 0.5x instead. The tuning didn't affect ranking for non-macro
completions.

llvm-svn: 341449
2018-09-05 07:40:38 +00:00
Sam McCall 76c4c3af52 [clangd] Load static index asynchronously, add tracing.
Summary:
Like D51475 but simplified based on recent patches.
While here, clarify that loadIndex() takes a filename, not file content.

Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51638

llvm-svn: 341376
2018-09-04 16:19:40 +00:00
Sam McCall 50f3631057 [clangd] Define a compact binary serialization fomat for symbol slab/index.
Summary:
This is intended to replace the current YAML format for general use.
It's ~10x more compact than YAML, and ~40% more compact than gzipped YAML:
  llvmidx.riff = 20M, llvmidx.yaml = 272M, llvmidx.yaml.gz = 32M
It's also simpler/faster to read and write.

The format is a RIFF container (chunks of (type, size, data)) with:
 - a compressed string table
 - simple binary encoding of symbols (with varints for compactness)
It can be extended to include occurrences, Dex posting lists, etc.

There's no rich backwards-compatibility scheme, but a version number is included
so we can detect incompatible files and do ad-hoc back-compat.

Alternatives considered:
 - compressed YAML or JSON: bulky and slow to load
 - llvm bitstream: confusing model and libraries are hard to use. My attempt
   produced slightly larger files, and the code was longer and slower.
 - protobuf or similar: would be really nice (esp for back-compat) but the
   dependency is a big hassle
 - ad-hoc binary format without a container: it seems clear we're going
   to add posting lists and occurrences here, and that they will benefit
   from sharing a string table. The container makes it easy to debug
   these pieces in isolation, and make them optional.

Reviewers: ioeric

Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51585

llvm-svn: 341375
2018-09-04 16:16:50 +00:00
Kirill Bobyrev cc8b507a60 [clangd] NFC: Change quality type to float
Reviewed by: sammccall

Differential Revision: https://reviews.llvm.org/D51636

llvm-svn: 341374
2018-09-04 15:45:56 +00:00
Kirill Bobyrev d5bc65444c [clangd] Move buildStaticIndex() to SymbolYAML
`buildStaticIndex()` is used by two other tools that I'm building, now
it's useful outside of `tool/ClangdMain.cpp`.

Also, slightly refactor the code while moving it to the different source
file.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D51626

llvm-svn: 341369
2018-09-04 15:10:40 +00:00
Sam McCall b0138317d6 [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 14:39:56 +00:00
Simon Pilgrim 9875ae48e4 Remove lambda default parameter to silence -Wpedantic warning. NFCI.
llvm-svn: 341362
2018-09-04 12:17:10 +00:00
Sam McCall dd4a24c86c [clangd] Fix index-twice regression from r341242
llvm-svn: 341337
2018-09-03 20:26:26 +00:00
Sam McCall 046557bc03 [clangd] Some nitpicking around the new split (preamble/main) dynamic index
Summary:
- DynamicIndex doesn't implement ParsingCallbacks, to make its role clearer.
  ParsingCallbacks is a separate object owned by the receiving TUScheduler.
  (I tried to get rid of the "index-like-object that doesn't implement index"
  but it was too messy).
- Clarified(?) docs around DynamicIndex - fewer details up front, more details
  inside.
- Exposed dynamic index from ClangdServer for memory monitoring and more
  direct testing of its contents (actual tests not added here, wanted to get
  this out for review)
- Removed a redundant and sligthly confusing filename param in a callback

Reviewers: ilya-biryukov

Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51221

llvm-svn: 341325
2018-09-03 16:37:59 +00:00
Ilya Biryukov 5a79d1e377 [clangd] Avoid crashes in override completions
Summary: NamedDecl::getName cannot be called on non-identifier names.

Reviewers: kadircet, ioeric, hokein, sammccall

Reviewed By: ioeric

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51598

llvm-svn: 341322
2018-09-03 15:25:27 +00:00
Sam McCall b466e11c39 [clangd] Fix ambiguous make_unique with c++17. NFC
llvm-svn: 341321
2018-09-03 15:23:01 +00:00
Ilya Biryukov d9fe7538a3 [clangd] Handle errors before checking for cancelltion
To avoid hitting assertions in llvm::Expected destructor.

llvm-svn: 341319
2018-09-03 14:39:34 +00:00
Sam McCall 9c7624e14b [clangd] Factor out the data-swapping functionality from MemIndex/DexIndex.
Summary:
This is now handled by a wrapper class SwapIndex, so MemIndex/DexIndex can be
immutable and focus on their job.

Old and busted:
 I have a MemIndex, which holds a shared_ptr<vector<Symbol*>>, which keeps the
 symbol slab alive. I update by calling build(shared_ptr<vector<Symbol*>>).

New hotness: I have a SwapIndex, which holds a unique_ptr<SymbolIndex>, which
 holds a MemIndex, which holds a shared_ptr<void>, which keeps backing
 data alive.
 I update by building a new MemIndex and calling SwapIndex::reset().

Reviewers: kbobyrev, ioeric

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51422

llvm-svn: 341318
2018-09-03 14:37:43 +00:00
Eric Liu 83f63e42b2 [clangd] Support multiple #include headers in one symbol.
Summary:
Currently, a symbol can have only one #include header attached, which
might not work well if the symbol can be imported via different #includes depending
on where it's used. This patch stores multiple #include headers (with # references)
for each symbol, so that CodeCompletion can decide which include to insert.

In this patch, code completion simply picks the most popular include as the default inserted header. We also return all possible includes and their edits in the `CodeCompletion` results.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: mgrang, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51291

llvm-svn: 341304
2018-09-03 10:18:21 +00:00
Fangrui Song 399943bc76 [clangd] Fix many typos. NFC
llvm-svn: 341273
2018-09-01 07:47:03 +00:00
Haojian Wu e8064b6f6d [clangd] Implement findOccurrences interface in dynamic index.
Summary:
Implement the interface in
  - FileIndex
  - MemIndex
  - MergeIndex

Depends on https://reviews.llvm.org/D50385.

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

Subscribers: mgrang, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51279

llvm-svn: 341242
2018-08-31 19:53:37 +00:00
Sam McCall 2e5700f038 [clangd] Flatten out Symbol::Details. It was ill-conceived, sorry.
Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51504

llvm-svn: 341211
2018-08-31 13:55:01 +00:00
Haojian Wu d81e3146e3 [clangd] Collect symbol occurrences in SymbolCollector.
SymbolCollector will be used for two cases:
 - collect Symbol type only, used for indexing preamble AST.
 - collect Symbol and SymbolOccurrences, used for indexing main AST.

For finding local references from the AST, we will implement it in other ways.

llvm-svn: 341208
2018-08-31 12:54:13 +00:00
Kirill Bobyrev 493b1627ca [NFC] Cleanup Dex
* Use consistent assertion messages in iterators implementations
* Silence a bunch of clang-tidy warnings: use `emplace_back` instead of
  `push_back` where possible, make sure arguments have the same name in
  header and implementation file, use for loop over ranges where possible

Reviewed by: ioeric

Differential Revision: https://reviews.llvm.org/D51528

llvm-svn: 341190
2018-08-31 09:17:02 +00:00
Kirill Bobyrev c38b3f0308 NFC: Fix build failure after rL341182
Didn't rename another variable reference.

llvm-svn: 341184
2018-08-31 08:29:48 +00:00
Kirill Bobyrev c1bb7b9ec4 [NFC] Use LLVM naming conventions within FileDistance
Reviewed by: sammccall

Differential Revision: https://reviews.llvm.org/D51527

llvm-svn: 341182
2018-08-31 08:19:50 +00:00
Argyrios Kyrtzidis 2b6ec65696 [clang-move] Explicitly ignore implicit UsingDirectiveDecls instead of depending on them missing source locations
This is adjustment to allow the logic to work even if implicit UsingDirectiveDecls get actual source locations.
There should be no functionality change.

llvm-svn: 341161
2018-08-31 03:51:33 +00:00
Fangrui Song 8810f3319c Import lit.llvm after rL341130
llvm-svn: 341152
2018-08-31 00:26:46 +00:00
Stephen Kelly 7cbfd8bb2f Add preload option to clang-query
Summary: This allows loading a file with pre-defined let commands for example.

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D51261

llvm-svn: 341145
2018-08-30 23:25:44 +00:00
Stephen Kelly 7dfed0b22c Extract runCommandsInFile method
Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D51260

llvm-svn: 341144
2018-08-30 23:25:38 +00:00
Nico Weber b737d4d560 Remove LIT_SITE_CFG_IN_FOOTER, clang-tools-extra
It's always replaced with the same (short) static string, so just put that
there directly.

No intended behavior change.
https://reviews.llvm.org/D51357

llvm-svn: 341130
2018-08-30 22:10:13 +00:00
Sam McCall e6ce8da025 [clangd] Run SignatureHelp using an up-to-date preamble, waiting if needed.
Summary:
After code completion inserts a header, running signature help using the old
preamble will usually fail. So we add support for consistent preamble reads.

Reviewers: ilya-biryukov

Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51438

llvm-svn: 341076
2018-08-30 15:07:34 +00:00
Kirill Bobyrev a2f146fd9c [clangd] Remove UB introduced in rL341057
llvm-svn: 341066
2018-08-30 13:30:34 +00:00
Ilya Biryukov 43c292c6d9 [clangd] Report position of opening paren in singature help
Summary: Only accessible via the C++ API at the moment.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51437

llvm-svn: 341065
2018-08-30 13:14:31 +00:00
Kirill Bobyrev 29925890d9 [clang-tidy] Use simple string matching instead of Regex
Instead of parsing and compiling the `llvm::Regex` each time, it's
faster to use basic string matching for filename prefix check.

Reviewed by: hokein

Differential Revision: https://reviews.llvm.org/D51360

llvm-svn: 341061
2018-08-30 12:42:19 +00:00
Kirill Bobyrev bf3bc7117e [clangd] Fix tests after rL341057
Since OR iterator children are not longer sorted by the estimated size,
string representation should be different.

llvm-svn: 341060
2018-08-30 12:29:36 +00:00
Kirill Bobyrev 38bdac5db8 [clangd] Implement iterator cost
This patch introduces iterator cost concept to improve the performance
of Dex query iterators (mainly, AND iterator). Benchmarks show that the
queries become ~10% faster.

Before

```
-------------------------------------------------------
Benchmark                Time           CPU Iteration
-------------------------------------------------------
DexAdHocQueries    5883074 ns    5883018 ns        117
DexRealQ         959904457 ns  959898507 ns          1
```

After

```
-------------------------------------------------------
Benchmark                Time           CPU Iteration
-------------------------------------------------------
DexAdHocQueries    5238403 ns    5238361 ns        130
DexRealQ         873275207 ns  873269453 ns          1
```

Reviewed by: sammccall

Differential Revision: https://reviews.llvm.org/D51310

llvm-svn: 341057
2018-08-30 11:23:58 +00:00
Jonas Toth 5c0f66b1fe [clang-tidy] fix check_clang_tidy to forbid mixing of CHECK-NOTES and CHECK-MESSAGES
Summary:
The check_clang_tidy.py script would allow mixing of `CHECK-NOTES` and `CHECK-MESSAGES` but running `FileCheck` for that would implicitly fail, because `CHECK-NOTES` bails out if there is a warning.

That means a clang-tidy test can not mix these constructs to check warnings with `CHECK-MESSAGES` and notes with `CHECK-NOTES`. The script gives now a clear error if that happens.

Reviewers: alexfh, aaron.ballman, lebedev.ri, hokein

Reviewed By: lebedev.ri

Subscribers: xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D51381

llvm-svn: 341039
2018-08-30 08:44:27 +00:00
Jonas Toth 51aadb463e [clang-tidy] Add abseil-no-internal-dependencies check
Finds instances where the user depends on internal details and warns them against doing so.
Should not be run on internal Abseil files or Abseil source code.

Patch by hugoeg!

Differential Revision: https://reviews.llvm.org/D50542

llvm-svn: 340928
2018-08-29 14:23:15 +00:00
Aaron Ballman ca5f775dbe Introduce the abseil-redundant-strcat-calls check.
This flags redundant calls to absl::StrCat where the result is being passed to another call to absl::StrCat or absl::StrAppend. Patch by Hugo Gonzalez and Samuel Benzaquen.

llvm-svn: 340918
2018-08-29 11:29:07 +00:00
Aaron Ballman a22d24a36c Introduce the abseil-str-cat-append check.
This flags uses of absl::StrCat when absl::StrAppend should be used instead. Patch by Hugo Gonzalez and Benjamin Kramer.

llvm-svn: 340915
2018-08-29 11:17:31 +00:00
Kirill Bobyrev 8212eae996 [clangd] Switch to Dex by default for the static index
Dex is now mature enough to be used as the default static index. This
patch performs the switch but introduces a hidden flag to allow users
fallback to Mem in case something happens.

Reviewed by: ioeric

Differential Revision: https://reviews.llvm.org/D51352

llvm-svn: 340828
2018-08-28 14:55:05 +00:00
Eric Liu 4e4e5a4e8a [clangd] Use buffered llvm::errs() in the clangd binary.
Summary: Unbuffered stream can cause significant (non-deterministic) latency for the logger.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D51349

llvm-svn: 340822
2018-08-28 13:15:50 +00:00
Ilya Biryukov 8f3b3df5f8 [clangd] Remove unused parameter. NFC
llvm-svn: 340816
2018-08-28 11:04:07 +00:00
Ilya Biryukov c572dae405 [clangd] Add some trace::Spans. NFC
llvm-svn: 340815
2018-08-28 10:57:45 +00:00
Haojian Wu d2f7b04d1b [clang-tidy] Abseil: no namepsace check
This check ensures that users of Abseil do not open namespace absl in their code, as that violates our compatibility guidelines.

AbseilMatcher.h written by Hugo Gonzalez.

Patch by Deanna Garcia!

llvm-svn: 340800
2018-08-28 07:48:28 +00:00
Kirill Bobyrev e6d5fd818f Cleanup after rL340729
llvm-svn: 340759
2018-08-27 17:26:43 +00:00
Kirill Bobyrev 5bda3fad00 [docs] Mention clangd-dev in clangd documentation
Since the clangd-dev is intended to be the place for clangd-related
discussions, we should point new users to this mailing list while
probably mentioning cfe-dev, too.

Reviewed by: ioeric

Differential Revision: https://reviews.llvm.org/D51293

llvm-svn: 340749
2018-08-27 15:38:49 +00:00
Kirill Bobyrev b217ddb1bb [clangd] Use TRUE iterator instead of complete posting list
Stop using `$$$` (empty) trigram and generating a posting list with all
items. Since TRUE iterator is already implemented and correctly inserted
when there are no real trigram posting lists, this is a valid
transformation.

Benchmarks show that this simple change allows ~30% speedup on dataset
of real completion queries.

Before

```
-------------------------------------------------------
Benchmark                Time           CPU Iterations
-------------------------------------------------------
DexAdHocQueries    5640321 ns    5640265 ns        120
DexRealQ         939835603 ns  939830296 ns          1
```

After

```
-------------------------------------------------------
Benchmark                Time           CPU Iterations
-------------------------------------------------------
DexAdHocQueries    3452014 ns    3451987 ns        203
DexRealQ         667455912 ns  667455750 ns          1
```

Reviewed by: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D51287

llvm-svn: 340729
2018-08-27 09:47:50 +00:00
Julie Hockett b8ff56c726 [clang-doc] Fix memory leaks
Adds a virtual destructor to the base Info class.

Differential Revision: https://reviews.llvm.org/D51137

llvm-svn: 340620
2018-08-24 16:43:46 +00:00
Kadir Cetinkaya 689bf93b2f [clangd] Initial cancellation mechanism for LSP requests.
Reviewers: ilya-biryukov, ioeric, hokein

Reviewed By: ilya-biryukov

Subscribers: mgorny, ioeric, MaskRay, jkorous, arphaman, jfb, cfe-commits

Differential Revision: https://reviews.llvm.org/D50502

llvm-svn: 340607
2018-08-24 13:09:41 +00:00