Commit Graph

3689 Commits

Author SHA1 Message Date
Shuai Wang 5066ab369d Revert "Revert "[clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer""
This is the same as D50619 plus fixes for buildbot failures on windows.
The test failures on windows are caused by -fdelayed-template-parsing
and is fixed by forcing -fno-delayed-template-parsing on test cases that
requires AST for uninstantiated templates.

llvm-svn: 341891
2018-09-11 02:23:35 +00:00
Shuai Wang cec7d3a055 Revert "[clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer"
Summary:
Tests somehow break on windows (and only on windows)
http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/13003
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/13747

I have yet figure out why so reverting to unbreak first.

Reviewers: george.karpenkov

Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits

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

llvm-svn: 341886
2018-09-10 23:58:04 +00:00
Roman Lebedev a3dc9484e3 [clang-tidy] ExprMutationAnalyzer: construct from references. Fixes PR38888
Summary:
I have hit this the rough way, while trying to use this in D51870.

There is no particular point in storing the pointers, and moreover
the pointers are assumed to be non-null, and that assumption is not
enforced. If they are null, it won't be able to do anything good
with them anyway.

Initially i thought about simply adding asserts() that they are
not null, but taking/storing references looks like even cleaner solution?

Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=38888 | PR38888 ]]

Reviewers: JonasToth, shuaiwang, alexfh, george.karpenkov

