Skip to content

Commit 2295e1d

Browse files
committed
Merge from 'master' to 'sycl-web' (#1)
2 parents 99157bb + c858deb commit 2295e1d

File tree

858 files changed

+19687
-9046
lines changed

Some content is hidden

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

858 files changed

+19687
-9046
lines changed

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,12 @@ if(CLANG_INCLUDE_TESTS)
153153
add_subdirectory(test)
154154
add_subdirectory(unittests)
155155
endif()
156+
157+
# FIXME(kirillbobyrev): Document this in the LLVM docs once remote index is stable.
158+
option(CLANGD_ENABLE_REMOTE "Use gRPC library to enable remote index support for Clangd" OFF)
159+
set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual installation.")
160+
161+
if (CLANGD_ENABLE_REMOTE)
162+
include(FindGRPC)
163+
add_subdirectory(index/remote)
164+
endif()

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,7 @@ CompletionItem CodeCompletion::render(const CodeCompleteOptions &Opts) const {
18361836
// is mainly to help LSP clients again, so that changes do not effect each
18371837
// other.
18381838
for (const auto &FixIt : FixIts) {
1839-
if (isRangeConsecutive(FixIt.range, LSP.textEdit->range)) {
1839+
if (FixIt.range.end == LSP.textEdit->range.start) {
18401840
LSP.textEdit->newText = FixIt.newText + LSP.textEdit->newText;
18411841
LSP.textEdit->range.start = FixIt.range.start;
18421842
} else {

clang-tools-extra/clangd/SourceCode.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -240,26 +240,6 @@ bool isValidFileRange(const SourceManager &Mgr, SourceRange R) {
240240
return BeginFID.isValid() && BeginFID == EndFID && BeginOffset <= EndOffset;
241241
}
242242

243-
bool halfOpenRangeContains(const SourceManager &Mgr, SourceRange R,
244-
SourceLocation L) {
245-
assert(isValidFileRange(Mgr, R));
246-
247-
FileID BeginFID;
248-
size_t BeginOffset = 0;
249-
std::tie(BeginFID, BeginOffset) = Mgr.getDecomposedLoc(R.getBegin());
250-
size_t EndOffset = Mgr.getFileOffset(R.getEnd());
251-
252-
FileID LFid;
253-
size_t LOffset;
254-
std::tie(LFid, LOffset) = Mgr.getDecomposedLoc(L);
255-
return BeginFID == LFid && BeginOffset <= LOffset && LOffset < EndOffset;
256-
}
257-
258-
bool halfOpenRangeTouches(const SourceManager &Mgr, SourceRange R,
259-
SourceLocation L) {
260-
return L == R.getEnd() || halfOpenRangeContains(Mgr, R, L);
261-
}
262-
263243
SourceLocation includeHashLoc(FileID IncludedFile, const SourceManager &SM) {
264244
assert(SM.getLocForEndOfFile(IncludedFile).isFileID());
265245
FileID IncludingFile;
@@ -558,11 +538,6 @@ TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M,
558538
return Result;
559539
}
560540

561-
bool isRangeConsecutive(const Range &Left, const Range &Right) {
562-
return Left.end.line == Right.start.line &&
563-
Left.end.character == Right.start.character;
564-
}
565-
566541
FileDigest digest(llvm::StringRef Content) {
567542
uint64_t Hash{llvm::xxHash64(Content)};
568543
FileDigest Result;

clang-tools-extra/clangd/SourceCode.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,6 @@ llvm::Optional<SourceRange> toHalfOpenFileRange(const SourceManager &Mgr,
120120
/// FIXME: introduce a type for source range with this invariant.
121121
bool isValidFileRange(const SourceManager &Mgr, SourceRange R);
122122

123-
/// Returns true iff \p L is contained in \p R.
124-
/// EXPECTS: isValidFileRange(R) == true, L is a file location.
125-
bool halfOpenRangeContains(const SourceManager &Mgr, SourceRange R,
126-
SourceLocation L);
127-
128-
/// Returns true iff \p L is contained in \p R or \p L is equal to the end point
129-
/// of \p R.
130-
/// EXPECTS: isValidFileRange(R) == true, L is a file location.
131-
bool halfOpenRangeTouches(const SourceManager &Mgr, SourceRange R,
132-
SourceLocation L);
133-
134123
/// Returns the source code covered by the source range.
135124
/// EXPECTS: isValidFileRange(R) == true.
136125
llvm::StringRef toSourceCode(const SourceManager &SM, SourceRange R);
@@ -171,8 +160,6 @@ TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M,
171160
llvm::Optional<std::string> getCanonicalPath(const FileEntry *F,
172161
const SourceManager &SourceMgr);
173162

174-
bool isRangeConsecutive(const Range &Left, const Range &Right);
175-
176163
/// Choose the clang-format style we should apply to a certain file.
177164
/// This will usually use FS to look for .clang-format directories.
178165
/// FIXME: should we be caching the .clang-format file search?

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ FileShardedIndex::FileShardedIndex(IndexFileIn Input, PathRef HintPath)
174174
// not have been indexed, see SymbolCollector::processRelations for details.
175175
if (Index.Relations) {
176176
for (const auto &R : *Index.Relations) {
177-
auto *File = SymbolIDToFile.lookup(R.Subject);
178-
assert(File && "unknown subject in relation");
179-
File->Relations.insert(&R);
177+
// FIXME: RelationSlab shouldn't contain dangling relations.
178+
if (auto *File = SymbolIDToFile.lookup(R.Subject))
179+
File->Relations.insert(&R);
180180
}
181181
}
182182
// Store only the direct includes of a file in a shard.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generate_grpc_protos(RemoteIndexProtos "Index.proto")
2+
3+
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
4+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
5+
6+
add_subdirectory(client)
7+
add_subdirectory(server)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===--- Index.proto - Remote index Protocol Buffers definition -----------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
syntax = "proto3";
10+
11+
package clang.clangd.remote;
12+
13+
service Index {
14+
rpc Lookup(LookupRequest) returns (stream LookupReply) {}
15+
}
16+
17+
message LookupRequest { string id = 1; }
18+
19+
message LookupReply { string symbol_yaml = 1; }
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Clangd remote index
2+
3+
Clangd uses a global index for project-wide code completion, navigation and
4+
other features. For large projects, building this can take many hours and
5+
keeping it loaded uses a lot of memory.
6+
7+
To relieve that burden, we're building remote index &mdash; a global index
8+
served on a different machine and shared between developers. This directory
9+
contains code that is used as Proof of Concept for the upcoming remote index
10+
feature.
11+
12+
## Building
13+
14+
This feature uses gRPC and Protobuf libraries, so you will need to install them.
15+
There are two ways of doing that.
16+
17+
However you install dependencies, to enable this feature and build remote index
18+
tools you will need to set this CMake flag &mdash; `-DCLANGD_ENABLE_REMOTE=On`.
19+
20+
### System-installed libraries
21+
22+
On Debian-like systems gRPC and Protobuf can be installed from apt:
23+
24+
```bash
25+
apt install libgrpc++-dev libprotobuf-dev protobuf-compiler protobuf-compiler-grpc
26+
```
27+
28+
### Building from sources
29+
30+
Another way of installing gRPC and Protobuf is building from sources using
31+
CMake. The easiest way of doing that would be to choose a directory where you
32+
want to install so that the installation files are not copied to system root and
33+
you can uninstall gRPC or use different versions of the library.
34+
35+
```bash
36+
# Get source code.
37+
$ git clone -b v1.28.1 https://github.com/grpc/grpc
38+
$ cd grpc
39+
$ git submodule update --init
40+
# Choose directory where you want gRPC installation to live.
41+
$ export GRPC_INSTALL_PATH=/where/you/want/grpc/to/be/installed
42+
# Build and install gRPC to ${GRPC_INSTALL_PATH}
43+
$ mkdir build; cd build
44+
$ cmake -DgRPC_INSTALL=ON -DCMAKE_INSTALL_PREFIX=${GRPC_INSTALL_PATH} -DCMAKE_BUILD_TYPE=Release ..
45+
$ make install
46+
```
47+
48+
This [guide](https://github.com/grpc/grpc/blob/master/BUILDING.md) goes into
49+
more detail on how to build gRPC from sources.
50+
51+
By default, CMake will look for system-installed libraries when building remote
52+
index tools so you will have to adjust LLVM's CMake invocation. The following
53+
flag will inform build system that you chose this option &mdash;
54+
`-DGRPC_INSTALL_PATH=${GRPC_INSTALL_PATH}`.
55+
56+
## Running
57+
58+
The remote index isn't usable with Clangd yet, but you can try the
59+
proof-of-concept tools in `client/` and `server/` subdirectories.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
set(LLVM_LINK_COMPONENTS
2+
LineEditor
3+
Support
4+
)
5+
add_clang_executable(clangd-index-client
6+
Client.cpp
7+
)
8+
target_compile_definitions(clangd-index-client PRIVATE -DGOOGLE_PROTOBUF_NO_RTTI=1)
9+
clang_target_link_libraries(clangd-index-client
10+
PRIVATE
11+
clangDaemon
12+
)
13+
target_link_libraries(clangd-index-client
14+
PRIVATE
15+
RemoteIndexProtos
16+
17+
protobuf
18+
grpc++
19+
)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===--- Client.cpp - Remote Index Client -----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file implements a simple interactive tool which can be used to manually
10+
// evaluate symbol search quality of Clangd index.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "SourceCode.h"
15+
#include "index/Serialization.h"
16+
#include "index/dex/Dex.h"
17+
#include "llvm/ADT/ScopeExit.h"
18+
#include "llvm/ADT/SmallVector.h"
19+
#include "llvm/ADT/StringRef.h"
20+
#include "llvm/ADT/StringSwitch.h"
21+
#include "llvm/LineEditor/LineEditor.h"
22+
#include "llvm/Support/CommandLine.h"
23+
#include "llvm/Support/Signals.h"
24+
25+
#include "grpcpp/grpcpp.h"
26+
27+
#include "Index.grpc.pb.h"
28+
29+
namespace clang {
30+
namespace clangd {
31+
namespace {
32+
33+
llvm::cl::opt<std::string>
34+
ServerAddress("server-address",
35+
llvm::cl::desc("Address of remote index server to use."),
36+
llvm::cl::init("0.0.0.0:50051"));
37+
38+
static const std::string Overview = R"(
39+
This is an **experimental** interactive tool to process user-provided search
40+
queries over given symbol collection obtained via clangd-indexer with the help
41+
of remote index server. The client will connect to remote index server and pass
42+
it lookup queries.
43+
)";
44+
45+
class RemoteIndexClient {
46+
public:
47+
RemoteIndexClient(std::shared_ptr<grpc::Channel> Channel)
48+
: Stub(remote::Index::NewStub(Channel)) {}
49+
50+
void lookup(llvm::StringRef ID) {
51+
llvm::outs() << "Lookup of symbol with ID " << ID << '\n';
52+
remote::LookupRequest Proto;
53+
Proto.set_id(ID.str());
54+
55+
grpc::ClientContext Context;
56+
remote::LookupReply Reply;
57+
std::unique_ptr<grpc::ClientReader<remote::LookupReply>> Reader(
58+
Stub->Lookup(&Context, Proto));
59+
while (Reader->Read(&Reply)) {
60+
llvm::outs() << Reply.symbol_yaml();
61+
}
62+
grpc::Status Status = Reader->Finish();
63+
if (Status.ok()) {
64+
llvm::outs() << "lookupRequest rpc succeeded.\n";
65+
} else {
66+
llvm::outs() << "lookupRequest rpc failed.\n";
67+
}
68+
}
69+
70+
private:
71+
std::unique_ptr<remote::Index::Stub> Stub;
72+
};
73+
74+
} // namespace
75+
} // namespace clangd
76+
} // namespace clang
77+
78+
int main(int argc, const char *argv[]) {
79+
using namespace clang::clangd;
80+
81+
llvm::cl::ParseCommandLineOptions(argc, argv, Overview);
82+
llvm::cl::ResetCommandLineParser(); // We reuse it for REPL commands.
83+
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
84+
85+
RemoteIndexClient IndexClient(
86+
grpc::CreateChannel(ServerAddress, grpc::InsecureChannelCredentials()));
87+
88+
llvm::LineEditor LE("remote-index-client");
89+
while (llvm::Optional<std::string> Request = LE.readLine())
90+
IndexClient.lookup(std::move(*Request));
91+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(LLVM_LINK_COMPONENTS
2+
LineEditor
3+
Support
4+
)
5+
add_clang_executable(clangd-index-server
6+
Server.cpp
7+
)
8+
target_compile_definitions(clangd-index-server PRIVATE -DGOOGLE_PROTOBUF_NO_RTTI=1)
9+
clang_target_link_libraries(clangd-index-server
10+
PRIVATE
11+
clangDaemon
12+
)
13+
target_link_libraries(clangd-index-server
14+
PRIVATE
15+
RemoteIndexProtos
16+
17+
protobuf
18+
grpc++
19+
clangDaemon
20+
)

0 commit comments

Comments
 (0)