Skip to content

Commit a34c9f0

Browse files
author
Valery N Dmitriev
committed
Merge from 'master' to 'sycl-web' (intel#89)
2 parents 17cb38d + fccd29d commit a34c9f0

File tree

260 files changed

+8915
-2240
lines changed

Some content is hidden

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

260 files changed

+8915
-2240
lines changed

clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ namespace change_namespace {
1919

2020
namespace {
2121

22-
inline std::string
23-
joinNamespaces(const llvm::SmallVectorImpl<StringRef> &Namespaces) {
24-
if (Namespaces.empty())
25-
return "";
26-
std::string Result(Namespaces.front());
27-
for (auto I = Namespaces.begin() + 1, E = Namespaces.end(); I != E; ++I)
28-
Result += ("::" + *I).str();
29-
return Result;
22+
inline std::string joinNamespaces(ArrayRef<StringRef> Namespaces) {
23+
return llvm::join(Namespaces, "::");
3024
}
3125

3226
// Given "a::b::c", returns {"a", "b", "c"}.

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ClangdServer {
100100
bool StorePreamblesInMemory = true;
101101
/// Reuse even stale preambles, and rebuild them in the background.
102102
/// This improves latency at the cost of accuracy.
103-
bool AsyncPreambleBuilds = false;
103+
bool AsyncPreambleBuilds = true;
104104

105105
/// If true, ClangdServer builds a dynamic in-memory index for symbols in
106106
/// opened files and uses the index to augment code completion results.

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,47 @@ using llvm::yaml::SequenceNode;
2626

2727
class Parser {
2828
llvm::SourceMgr &SM;
29+
bool HadError = false;
2930

3031
public:
3132
Parser(llvm::SourceMgr &SM) : SM(SM) {}
3233

3334
// Tries to parse N into F, returning false if it failed and we couldn't
34-
// meaningfully recover (e.g. YAML syntax error broke the stream).
35-
// The private parse() helpers follow the same pattern.
35+
// meaningfully recover (YAML syntax error, or hard semantic error).
3636
bool parse(Fragment &F, Node &N) {
3737
DictParser Dict("Config", this);
38-
Dict.handle("If", [&](Node &N) { return parse(F.If, N); });
39-
Dict.handle("CompileFlags",
40-
[&](Node &N) { return parse(F.CompileFlags, N); });
41-
return Dict.parse(N);
38+
Dict.handle("If", [&](Node &N) { parse(F.If, N); });
39+
Dict.handle("CompileFlags", [&](Node &N) { parse(F.CompileFlags, N); });
40+
Dict.parse(N);
41+
return !(N.failed() || HadError);
4242
}
4343

4444
private:
45-
bool parse(Fragment::IfBlock &F, Node &N) {
45+
void parse(Fragment::IfBlock &F, Node &N) {
4646
DictParser Dict("If", this);
4747
Dict.unrecognized(
4848
[&](llvm::StringRef) { F.HasUnrecognizedCondition = true; });
4949
Dict.handle("PathMatch", [&](Node &N) {
5050
if (auto Values = scalarValues(N))
5151
F.PathMatch = std::move(*Values);
52-
return !N.failed();
5352
});
54-
return Dict.parse(N);
53+
Dict.parse(N);
5554
}
5655

57-
bool parse(Fragment::CompileFlagsBlock &F, Node &N) {
56+
void parse(Fragment::CompileFlagsBlock &F, Node &N) {
5857
DictParser Dict("CompileFlags", this);
5958
Dict.handle("Add", [&](Node &N) {
6059
if (auto Values = scalarValues(N))
6160
F.Add = std::move(*Values);
62-
return !N.failed();
6361
});
64-
return Dict.parse(N);
62+
Dict.parse(N);
6563
}
6664

6765
// Helper for parsing mapping nodes (dictionaries).
6866
// We don't use YamlIO as we want to control over unknown keys.
6967
class DictParser {
7068
llvm::StringRef Description;
71-
std::vector<std::pair<llvm::StringRef, std::function<bool(Node &)>>> Keys;
69+
std::vector<std::pair<llvm::StringRef, std::function<void(Node &)>>> Keys;
7270
std::function<void(llvm::StringRef)> Unknown;
7371
Parser *Outer;
7472

@@ -79,7 +77,7 @@ class Parser {
7977
// Parse is called when Key is encountered, and passed the associated value.
8078
// It should emit diagnostics if the value is invalid (e.g. wrong type).
8179
// If Key is seen twice, Parse runs only once and an error is reported.
82-
void handle(llvm::StringLiteral Key, std::function<bool(Node &)> Parse) {
80+
void handle(llvm::StringLiteral Key, std::function<void(Node &)> Parse) {
8381
for (const auto &Entry : Keys) {
8482
(void) Entry;
8583
assert(Entry.first != Key && "duplicate key handler");
@@ -94,16 +92,17 @@ class Parser {
9492
}
9593

9694
// Process a mapping node and call handlers for each key/value pair.
97-
bool parse(Node &N) const {
95+
void parse(Node &N) const {
9896
if (N.getType() != Node::NK_Mapping) {
9997
Outer->error(Description + " should be a dictionary", N);
100-
return false;
98+
return;
10199
}
102100
llvm::SmallSet<std::string, 8> Seen;
101+
// We *must* consume all items, even on error, or the parser will assert.
103102
for (auto &KV : llvm::cast<MappingNode>(N)) {
104103
auto *K = KV.getKey();
105104
if (!K) // YAMLParser emitted an error.
106-
return false;
105+
continue;
107106
auto Key = Outer->scalarValue(*K, "Dictionary key");
108107
if (!Key)
109108
continue;
@@ -113,13 +112,12 @@ class Parser {
113112
}
114113
auto *Value = KV.getValue();
115114
if (!Value) // YAMLParser emitted an error.
116-
return false;
115+
continue;
117116
bool Matched = false;
118117
for (const auto &Handler : Keys) {
119118
if (Handler.first == **Key) {
120-
if (!Handler.second(*Value))
121-
return false;
122119
Matched = true;
120+
Handler.second(*Value);
123121
break;
124122
}
125123
}
@@ -129,7 +127,6 @@ class Parser {
129127
Unknown(**Key);
130128
}
131129
}
132-
return true;
133130
}
134131
};
135132

@@ -154,6 +151,7 @@ class Parser {
154151
} else if (auto *S = llvm::dyn_cast<BlockScalarNode>(&N)) {
155152
Result.emplace_back(S->getValue().str(), N.getSourceRange());
156153
} else if (auto *S = llvm::dyn_cast<SequenceNode>(&N)) {
154+
// We *must* consume all items, even on error, or the parser will assert.
157155
for (auto &Child : *S) {
158156
if (auto Value = scalarValue(Child, "List item"))
159157
Result.push_back(std::move(*Value));
@@ -167,6 +165,7 @@ class Parser {
167165

168166
// Report a "hard" error, reflecting a config file that can never be valid.
169167
void error(const llvm::Twine &Msg, const Node &N) {
168+
HadError = true;
170169
SM.PrintMessage(N.getSourceRange().Start, llvm::SourceMgr::DK_Error, Msg,
171170
N.getSourceRange());
172171
}
@@ -196,7 +195,7 @@ std::vector<Fragment> Fragment::parseYAML(llvm::StringRef YAML,
196195
&Diags);
197196
std::vector<Fragment> Result;
198197
for (auto &Doc : llvm::yaml::Stream(*Buf, *SM)) {
199-
if (Node *N = Doc.parseBlockNode()) {
198+
if (Node *N = Doc.getRoot()) {
200199
Fragment Fragment;
201200
Fragment.Source.Manager = SM;
202201
Fragment.Source.Location = N->getSourceRange().Start;

clang-tools-extra/clangd/TUScheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class TUScheduler {
194194

195195
/// Whether to run PreamblePeer asynchronously.
196196
/// No-op if AsyncThreadsCount is 0.
197-
bool AsyncPreambleBuilds = false;
197+
bool AsyncPreambleBuilds = true;
198198

199199
/// Used to create a context that wraps each single operation.
200200
/// Typically to inject per-file configuration.

clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ llvm::cl::opt<std::string> IndexLocation(
3232
llvm::cl::opt<std::string>
3333
ExecCommand("c", llvm::cl::desc("Command to execute and then exit"));
3434

35+
llvm::cl::opt<std::string> ProjectRoot("project-root",
36+
llvm::cl::desc("Path to the project"));
37+
3538
static constexpr char Overview[] = R"(
3639
This is an **experimental** interactive tool to process user-provided search
3740
queries over given symbol collection obtained via clangd-indexer. The
@@ -326,7 +329,8 @@ struct {
326329

327330
std::unique_ptr<SymbolIndex> openIndex(llvm::StringRef Index) {
328331
return Index.startswith("remote:")
329-
? remote::getClient(Index.drop_front(strlen("remote:")))
332+
? remote::getClient(Index.drop_front(strlen("remote:")),
333+
ProjectRoot)
330334
: loadIndex(Index, /*UseDex=*/true);
331335
}
332336

clang-tools-extra/clangd/index/remote/Client.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
#include "Client.h"
1212
#include "Index.grpc.pb.h"
13+
#include "index/Index.h"
1314
#include "index/Serialization.h"
1415
#include "marshalling/Marshalling.h"
1516
#include "support/Logger.h"
1617
#include "support/Trace.h"
18+
#include "llvm/ADT/StringRef.h"
1719

1820
#include <chrono>
1921

@@ -27,14 +29,24 @@ class IndexClient : public clangd::SymbolIndex {
2729
using StreamingCall = std::unique_ptr<grpc::ClientReader<ReplyT>> (
2830
remote::SymbolIndex::Stub::*)(grpc::ClientContext *, const RequestT &);
2931

32+
template <typename ClangdRequestT, typename RequestT>
33+
RequestT serializeRequest(ClangdRequestT Request) const {
34+
return toProtobuf(Request);
35+
}
36+
37+
template <>
38+
FuzzyFindRequest serializeRequest(clangd::FuzzyFindRequest Request) const {
39+
return toProtobuf(Request, ProjectRoot);
40+
}
41+
3042
template <typename RequestT, typename ReplyT, typename ClangdRequestT,
3143
typename CallbackT>
3244
bool streamRPC(ClangdRequestT Request,
3345
StreamingCall<RequestT, ReplyT> RPCCall,
3446
CallbackT Callback) const {
3547
bool FinalResult = false;
3648
trace::Span Tracer(RequestT::descriptor()->name());
37-
const auto RPCRequest = toProtobuf(Request);
49+
const auto RPCRequest = serializeRequest<ClangdRequestT, RequestT>(Request);
3850
grpc::ClientContext Context;
3951
std::chrono::system_clock::time_point Deadline =
4052
std::chrono::system_clock::now() + DeadlineWaitingTime;
@@ -48,20 +60,21 @@ class IndexClient : public clangd::SymbolIndex {
4860
FinalResult = Reply.final_result();
4961
continue;
5062
}
51-
auto Sym = fromProtobuf(Reply.stream_result(), &Strings);
52-
if (!Sym)
63+
auto Response =
64+
fromProtobuf(Reply.stream_result(), &Strings, ProjectRoot);
65+
if (!Response)
5366
elog("Received invalid {0}", ReplyT::descriptor()->name());
54-
Callback(*Sym);
67+
Callback(*Response);
5568
}
5669
SPAN_ATTACH(Tracer, "status", Reader->Finish().ok());
5770
return FinalResult;
5871
}
5972

6073
public:
6174
IndexClient(
62-
std::shared_ptr<grpc::Channel> Channel,
75+
std::shared_ptr<grpc::Channel> Channel, llvm::StringRef ProjectRoot,
6376
std::chrono::milliseconds DeadlineTime = std::chrono::milliseconds(1000))
64-
: Stub(remote::SymbolIndex::NewStub(Channel)),
77+
: Stub(remote::SymbolIndex::NewStub(Channel)), ProjectRoot(ProjectRoot),
6578
DeadlineWaitingTime(DeadlineTime) {}
6679

6780
void lookup(const clangd::LookupRequest &Request,
@@ -86,22 +99,26 @@ class IndexClient : public clangd::SymbolIndex {
8699
llvm::function_ref<void(const SymbolID &, const clangd::Symbol &)>)
87100
const {}
88101

89-
// IndexClient does not take any space since the data is stored on the server.
102+
// IndexClient does not take any space since the data is stored on the
103+
// server.
90104
size_t estimateMemoryUsage() const { return 0; }
91105

92106
private:
93107
std::unique_ptr<remote::SymbolIndex::Stub> Stub;
108+
std::string ProjectRoot;
94109
// Each request will be terminated if it takes too long.
95110
std::chrono::milliseconds DeadlineWaitingTime;
96111
};
97112

98113
} // namespace
99114

100-
std::unique_ptr<clangd::SymbolIndex> getClient(llvm::StringRef Address) {
115+
std::unique_ptr<clangd::SymbolIndex> getClient(llvm::StringRef Address,
116+
llvm::StringRef ProjectRoot) {
101117
const auto Channel =
102118
grpc::CreateChannel(Address.str(), grpc::InsecureChannelCredentials());
103119
Channel->GetState(true);
104-
return std::unique_ptr<clangd::SymbolIndex>(new IndexClient(Channel));
120+
return std::unique_ptr<clangd::SymbolIndex>(
121+
new IndexClient(Channel, ProjectRoot));
105122
}
106123

107124
} // namespace remote

clang-tools-extra/clangd/index/remote/Client.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_REMOTE_INDEX_H
1111

1212
#include "index/Index.h"
13+
#include "llvm/ADT/StringRef.h"
1314

1415
namespace clang {
1516
namespace clangd {
1617
namespace remote {
1718

1819
/// Returns an SymbolIndex client that passes requests to remote index located
1920
/// at \p Address. The client allows synchronous RPC calls.
21+
/// \p IndexRoot is an absolute path on the local machine to the source tree
22+
/// described by the remote index. Paths returned by the index will be treated
23+
/// as relative to this directory.
2024
///
2125
/// This method attempts to resolve the address and establish the connection.
2226
///
2327
/// \returns nullptr if the address is not resolved during the function call or
2428
/// if the project was compiled without Remote Index support.
25-
std::unique_ptr<clangd::SymbolIndex> getClient(llvm::StringRef Address);
29+
std::unique_ptr<clangd::SymbolIndex> getClient(llvm::StringRef Address,
30+
llvm::StringRef IndexRoot);
2631

2732
} // namespace remote
2833
} // namespace clangd

clang-tools-extra/clangd/index/remote/Index.proto

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ message Symbol {
7171
string name = 3;
7272
SymbolLocation definition = 4;
7373
string scope = 5;
74-
SymbolLocation canonical_declarattion = 6;
74+
SymbolLocation canonical_declaration = 6;
7575
int32 references = 7;
7676
uint32 origin = 8;
7777
string signature = 9;
@@ -99,7 +99,10 @@ message SymbolInfo {
9999
message SymbolLocation {
100100
Position start = 1;
101101
Position end = 2;
102-
string file_uri = 3;
102+
// clangd::SymbolLocation stores FileURI, but the protocol transmits a the
103+
// relative path. Because paths are different on the remote and local machines
104+
// they will be translated in the marshalling layer.
105+
string file_path = 3;
103106
}
104107

105108
message Position {

0 commit comments

Comments
 (0)