Reviewed By: shuaiwang

Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 341854
2018-09-10 19:59:18 +00:00
Shuai Wang bef0941b6b [clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer
Summary:
- If a function is unresolved, assume it mutates its arguments
- Follow unresolved member expressions for nested mutations

Reviewers: aaron.ballman, JonasToth, george.karpenkov

Subscribers: xazax.hun, a.sidorin, cfe-commits

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

llvm-svn: 341848
2018-09-10 18:05:13 +00:00
Kirill Bobyrev 5faf8a3d84 [clangd] Unbreak buildbots after r341802
Solution: use std::move when returning result from toJSON(...).
llvm-svn: 341832
2018-09-10 14:31:38 +00:00
Kadir Cetinkaya 0b77d03d80 [clangd] Add unittests for D51038
Reviewers: ilya-biryukov, ioeric, hokein

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

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

llvm-svn: 341830
2018-09-10 14:22:42 +00:00
Kirill Bobyrev 09f00dcf69 [clangd] Implement FuzzyFindRequest JSON (de)serialization
JSON (de)serialization of `FuzzyFindRequest` might be useful for both
D51090 and D51628. Also, this allows precise logging of the fuzzy find
requests.

Reviewed By: sammccall

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

llvm-svn: 341802
2018-09-10 11:51:05 +00:00
Kirill Bobyrev 38a889c185 [clangd] Add symbol slab size to index memory consumption estimates
Currently, `SymbolIndex::estimateMemoryUsage()` returns the "overhead"
estimate, i.e. the estimate of the Index data structure excluding
backing data (such as Symbol Slab and Reference Slab). This patch
propagates information about paired data size where necessary.

Reviewed By: ioeric, sammccall

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

llvm-svn: 341800
2018-09-10 11:46:07 +00:00
Sam McCall f469c64fef [clangd] Fix async index loading (from r341376).
Summary:
This wasn't actually async (due to std::future destructor blocking).
If it were, we would have clean shutdown issues if main returned
and destroyed Placeholder before the thread is done with it.

We could attempt to avoid any blocking by using shared_ptr or weak_ptr tricks so
the thread can detect Placeholder's destruction, but there are other potential
issues (e.g. loadIndex does tracing, and we'll destroy the tracer...)
Instead, once LSPServer::run returns, we wait for the index to finish loading
before exiting. Performance is not critical in this situation.

Reviewers: ilya-biryukov

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

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

llvm-svn: 341797
2018-09-10 10:00:47 +00:00
Hans Wennborg a2585a12d8 ReleaseNotes: update links to use https
llvm-svn: 341787
2018-09-10 08:52:04 +00:00
Kirill Bobyrev 5abe478a3d [clangd] NFC: Rename DexIndex to Dex
Also, cleanup some redundant includes.

Reviewed By: sammccall

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

llvm-svn: 341784
2018-09-10 08:23:53 +00:00
Kirill Bobyrev 59491a1fa9 [clangd] Make advanceTo() faster on Posting Lists
If the current element is already beyond advanceTo()'s DocID, just
return instead of doing binary search. This simple optimization saves up
to 6-7% performance,

Reviewed By: ilya-biryukov

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

llvm-svn: 341781
2018-09-10 07:57:28 +00:00
Ben Hamilton 8e261351b4 [clang-tidy/ObjC] Update list of acronyms in PropertyDeclarationCheck
Summary: This adds a few common acronyms we found were missing from PropertyDeclarationCheck.

Reviewers: Wizard, hokein

Reviewed By: hokein

Subscribers: cfe-commits

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

llvm-svn: 341721
2018-09-07 22:03:48 +00:00
Ben Hamilton 2f0a1286f3 [clang-tidy/ObjC] Update list of acronyms in PropertyDeclarationCheck
Summary: This adds a few common acronyms we found were missing from PropertyDeclarationCheck.

Reviewers: Wizard, hokein

Subscribers: cfe-commits

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

llvm-svn: 341720
2018-09-07 22:02:38 +00:00
Eric Liu f76886859f [clangd] Canonicalize include paths in clangd.
Get rid of "../"  and "../../".

llvm-svn: 341645
2018-09-07 09:40:36 +00:00
Benjamin Kramer 14dd35c30b [clang-tidy] Abseil: Allow macros inside of absl to use internal absl things
llvm-svn: 341643
2018-09-07 09:25:23 +00:00
Kirill Bobyrev e5536b972f [clangd] NFC: Document URIDistance
`URIDistance` constructor should mention that `Sources` must contain
*absolute paths*, not URIs. This is not very clear when looking at the
interface, especially given that `distance(...)` accepts `URI`, not an
absolute path which can give the wrong impression.

Reviewed By: sammccall

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

llvm-svn: 341639
2018-09-07 09:18:58 +00:00
Stephen Kelly 9b11da91c7 Fix reported range of partial token replacement
Summary: Fixes bug: 38678

Reviewers: klimek, rsmith

Subscribers: cfe-commits

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

llvm-svn: 341583
2018-09-06 20:16:34 +00:00
Eric Liu 6df66001ee [clangd] Add "Deprecated" field to Symbol and CodeCompletion.
Summary: Also set "deprecated" field in LSP CompletionItem.

Reviewers: sammccall, kadircet

Reviewed By: sammccall

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

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

llvm-svn: 341576
2018-09-06 18:52:26 +00:00
Kirill Bobyrev 049b2d4345 [clangd] Fix Dex initialization
This patch sets URI schemes of Dex to SymbolCollector's default schemes
in case callers tried to pass empty list of schemes. This was the case
for initialization in Clangd main and was a reason of incorrect
behavior.

Also, it fixes a bug with missed `continue;` after spotting invalid URI
scheme conversion.

llvm-svn: 341552
2018-09-06 15:10:10 +00:00
Kirill Bobyrev afbf31854d [clangd] NFC: Use TopN instead of std::priority_queue
Quality.cpp defines a structure for convenient storage of Top N items,
it should be used instead of the `std::priority_queue` with slightly
obscure semantics.

This patch does not affect functionality.

Reviewed By: sammccall

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

llvm-svn: 341544
2018-09-06 13:15:03 +00:00
Kirill Bobyrev e4ee0213d4 [clangd] NFC: mark single-parameter constructors explicit
Code health: prevent implicit conversions to user-defined types.

Reviewed By: sammccall

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

llvm-svn: 341543
2018-09-06 13:06:04 +00:00
Kirill Bobyrev 19a9461e5f [clangd] Implement proximity path boosting for Dex
This patch introduces `PathURI` Search Token kind and utilizes it to
uprank symbols which are defined in files with small distance to the
directory where the fuzzy find request is coming from (e.g. files user
is editing).

Reviewed By: ioeric

Reviewers: ioeric, sammccall

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

llvm-svn: 341542
2018-09-06 12:54:43 +00:00
Ilya Biryukov 5c4d6e66f0 [clangd] Fix data race in async fuzzyFind tests.
llvm-svn: 341538
2018-09-06 11:04:56 +00:00
Eric Liu d25f1214a8 [clangd] Set SymbolID for sema macros so that they can be merged with index macros.
Reviewers: sammccall

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

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

llvm-svn: 341534
2018-09-06 09:59:37 +00:00
Eric Liu d2eb03aec8 [clang-tidy] minor bug fix to AbseilMatcher.h
This missing directory is not yet released, but is causing some problems
internally. It's gonna be released eventually and received permission to
include it here. This matcher will also be periodically updated by my
team as we have more releases and or problems internally.

Patch by Hugo Gonzalez!

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

llvm-svn: 341488
2018-09-05 19:01:34 +00:00
Sam McCall ce2498a4c1 [clangd] Fix type/variable name conflict on some compilers
llvm-svn: 341467
2018-09-05 13:22:11 +00:00
Sam McCall c54dd0a731 [clangd] Fix references.test assertions
llvm-svn: 341466
2018-09-05 13:17:51 +00:00
Sam McCall e4fa7b8418 [clangd] make zlib compression optional for binary format
llvm-svn: 341465
2018-09-05 13:17:47 +00:00
Haojian Wu 53e91c1b08 [clangd] Sort GoToDefinition results.
Summary:
GoToDefinition returns all declaration results (implicit/explicit) that are
in the same location, and the results are returned in arbitrary order.

Some LSP clients defaultly take the first result as the final result, which
might present a bad result (implicit decl) to users.

This patch ranks the result based on whether the declarations are
referenced explicitly/implicitly. We put explicit declarations first.

This also improves the "hover" (which just take the first result) feature
in some cases.

Reviewers: ilya-biryukov

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

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

llvm-svn: 341463
2018-09-05 12:00:15 +00:00
Sam McCall 1ad142fe26 [clangd] Add xrefs LSP boilerplate implementation.
Reviewers: ilya-biryukov, ioeric

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

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

llvm-svn: 341462
2018-09-05 11:53:07 +00:00
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