[clang-tools-extra] r339665 - [clangd] Show non-instantiated decls in signatureHelp

2018-08-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Aug 14 02:36:32 2018
New Revision: 339665

URL: http://llvm.org/viewvc/llvm-project?rev=339665&view=rev
Log:
[clangd] Show non-instantiated decls in signatureHelp

Summary:
To avoid producing very verbose output in substitutions involving
typedefs, e.g.
  T -> std::vector::iterator
gets turned into an unreadable mess when printed out for libstdc++,
result contains internal types (std::__Vector_iterator<...>) and
expanded well-defined typedefs (std::basic_string).

Until we improve the presentation code in clang, going with
non-instantiated decls looks like a better UX trade-off.

Reviewers: hokein, ioeric, kadircet

Reviewed By: hokein

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=339665&r1=339664&r2=339665&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Aug 14 02:36:32 2018
@@ -714,7 +714,15 @@ public:
"too many arguments");
 SigHelp.activeParameter = static_cast(CurrentArg);
 for (unsigned I = 0; I < NumCandidates; ++I) {
-  const auto &Candidate = Candidates[I];
+  OverloadCandidate Candidate = Candidates[I];
+  // We want to avoid showing instantiated signatures, because they may be
+  // long in some cases (e.g. when 'T' is substituted with 'std::string', 
we
+  // would get 'std::basic_string').
+  if (auto *Func = Candidate.getFunction()) {
+if (auto *Pattern = Func->getTemplateInstantiationPattern())
+  Candidate = OverloadCandidate(Pattern);
+  }
+
   const auto *CCS = Candidate.CreateSignatureString(
   CurrentArg, S, *Allocator, CCTUInfo, true);
   assert(CCS && "Expected the CodeCompletionString to be non-null");

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=339665&r1=339664&r2=339665&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Tue Aug 14 
02:36:32 2018
@@ -1537,6 +1537,59 @@ TEST(SignatureHelpTest, OverloadsOrderin
   EXPECT_EQ(0, Results.activeParameter);
 }
 
+TEST(SignatureHelpTest, InstantiatedSignatures) {
+  EXPECT_THAT(signatures(R"cpp(
+template 
+void foo(T, T, T);
+
+int main() {
+  foo(^);
+}
+  )cpp")
+  .signatures,
+  ElementsAre(Sig("foo(T, T, T) -> void", {"T", "T", "T"})));
+
+  EXPECT_THAT(signatures(R"cpp(
+template 
+void foo(T, T, T);
+
+int main() {
+  foo(10, ^);
+})cpp")
+  .signatures,
+  ElementsAre(Sig("foo(T, T, T) -> void", {"T", "T", "T"})));
+
+  EXPECT_THAT(signatures(R"cpp(
+template 
+void foo(T...);
+
+int main() {
+  foo(^);
+}
+  )cpp")
+  .signatures,
+  ElementsAre(Sig("foo(T...) -> void", {"T..."})));
+
+  // It is debatable whether we should substitute the outer template parameter
+  // ('T') in that case. Currently we don't substitute it in signature help, 
but
+  // do substitute in code complete.
+  // FIXME: make code complete and signature help consistent, figure out which
+  // way is better.
+  EXPECT_THAT(signatures(R"cpp(
+template 
+struct X {
+  template 
+  void foo(T, U);
+};
+
+int main() {
+  X().foo(^)
+}
+  )cpp")
+  .signatures,
+  ElementsAre(Sig("foo(T, U) -> void", {"T", "U"})));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r340004 - [clangd] Show function documentation in signature help

2018-08-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Aug 17 02:29:38 2018
New Revision: 340004

URL: http://llvm.org/viewvc/llvm-project?rev=340004&view=rev
Log:
[clangd] Show function documentation in signature help

Summary:
Previously, clangd was trying to show documentation for the active
parameter instead, which is wrong per LSP specification.

Moreover, the code path that attempts to get parameter comments never
succeds, because no attempt is made to parse function doc comment and
extract parameter-specific parts out of it. So we also remove the code
that claims to fetch parameter comments: it is not used anymore and is
incorrect.

Reviewers: hokein, ioeric, kadircet

Reviewed By: ioeric

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.h

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=340004&r1=340003&r2=340004&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Aug 17 02:29:38 2018
@@ -729,8 +729,9 @@ public:
   // FIXME: for headers, we need to get a comment from the index.
   ScoredSignatures.push_back(processOverloadCandidate(
   Candidate, *CCS,
-  getParameterDocComment(S.getASTContext(), Candidate, CurrentArg,
- /*CommentsFromHeaders=*/false)));
+  Candidate.getFunction()
+  ? getDeclComment(S.getASTContext(), *Candidate.getFunction())
+  : ""));
 }
 std::sort(ScoredSignatures.begin(), ScoredSignatures.end(),
   [](const ScoredSignature &L, const ScoredSignature &R) {

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=340004&r1=340003&r2=340004&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Fri Aug 17 
02:29:38 2018
@@ -51,44 +51,26 @@ std::string getDocComment(const ASTConte
   // get this declaration, so we don't show documentation in that case.
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
 return "";
-  auto *Decl = Result.getDeclaration();
-  if (!Decl || llvm::isa(Decl)) {
+  return Result.getDeclaration() ? getDeclComment(Ctx, 
*Result.getDeclaration())
+ : "";
+}
+
+std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
+  if (llvm::isa(Decl)) {
 // Namespaces often have too many redecls for any particular redecl comment
 // to be useful. Moreover, we often confuse file headers or generated
 // comments with namespace comments. Therefore we choose to just ignore
 // the comments for namespaces.
 return "";
   }
-  const RawComment *RC = getCompletionComment(Ctx, Decl);
-  if (!RC)
-return "";
-
-  // Sanity check that the comment does not come from the PCH. We choose to not
-  // write them into PCH, because they are racy and slow to load.
-  assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
-  std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), 
Ctx.getDiagnostics());
-  if (!looksLikeDocComment(Doc))
-return "";
-  return Doc;
-}
-
-std::string
-getParameterDocComment(const ASTContext &Ctx,
-   const CodeCompleteConsumer::OverloadCandidate &Result,
-   unsigned ArgIndex, bool CommentsFromHeaders) {
-  auto *Func = Result.getFunction();
-  if (!Func)
-return "";
-  const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex);
+  const RawComment *RC = getCompletionComment(Ctx, &Decl);
   if (!RC)
 return "";
   // Sanity check that the comment does not come from the PCH. We choose to not
   // write them into PCH, because they are racy and slow to load.
   assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
   std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), 
Ctx.getDiagnostics());
-  if (!looksLikeDocComment(Doc))
-return "";
-  return Doc;
+  return looksLikeDocComment(Doc) ? Doc : "";
 }
 
 void getSignature(const CodeCompletionString &CCS, std::string *Signature,

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.h?rev=340004&r1=340003&r2=340004&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeCompletionStri

[clang-tools-extra] r340005 - [clangd] Fetch documentation from the Index during signature help

2018-08-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Aug 17 02:32:30 2018
New Revision: 340005

URL: http://llvm.org/viewvc/llvm-project?rev=340005&view=rev
Log:
[clangd] Fetch documentation from the Index during signature help

Summary:
Sema can only be used for documentation in the current file, other doc
comments should be fetched from the index.

Reviewers: hokein, ioeric, kadircet

Reviewed By: hokein, kadircet

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

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=340005&r1=340004&r2=340005&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Aug 17 02:32:30 2018
@@ -177,15 +177,16 @@ void ClangdServer::signatureHelp(PathRef
 
   auto PCHs = this->PCHs;
   auto FS = FSProvider.getFileSystem();
-  auto Action = [Pos, FS, PCHs](Path File, Callback CB,
-llvm::Expected IP) {
+  auto *Index = this->Index;
+  auto Action = [Pos, FS, PCHs, Index](Path File, Callback CB,
+   llvm::Expected IP) {
 if (!IP)
   return CB(IP.takeError());
 
 auto PreambleData = IP->Preamble;
 CB(clangd::signatureHelp(File, IP->Command,
  PreambleData ? &PreambleData->Preamble : nullptr,
- IP->Contents, Pos, FS, PCHs));
+ IP->Contents, Pos, FS, PCHs, Index));
   };
 
   WorkScheduler.runWithPreamble("SignatureHelp", File,

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=340005&r1=340004&r2=340005&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Aug 17 02:32:30 2018
@@ -687,18 +687,23 @@ private:
   llvm::unique_function ResultsCallback;
 };
 
-using ScoredSignature =
-std::pair;
+struct ScoredSignature {
+  // When set, requires documentation to be requested from the index with this
+  // ID.
+  llvm::Optional IDForDoc;
+  SignatureInformation Signature;
+  SignatureQualitySignals Quality;
+};
 
 class SignatureHelpCollector final : public CodeCompleteConsumer {
-
 public:
   SignatureHelpCollector(const clang::CodeCompleteOptions &CodeCompleteOpts,
- SignatureHelp &SigHelp)
-  : CodeCompleteConsumer(CodeCompleteOpts, /*OutputIsBinary=*/false),
+ SymbolIndex *Index, SignatureHelp &SigHelp)
+  : CodeCompleteConsumer(CodeCompleteOpts,
+ /*OutputIsBinary=*/false),
 SigHelp(SigHelp),
 Allocator(std::make_shared()),
-CCTUInfo(Allocator) {}
+CCTUInfo(Allocator), Index(Index) {}
 
   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
@@ -726,47 +731,74 @@ public:
   const auto *CCS = Candidate.CreateSignatureString(
   CurrentArg, S, *Allocator, CCTUInfo, true);
   assert(CCS && "Expected the CodeCompletionString to be non-null");
-  // FIXME: for headers, we need to get a comment from the index.
   ScoredSignatures.push_back(processOverloadCandidate(
   Candidate, *CCS,
   Candidate.getFunction()
   ? getDeclComment(S.getASTContext(), *Candidate.getFunction())
   : ""));
 }
-std::sort(ScoredSignatures.begin(), ScoredSignatures.end(),
-  [](const ScoredSignature &L, const ScoredSignature &R) {
-// Ordering follows:
-// - Less number of parameters is better.
-// - Function is better than FunctionType which is better than
-// Function Template.
-// - High score is better.
-// - Shorter signature is better.
-// - Alphebatically smaller is better.
-if (L.first.NumberOfParameters != R.first.NumberOfParameters)
-  return L.first.NumberOfParameters <
- R.first.NumberOfParameters;
-if (L.first.NumberOfOptionalParameters !=
-R.first.NumberOfOptionalParameters)
-  return L.first.NumberOfOptionalParameters <
- R.first.NumberOfOptionalParameters;
-if (L.first.Kind != R.first.Kind) {
-  using OC = CodeCompleteConsum

[clang-tools-extra] r340401 - [clangd] Add callbacks on parsed AST in addition to parsed preambles

2018-08-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Aug 22 04:39:16 2018
New Revision: 340401

URL: http://llvm.org/viewvc/llvm-project?rev=340401&view=rev
Log:
[clangd] Add callbacks on parsed AST in addition to parsed preambles

Summary:
Will be used for updating the dynamic index on updates to the open files.
Currently we collect only information coming from the preamble
AST. This has a bunch of limitations:
  - Dynamic index misses important information from the body of the
file, e.g. locations of definitions.
  - XRefs cannot be collected at all, since we can only obtain full
information for the current file (preamble is parsed with skipped
function bodies, therefore not reliable).

This patch only adds the new callback, actually updates to the index
will be done in a follow-up patch.

Reviewers: hokein

Reviewed By: hokein

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

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=340401&r1=340400&r2=340401&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Aug 22 04:39:16 2018
@@ -66,6 +66,24 @@ public:
   Optional> Result;
 };
 
+class UpdateFileIndex : public ParsingCallbacks {
+public:
+  UpdateFileIndex(FileIndex *FileIdx) : FileIdx(FileIdx) {}
+
+  void onPreambleAST(PathRef Path, ASTContext &Ctx,
+ std::shared_ptr PP) override {
+if (FileIdx)
+  FileIdx->update(Path, &Ctx, std::move(PP));
+  }
+
+  void onMainAST(PathRef Path, ParsedAST &AST) override {
+// FIXME: merge results from the main file into the index too.
+  }
+
+private:
+  FileIndex *FileIdx;
+};
+
 } // namespace
 
 ClangdServer::Options ClangdServer::optsForTest() {
@@ -85,20 +103,16 @@ ClangdServer::ClangdServer(GlobalCompila
: getStandardResourceDir()),
   FileIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex(Opts.URISchemes)
: nullptr),
+  FileIdxUpdater(llvm::make_unique(FileIdx.get())),
   PCHs(std::make_shared()),
   // Pass a callback into `WorkScheduler` to extract symbols from a newly
   // parsed file and rebuild the file index synchronously each time an AST
   // is parsed.
   // FIXME(ioeric): this can be slow and we may be able to index on less
   // critical paths.
-  WorkScheduler(
-  Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
-  FileIdx
-  ? [this](PathRef Path, ASTContext &AST,
-   std::shared_ptr
-   PP) { FileIdx->update(Path, &AST, std::move(PP)); }
-  : PreambleParsedCallback(),
-  Opts.UpdateDebounce, Opts.RetentionPolicy) {
+  WorkScheduler(Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
+*FileIdxUpdater, Opts.UpdateDebounce,
+Opts.RetentionPolicy) {
   if (FileIdx && Opts.StaticIndex) {
 MergedIndex = mergeIndex(FileIdx.get(), Opts.StaticIndex);
 Index = MergedIndex.get();

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=340401&r1=340400&r2=340401&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Aug 22 04:39:16 2018
@@ -223,6 +223,8 @@ private:
   SymbolIndex *Index;
   // If present, an up-to-date of symbols in open files. Read via Index.
   std::unique_ptr FileIdx;
+  /// Callbacks responsible for updating FileIdx.
+  std::unique_ptr FileIdxUpdater;
   // If present, a merged view of FileIdx and an external index. Read via 
Index.
   std::unique_ptr MergedIndex;
   // If set, this represents the workspace path.

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=340401&r1=340400&r2=340401&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Wed Aug 22 04:39:16 2018
@@ -158,8 +158,7 @@ class ASTWorker {
 Semaphore &Barrier, bool RunSync,
 steady_clock::duration UpdateDebounce,
 std::shared_ptr PCHs,
-bool StorePreamb

[clang-tools-extra] r340404 - [clangd] Make FileIndex aware of the main file

2018-08-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Aug 22 05:43:17 2018
New Revision: 340404

URL: http://llvm.org/viewvc/llvm-project?rev=340404&view=rev
Log:
[clangd] Make FileIndex aware of the main file

Summary:
It was previously only indexing the preamble decls. The new
implementation will index both the preamble and the main AST and
report both sets of symbols, preferring the ones from the main AST
whenever the symbol is present in both.
The symbols in the main AST slab always store all information
available in the preamble symbols, possibly adding more,
e.g. definition locations.

Reviewers: hokein, ioeric

Reviewed By: ioeric

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

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=340404&r1=340403&r2=340404&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Aug 22 05:43:17 2018
@@ -65,27 +65,39 @@ public:
 
   Optional> Result;
 };
+} // namespace
 
-class UpdateFileIndex : public ParsingCallbacks {
+/// Manages dynamic index for open files. Each file might contribute two sets
+/// of symbols to the dynamic index: symbols from the preamble and symbols
+/// from the file itself. Those have different lifetimes and we merge results
+/// from both
+class ClangdServer::DynamicIndex : public ParsingCallbacks {
 public:
-  UpdateFileIndex(FileIndex *FileIdx) : FileIdx(FileIdx) {}
+  DynamicIndex(std::vector URISchemes)
+  : PreambleIdx(URISchemes), MainFileIdx(URISchemes),
+MergedIndex(mergeIndex(&MainFileIdx, &PreambleIdx)) {}
+
+  SymbolIndex &index() const { return *MergedIndex; }
 
   void onPreambleAST(PathRef Path, ASTContext &Ctx,
  std::shared_ptr PP) override {
-if (FileIdx)
-  FileIdx->update(Path, &Ctx, std::move(PP));
+PreambleIdx.update(Path, &Ctx, PP, /*TopLevelDecls=*/llvm::None);
   }
 
   void onMainAST(PathRef Path, ParsedAST &AST) override {
-// FIXME: merge results from the main file into the index too.
+
+MainFileIdx.update(Path, &AST.getASTContext(), AST.getPreprocessorPtr(),
+   AST.getLocalTopLevelDecls());
   }
 
 private:
-  FileIndex *FileIdx;
+  FileIndex PreambleIdx;
+  FileIndex MainFileIdx;
+  /// Merged view into both indexes. Merges are performed in a similar manner
+  /// to the merges of dynamic and static index.
+  std::unique_ptr MergedIndex;
 };
 
-} // namespace
-
 ClangdServer::Options ClangdServer::optsForTest() {
   ClangdServer::Options Opts;
   Opts.UpdateDebounce = std::chrono::steady_clock::duration::zero(); // Faster!
@@ -101,9 +113,9 @@ ClangdServer::ClangdServer(GlobalCompila
 : CDB(CDB), DiagConsumer(DiagConsumer), FSProvider(FSProvider),
   ResourceDir(Opts.ResourceDir ? Opts.ResourceDir->str()
: getStandardResourceDir()),
-  FileIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex(Opts.URISchemes)
-   : nullptr),
-  FileIdxUpdater(llvm::make_unique(FileIdx.get())),
+  DynamicIdx(Opts.BuildDynamicSymbolIndex
+ ? new DynamicIndex(Opts.URISchemes)
+ : nullptr),
   PCHs(std::make_shared()),
   // Pass a callback into `WorkScheduler` to extract symbols from a newly
   // parsed file and rebuild the file index synchronously each time an AST
@@ -111,19 +123,23 @@ ClangdServer::ClangdServer(GlobalCompila
   // FIXME(ioeric): this can be slow and we may be able to index on less
   // critical paths.
   WorkScheduler(Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
-*FileIdxUpdater, Opts.UpdateDebounce,
-Opts.RetentionPolicy) {
-  if (FileIdx && Opts.StaticIndex) {
-MergedIndex = mergeIndex(FileIdx.get(), Opts.StaticIndex);
+DynamicIdx ? *DynamicIdx : noopParsingCallbacks(),
+Opts.UpdateDebounce, Opts.RetentionPolicy) {
+  if (DynamicIdx && Opts.StaticIndex) {
+MergedIndex = mergeIndex(&DynamicIdx->index(), Opts.StaticIndex);
 Index = MergedIndex.get();
-  } else if (FileIdx)
-Index = FileIdx.get();
+  } else if (DynamicIdx)
+Index = &DynamicIdx->index();
   else if (Opts.StaticIndex)
 Index = Opts.StaticIndex;
   else
 Index = nullptr;
 }
 
+// Destructor has to be in .cpp file to see the definition of
+// ClangdServer::DynamicIndex.
+ClangdServer::~ClangdServer() = default;
+
 void ClangdServer::setRootPath(PathRef RootPath) {
   auto FS = FSProvider.getFileSystem();

[clang-tools-extra] r340410 - [clangd] Get rid of regexes in CanonicalIncludes

2018-08-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Aug 22 06:51:19 2018
New Revision: 340410

URL: http://llvm.org/viewvc/llvm-project?rev=340410&view=rev
Log:
[clangd] Get rid of regexes in CanonicalIncludes

Summary: Replace them with suffix mappings.

Reviewers: ioeric, kbobyrev

Reviewed By: ioeric

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

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

Modified:
clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp
clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h

Modified: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=340410&r1=340409&r2=340410&view=diff
==
--- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp Wed Aug 22 
06:51:19 2018
@@ -10,7 +10,8 @@
 #include "CanonicalIncludes.h"
 #include "../Headers.h"
 #include "clang/Driver/Types.h"
-#include "llvm/Support/Regex.h"
+#include "llvm/Support/Path.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -18,15 +19,17 @@ namespace {
 const char IWYUPragma[] = "// IWYU pragma: private, include ";
 } // namespace
 
-void CanonicalIncludes::addMapping(llvm::StringRef Path,
-   llvm::StringRef CanonicalPath) {
-  addRegexMapping((llvm::Twine("^") + llvm::Regex::escape(Path) + "$").str(),
-  CanonicalPath);
+void CanonicalIncludes::addPathSuffixMapping(llvm::StringRef Suffix,
+ llvm::StringRef CanonicalPath) {
+  int Components = std::distance(llvm::sys::path::begin(Suffix),
+ llvm::sys::path::end(Suffix));
+  MaxSuffixComponents = std::max(MaxSuffixComponents, Components);
+  SuffixHeaderMapping[Suffix] = CanonicalPath;
 }
 
-void CanonicalIncludes::addRegexMapping(llvm::StringRef RE,
-llvm::StringRef CanonicalPath) {
-  this->RegexHeaderMappingTable.emplace_back(llvm::Regex(RE), CanonicalPath);
+void CanonicalIncludes::addMapping(llvm::StringRef Path,
+   llvm::StringRef CanonicalPath) {
+  FullPathMapping[Path] = CanonicalPath;
 }
 
 void CanonicalIncludes::addSymbolMapping(llvm::StringRef QualifiedName,
@@ -41,7 +44,6 @@ CanonicalIncludes::mapHeader(llvm::Array
   auto SE = SymbolMapping.find(QualifiedName);
   if (SE != SymbolMapping.end())
 return SE->second;
-  std::lock_guard Lock(RegexMutex);
   // Find the first header such that the extension is not '.inc', and isn't a
   // recognized non-header file
   auto I =
@@ -62,13 +64,19 @@ CanonicalIncludes::mapHeader(llvm::Array
   if ((ExtType != driver::types::TY_INVALID) &&
   !driver::types::onlyPrecompileType(ExtType))
 return Headers[0];
-  for (auto &Entry : RegexHeaderMappingTable) {
-#ifndef NDEBUG
-std::string Dummy;
-assert(Entry.first.isValid(Dummy) && "Regex should never be invalid!");
-#endif
-if (Entry.first.match(Header))
-  return Entry.second;
+
+  auto MapIt = FullPathMapping.find(Header);
+  if (MapIt != FullPathMapping.end())
+return MapIt->second;
+
+  int Components = 1;
+  for (auto It = llvm::sys::path::rbegin(Header),
+End = llvm::sys::path::rend(Header);
+   It != End && Components <= MaxSuffixComponents; ++It, ++Components) {
+auto SubPath = Header.substr(It->data() - Header.begin());
+auto MappingIt = SuffixHeaderMapping.find(SubPath);
+if (MappingIt != SuffixHeaderMapping.end())
+  return MappingIt->second;
   }
   return Header;
 }
@@ -153,660 +161,660 @@ void addSystemHeadersMapping(CanonicalIn
 
   static const std::vector>
   SystemHeaderMap = {
-  {"include/__stddef_max_align_t.h$", ""},
-  {"include/__wmmintrin_aes.h$", ""},
-  {"include/__wmmintrin_pclmul.h$", ""},
-  {"include/adxintrin.h$", ""},
-  {"include/ammintrin.h$", ""},
-  {"include/avx2intrin.h$", ""},
-  {"include/avx512bwintrin.h$", ""},
-  {"include/avx512cdintrin.h$", ""},
-  {"include/avx512dqintrin.h$", ""},
-  {"include/avx512erintrin.h$", ""},
-  {"include/avx512fintrin.h$", ""},
-  {"include/avx512ifmaintrin.h$", ""},
-  {"include/avx512ifmavlintrin.h$", ""},
-  {"include/avx512pfintrin.h$", ""},
-  {"include/avx512vbmiintrin.h$", ""},
-  {"include/avx512vbmivlintrin.h$", ""},
-  {"include/avx512vlbwintrin.h$", ""},
-  {"include/avx512vlcdintrin.h$", ""},
-  {"include/avx512vldqintrin.h$", ""},
-  {"include/avx512vlintrin.h$", ""},
-  {"include/avxintrin.h$", ""},
-  {"include/bmi2intrin.h$", ""},
-  {"include/bmiintrin.h$", ""},
-  {"include/emmintrin.h$", ""},
-  {"include/f16cintrin.h$", ""},
-

[clang-tools-extra] r340523 - [clangd] Increase the timeouts in TUScheduler tests to 10 seconds.

2018-08-23 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Aug 23 03:25:07 2018
New Revision: 340523

URL: http://llvm.org/viewvc/llvm-project?rev=340523&view=rev
Log:
[clangd] Increase the timeouts in TUScheduler tests to 10 seconds.

Some of them timeout on our buildbots in certain configurations.
The timeouts are there to avoid hanging indefinitely on deadlocks, so
the exact number we put there does not matter.

Modified:
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp?rev=340523&r1=340522&r2=340523&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp Thu Aug 23 
03:25:07 2018
@@ -278,7 +278,7 @@ TEST_F(TUSchedulerTests, EvictedAST) {
   // one that the cache will evict.
   S.update(Foo, getInputs(Foo, SourceContents), WantDiagnostics::Yes,
[&BuiltASTCounter](std::vector Diags) { ++BuiltASTCounter; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   ASSERT_EQ(BuiltASTCounter.load(), 1);
 
   // Build two more files. Since we can retain only 2 ASTs, these should be the
@@ -287,7 +287,7 @@ TEST_F(TUSchedulerTests, EvictedAST) {
[&BuiltASTCounter](std::vector Diags) { ++BuiltASTCounter; });
   S.update(Baz, getInputs(Baz, SourceContents), WantDiagnostics::Yes,
[&BuiltASTCounter](std::vector Diags) { ++BuiltASTCounter; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   ASSERT_EQ(BuiltASTCounter.load(), 3);
 
   // Check only the last two ASTs are retained.
@@ -296,7 +296,7 @@ TEST_F(TUSchedulerTests, EvictedAST) {
   // Access the old file again.
   S.update(Foo, getInputs(Foo, OtherSourceContents), WantDiagnostics::Yes,
[&BuiltASTCounter](std::vector Diags) { ++BuiltASTCounter; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   ASSERT_EQ(BuiltASTCounter.load(), 4);
 
   // Check the AST for foo.cpp is retained now and one of the others got
@@ -333,13 +333,13 @@ TEST_F(TUSchedulerTests, EmptyPreamble)
 0u);
 });
   // Wait for the preamble is being built.
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
 
   // Update the file which results in an empty preamble.
   S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto,
[](std::vector) {});
   // Wait for the preamble is being built.
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   S.runWithPreamble("getEmptyPreamble", Foo,
 [&](llvm::Expected Preamble) {
   // We expect to get an empty preamble.
@@ -409,7 +409,7 @@ TEST_F(TUSchedulerTests, NoopOnEmptyChan
 Updated = false;
 S.update(Source, std::move(Inputs), WantDiagnostics::Yes,
  [&Updated](std::vector) { Updated = true; });
-bool UpdateFinished = S.blockUntilIdle(timeoutSeconds(1));
+bool UpdateFinished = S.blockUntilIdle(timeoutSeconds(10));
 if (!UpdateFinished)
   ADD_FAILURE() << "Updated has not finished in one second. Threading 
bug?";
 return Updated;
@@ -454,14 +454,14 @@ TEST_F(TUSchedulerTests, NoChangeDiags)
 // Make sure the AST was actually built.
 cantFail(std::move(IA));
   });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
 
   // Even though the inputs didn't change and AST can be reused, we need to
   // report the diagnostics, as they were not reported previously.
   std::atomic SeenDiags(false);
   S.update(FooCpp, getInputs(FooCpp, Contents), WantDiagnostics::Auto,
[&](std::vector) { SeenDiags = true; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   ASSERT_TRUE(SeenDiags);
 
   // Subsequent request does not get any diagnostics callback because the same
@@ -469,7 +469,7 @@ TEST_F(TUSchedulerTests, NoChangeDiags)
   S.update(
   FooCpp, getInputs(FooCpp, Contents), WantDiagnostics::Auto,
   [&](std::vector) { ADD_FAILURE() << "Should not be called."; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
 }
 
 } // namespace


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r332226 - [clangd] Don't query index when completing inside classes

2018-05-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 14 03:50:04 2018
New Revision: 332226

URL: http://llvm.org/viewvc/llvm-project?rev=332226&view=rev
Log:
[clangd] Don't query index when completing inside classes

Summary:
We used to query the index when completing after class qualifiers,
e.g. 'ClassName::^'. We should not do that for the same reasons we
don't query the index for member access expressions.

Reviewers: sammccall, ioeric

Reviewed By: sammccall

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332226&r1=332225&r2=332226&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon May 14 03:50:04 2018
@@ -759,9 +759,9 @@ bool semaCodeComplete(std::unique_ptrgetScopeRep();
+  if (!NameSpec)
+return true;
+  // We only query the index when qualifier is a namespace.
+  // If it's a class, we rely solely on sema completions.
+  switch (NameSpec->getKind()) {
+  case NestedNameSpecifier::Global:
+  case NestedNameSpecifier::Namespace:
+  case NestedNameSpecifier::NamespaceAlias:
+return true;
+  case NestedNameSpecifier::Super:
+  case NestedNameSpecifier::TypeSpec:
+  case NestedNameSpecifier::TypeSpecWithTemplate:
+  // Unresolved inside a template.
+  case NestedNameSpecifier::Identifier:
+return false;
+  }
+}
+
 } // namespace
 
 clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const {
@@ -918,7 +945,7 @@ private:
   }
 
   SymbolSlab queryIndex() {
-if (!Opts.Index || !allowIndex(Recorder->CCContext.getKind()))
+if (!Opts.Index || !allowIndex(Recorder->CCContext))
   return SymbolSlab();
 trace::Span Tracer("Query index");
 SPAN_ATTACH(Tracer, "limit", Opts.Limit);

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=332226&r1=332225&r2=332226&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon May 14 
03:50:04 2018
@@ -825,6 +825,67 @@ TEST(CompletionTest, GlobalQualifiedQuer
   UnorderedElementsAre("";
 }
 
+TEST(CompletionTest, NoIndexCompletionsInsideClasses) {
+  auto Completions = completions(
+  R"cpp(
+struct Foo {
+  int SomeNameOfField;
+  typedef int SomeNameOfTypedefField;
+};
+
+Foo::^)cpp",
+  {func("::SomeNameInTheIndex"), func("::Foo::SomeNameInTheIndex")});
+
+  EXPECT_THAT(Completions.items,
+  AllOf(Contains(Labeled("SomeNameOfField")),
+Contains(Labeled("SomeNameOfTypedefField")),
+Not(Contains(Labeled("SomeNameInTheIndex");
+}
+
+TEST(CompletionTest, NoIndexCompletionsInsideDependentCode) {
+  {
+auto Completions = completions(
+R"cpp(
+  template 
+  void foo() {
+T::^
+  }
+  )cpp",
+{func("::SomeNameInTheIndex")});
+
+EXPECT_THAT(Completions.items,
+Not(Contains(Labeled("SomeNameInTheIndex";
+  }
+
+  {
+auto Completions = completions(
+R"cpp(
+  template 
+  void foo() {
+T::template Y::^
+  }
+  )cpp",
+{func("::SomeNameInTheIndex")});
+
+EXPECT_THAT(Completions.items,
+Not(Contains(Labeled("SomeNameInTheIndex";
+  }
+
+  {
+auto Completions = completions(
+R"cpp(
+  template 
+  void foo() {
+T::foo::^
+  }
+  )cpp",
+{func("::SomeNameInTheIndex")});
+
+EXPECT_THAT(Completions.items,
+Not(Contains(Labeled("SomeNameInTheIndex";
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r332233 - [clangd] Fix warning after fully covered enum switch. NFC.

2018-05-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 14 04:47:30 2018
New Revision: 332233

URL: http://llvm.org/viewvc/llvm-project?rev=332233&view=rev
Log:
[clangd] Fix warning after fully covered enum switch. NFC.

By adding llvm_unreachable.

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332233&r1=332232&r2=332233&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon May 14 04:47:30 2018
@@ -828,6 +828,7 @@ bool allowIndex(CodeCompletionContext &C
   case NestedNameSpecifier::Identifier:
 return false;
   }
+  llvm_unreachable("invalid NestedNameSpecifier kind");
 }
 
 } // namespace


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r332244 - [CodeComplete] Provide completion in decls even for incomplete types

2018-05-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 14 06:50:36 2018
New Revision: 332244

URL: http://llvm.org/viewvc/llvm-project?rev=332244&view=rev
Log:
[CodeComplete] Provide completion in decls even for incomplete types

Summary:
This change fixes lack of completions in the following case
('^'designates completion points) :

void f(^);
struct Incomplete;
Incomplete g(^);

Reviewers: bkramer, aaron.ballman, sammccall

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeCompletion/incomplete-ret-type.cpp
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=332244&r1=332243&r2=332244&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon May 14 06:50:36 2018
@@ -4493,10 +4493,8 @@ void Sema::CodeCompleteConstructor(Scope
 return;
 
   // A complete type is needed to lookup for constructors.
-  if (!isCompleteType(Loc, Type))
-return;
-
-  CXXRecordDecl *RD = Type->getAsCXXRecordDecl();
+  CXXRecordDecl *RD =
+  isCompleteType(Loc, Type) ? Type->getAsCXXRecordDecl() : nullptr;
   if (!RD) {
 CodeCompleteExpression(S, Type);
 return;

Added: cfe/trunk/test/CodeCompletion/incomplete-ret-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/incomplete-ret-type.cpp?rev=332244&view=auto
==
--- cfe/trunk/test/CodeCompletion/incomplete-ret-type.cpp (added)
+++ cfe/trunk/test/CodeCompletion/incomplete-ret-type.cpp Mon May 14 06:50:36 
2018
@@ -0,0 +1,13 @@
+struct IncompleteType;
+int int_value;
+typedef int int_typedef;
+
+void f(in);
+IncompleteType g(in);
+// Completing should produce results even if types are incomplete.
+// Note that clang is expected to return an error code since 'in' does not 
resolve.
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:5:9 %s -o - | 
FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:6:19 %s -o - | 
FileCheck %s
+// CHECK: COMPLETION: int{{$}}
+// CHECK: COMPLETION: int_typedef
+// CHECK: COMPLETION: int_value


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r332457 - [CodeComplete] Expose helpers to get RawComment of completion result.

2018-05-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed May 16 05:30:01 2018
New Revision: 332457

URL: http://llvm.org/viewvc/llvm-project?rev=332457&view=rev
Log:
[CodeComplete] Expose helpers to get RawComment of completion result.

Summary: Used in clangd, see D45999.

Reviewers: sammccall, hokein, ioeric, arphaman

Reviewed By: sammccall

Subscribers: arphaman, cfe-commits

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

Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=332457&r1=332456&r2=332457&view=diff
==
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Wed May 16 05:30:01 2018
@@ -46,6 +46,7 @@ class NamedDecl;
 class NestedNameSpecifier;
 class Preprocessor;
 class Sema;
+class RawComment;
 
 /// Default priority values for code-completion results based
 /// on their kind.
@@ -1073,6 +1074,23 @@ public:
   virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() = 0;
 };
 
+/// Get the documentation comment used to produce
+/// CodeCompletionString::BriefComment for RK_Declaration.
+const RawComment *getCompletionComment(const ASTContext &Ctx,
+   const NamedDecl *Decl);
+
+/// Get the documentation comment used to produce
+/// CodeCompletionString::BriefComment for RK_Pattern.
+const RawComment *getPatternCompletionComment(const ASTContext &Ctx,
+  const NamedDecl *Decl);
+
+/// Get the documentation comment used to produce
+/// CodeCompletionString::BriefComment for OverloadCandidate.
+const RawComment *
+getParameterComment(const ASTContext &Ctx,
+const CodeCompleteConsumer::OverloadCandidate &Result,
+unsigned ArgIndex);
+
 /// A simple code-completion consumer that prints the results it
 /// receives in a simple format.
 class PrintingCodeCompleteConsumer : public CodeCompleteConsumer {

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=332457&r1=332456&r2=332457&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed May 16 05:30:01 2018
@@ -2765,27 +2765,11 @@ CodeCompletionResult::CreateCodeCompleti
 if (Declaration) {
   Result.addParentContext(Declaration->getDeclContext());
   Pattern->ParentName = Result.getParentName();
-  // Provide code completion comment for self.GetterName where
-  // GetterName is the getter method for a property with name
-  // different from the property name (declared via a property
-  // getter attribute.
-  const NamedDecl *ND = Declaration;
-  if (const ObjCMethodDecl *M = dyn_cast(ND))
-if (M->isPropertyAccessor())
-  if (const ObjCPropertyDecl *PDecl = M->findPropertyDecl())
-if (PDecl->getGetterName() == M->getSelector() &&
-PDecl->getIdentifier() != M->getIdentifier()) {
-  if (const RawComment *RC = 
-Ctx.getRawCommentForAnyRedecl(M)) {
-Result.addBriefComment(RC->getBriefText(Ctx));
-Pattern->BriefComment = Result.getBriefComment();
-  }
-  else if (const RawComment *RC = 
- Ctx.getRawCommentForAnyRedecl(PDecl)) {
-Result.addBriefComment(RC->getBriefText(Ctx));
-Pattern->BriefComment = Result.getBriefComment();
-  }
-}
+  if (const RawComment *RC =
+  getPatternCompletionComment(Ctx, Declaration)) {
+Result.addBriefComment(RC->getBriefText(Ctx));
+Pattern->BriefComment = Result.getBriefComment();
+  }
 }
 
 return Pattern;
@@ -2845,14 +2829,9 @@ CodeCompletionResult::CreateCodeCompleti
 
   if (IncludeBriefComments) {
 // Add documentation comment, if it exists.
-if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(ND)) {
+if (const RawComment *RC = getCompletionComment(Ctx, Declaration)) {
   Result.addBriefComment(RC->getBriefText(Ctx));
 } 
-else if (const ObjCMethodDecl *OMD = dyn_cast(ND))
-  if (OMD->isPropertyAccessor())
-if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl())
-  if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(PDecl))
-Result.addBriefComment(RC->getBriefText(Ctx));
   }
 
   if (StartsNestedNameSpecifier) {
@@ -3042,6 +3021,59 @@ CodeCompletionResult::CreateCodeCompleti
   return Result.TakeString();
 }
 
+const RawComment *clang::getCompletionComment(const ASTContext &Ctx,
+ 

r332458 - [AST] Added a helper to extract a user-friendly text of a comment.

2018-05-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed May 16 05:30:09 2018
New Revision: 332458

URL: http://llvm.org/viewvc/llvm-project?rev=332458&view=rev
Log:
[AST] Added a helper to extract a user-friendly text of a comment.

Summary:
The helper is used in clangd for documentation shown in code completion
and storing the docs in the symbols. See D45999.

This patch reuses the code of the Doxygen comment lexer, disabling the
bits that do command and html tag parsing.
The new helper works on all comments, including non-doxygen comments.
However, it does not understand or transform any doxygen directives,
i.e. cannot extract brief text, etc.

Reviewers: sammccall, hokein, ioeric

Reviewed By: ioeric

Subscribers: mgorny, cfe-commits

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

Added:
cfe/trunk/unittests/AST/CommentTextTest.cpp
Modified:
cfe/trunk/include/clang/AST/CommentLexer.h
cfe/trunk/include/clang/AST/RawCommentList.h
cfe/trunk/lib/AST/CommentLexer.cpp
cfe/trunk/lib/AST/RawCommentList.cpp
cfe/trunk/unittests/AST/CMakeLists.txt

Modified: cfe/trunk/include/clang/AST/CommentLexer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentLexer.h?rev=332458&r1=332457&r2=332458&view=diff
==
--- cfe/trunk/include/clang/AST/CommentLexer.h (original)
+++ cfe/trunk/include/clang/AST/CommentLexer.h Wed May 16 05:30:09 2018
@@ -281,6 +281,11 @@ private:
   /// command, including command marker.
   SmallString<16> VerbatimBlockEndCommandName;
 
+  /// If true, the commands, html tags, etc will be parsed and reported as
+  /// separate tokens inside the comment body. If false, the comment text will
+  /// be parsed into text and newline tokens.
+  bool ParseCommands;
+
   /// Given a character reference name (e.g., "lt"), return the character that
   /// it stands for (e.g., "<").
   StringRef resolveHTMLNamedCharacterReference(StringRef Name) const;
@@ -315,12 +320,11 @@ private:
   /// Eat string matching regexp \code \s*\* \endcode.
   void skipLineStartingDecorations();
 
-  /// Lex stuff inside comments.  CommentEnd should be set correctly.
+  /// Lex comment text, including commands if ParseCommands is set to true.
   void lexCommentText(Token &T);
 
-  void setupAndLexVerbatimBlock(Token &T,
-const char *TextBegin,
-char Marker, const CommandInfo *Info);
+  void setupAndLexVerbatimBlock(Token &T, const char *TextBegin, char Marker,
+const CommandInfo *Info);
 
   void lexVerbatimBlockFirstLine(Token &T);
 
@@ -343,14 +347,13 @@ private:
 
 public:
   Lexer(llvm::BumpPtrAllocator &Allocator, DiagnosticsEngine &Diags,
-const CommandTraits &Traits,
-SourceLocation FileLoc,
-const char *BufferStart, const char *BufferEnd);
+const CommandTraits &Traits, SourceLocation FileLoc,
+const char *BufferStart, const char *BufferEnd,
+bool ParseCommands = true);
 
   void lex(Token &T);
 
-  StringRef getSpelling(const Token &Tok,
-const SourceManager &SourceMgr,
+  StringRef getSpelling(const Token &Tok, const SourceManager &SourceMgr,
 bool *Invalid = nullptr) const;
 };
 

Modified: cfe/trunk/include/clang/AST/RawCommentList.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RawCommentList.h?rev=332458&r1=332457&r2=332458&view=diff
==
--- cfe/trunk/include/clang/AST/RawCommentList.h (original)
+++ cfe/trunk/include/clang/AST/RawCommentList.h Wed May 16 05:30:09 2018
@@ -111,6 +111,30 @@ public:
 return extractBriefText(Context);
   }
 
+  /// Returns sanitized comment text, suitable for presentation in editor UIs.
+  /// E.g. will transform:
+  /// // This is a long multiline comment.
+  /// //   Parts of it  might be indented.
+  /// /* The comments styles might be mixed. */
+  ///  into
+  /// "This is a long multiline comment.\n"
+  /// "  Parts of it  might be indented.\n"
+  /// "The comments styles might be mixed."
+  /// Also removes leading indentation and sanitizes some common cases:
+  /// /* This is a first line.
+  ///  *   This is a second line. It is indented.
+  ///  * This is a third line. */
+  /// and
+  /// /* This is a first line.
+  ///  This is a second line. It is indented.
+  /// This is a third line. */
+  /// will both turn into:
+  /// "This is a first line.\n"
+  /// "  This is a second line. It is indented.\n"
+  /// "This is a third line."
+  std::string getFormattedText(const SourceManager &SourceMgr,
+   DiagnosticsEngine &Diags) const;
+
   /// Parse the comment, assuming it is attached to decl \c D.
   comments::FullComment *parse(const ASTContext &Context,
const Prepr

[clang-tools-extra] r332460 - [clangd] Parse all comments in Sema and completion.

2018-05-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed May 16 05:32:49 2018
New Revision: 332460

URL: http://llvm.org/viewvc/llvm-project?rev=332460&view=rev
Log:
[clangd] Parse all comments in Sema and completion.

Summary:
And add tests for the comment extraction code.

clangd will now show non-doxygen comments in completion for results
coming from Sema and Dynamic index.
Static index does not include the comments yet, I will enable it in
a separate commit after investigating which implications it has for
the size of the index.

Reviewers: sammccall, hokein, ioeric

Reviewed By: sammccall

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=332460&r1=332459&r2=332460&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Wed May 16 05:32:49 2018
@@ -25,6 +25,7 @@
 #include "clang/Sema/Sema.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
@@ -316,6 +317,7 @@ llvm::Optional> CppFil
 }
 // createInvocationFromCommandLine sets DisableFree.
 CI->getFrontendOpts().DisableFree = false;
+CI->getLangOpts()->CommentOpts.ParseAllComments = true;
   }
 
   std::unique_ptr ContentsBuffer =

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332460&r1=332459&r2=332460&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed May 16 05:32:49 2018
@@ -25,6 +25,7 @@
 #include "Trace.h"
 #include "URI.h"
 #include "index/Index.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -648,6 +649,7 @@ bool semaCodeComplete(std::unique_ptrgetFrontendOpts().DisableFree = false;
+  CI->getLangOpts()->CommentOpts.ParseAllComments = true;
 
   std::unique_ptr ContentsBuffer =
   llvm::MemoryBuffer::getMemBufferCopy(Input.Contents, Input.FileName);

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=332460&r1=332459&r2=332460&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed May 16 
05:32:49 2018
@@ -628,6 +628,30 @@ TEST(CompletionTest, DynamicIndexMultiFi
 Doc("Doooc"), Detail("void";
 }
 
+TEST(CompletionTest, Documentation) {
+  auto Results = completions(
+  R"cpp(
+  // Non-doxygen comment.
+  int foo();
+  /// Doxygen comment.
+  /// \param int a
+  int bar(int a);
+  /* Multi-line
+ block comment
+  */
+  int baz();
+
+  int x = ^
+ )cpp");
+  EXPECT_THAT(Results.items,
+  Contains(AllOf(Named("foo"), Doc("Non-doxygen comment.";
+  EXPECT_THAT(
+  Results.items,
+  Contains(AllOf(Named("bar"), Doc("Doxygen comment.\n\\param int a";
+  EXPECT_THAT(Results.items,
+  Contains(AllOf(Named("baz"), Doc("Multi-line\nblock comment";
+}
+
 TEST(CodeCompleteTest, DisableTypoCorrection) {
   auto Results = completions(R"cpp(
  namespace clang { int v; }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r332459 - [clangd] Retrieve minimally formatted comment text in completion.

2018-05-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed May 16 05:32:44 2018
New Revision: 332459

URL: http://llvm.org/viewvc/llvm-project?rev=332459&view=rev
Log:
[clangd] Retrieve minimally formatted comment text in completion.

Summary:
Previous implementation used to extract brief text from doxygen comments.
Brief text parsing slows down completion and is not suited for
non-doxygen comments.

This commit switches to providing comments that mimic the ones
originally written in the source code, doing minimal reindenting and
removing the comments markers to make the output more user-friendly.

It means we lose support for doxygen-specific features, e.g. extracting
brief text, but provide useful results for non-doxygen comments.
Switching the doxygen support back is an option, but I suggest to see
whether the current approach gives more useful results.

Reviewers: sammccall, hokein, ioeric

Reviewed By: sammccall

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompletionStringsTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332459&r1=332458&r2=332459&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed May 16 05:32:44 2018
@@ -230,7 +230,8 @@ struct CompletionCandidate {
   CompletionItem build(StringRef FileName, const CompletionItemScores &Scores,
const CodeCompleteOptions &Opts,
CodeCompletionString *SemaCCS,
-   const IncludeInserter *Includes) const {
+   const IncludeInserter *Includes,
+   llvm::StringRef SemaDocComment) const {
 assert(bool(SemaResult) == bool(SemaCCS));
 CompletionItem I;
 if (SemaResult) {
@@ -238,7 +239,7 @@ struct CompletionCandidate {
   getLabelAndInsertText(*SemaCCS, &I.label, &I.insertText,
 Opts.EnableSnippets);
   I.filterText = getFilterText(*SemaCCS);
-  I.documentation = getDocumentation(*SemaCCS);
+  I.documentation = formatDocumentation(*SemaCCS, SemaDocComment);
   I.detail = getDetail(*SemaCCS);
 }
 if (IndexResult) {
@@ -481,17 +482,17 @@ struct CompletionRecorder : public CodeC
 case CodeCompletionResult::RK_Pattern:
   return Result.Pattern->getTypedText();
 }
-auto *CCS = codeCompletionString(Result, /*IncludeBriefComments=*/false);
+auto *CCS = codeCompletionString(Result);
 return CCS->getTypedText();
   }
 
   // Build a CodeCompletion string for R, which must be from Results.
   // The CCS will be owned by this recorder.
-  CodeCompletionString *codeCompletionString(const CodeCompletionResult &R,
- bool IncludeBriefComments) {
+  CodeCompletionString *codeCompletionString(const CodeCompletionResult &R) {
 // CodeCompletionResult doesn't seem to be const-correct. We own it, 
anyway.
 return const_cast(R).CreateCodeCompletionString(
-*CCSema, CCContext, *CCAllocator, CCTUInfo, IncludeBriefComments);
+*CCSema, CCContext, *CCAllocator, CCTUInfo,
+/*IncludeBriefComments=*/false);
   }
 
 private:
@@ -535,7 +536,9 @@ public:
   const auto *CCS = Candidate.CreateSignatureString(
   CurrentArg, S, *Allocator, CCTUInfo, true);
   assert(CCS && "Expected the CodeCompletionString to be non-null");
-  SigHelp.signatures.push_back(ProcessOverloadCandidate(Candidate, *CCS));
+  SigHelp.signatures.push_back(ProcessOverloadCandidate(
+  Candidate, *CCS,
+  getParameterDocComment(S.getASTContext(), Candidate, CurrentArg)));
 }
   }
 
@@ -548,11 +551,12 @@ private:
   // CompletionString.h.
   SignatureInformation
   ProcessOverloadCandidate(const OverloadCandidate &Candidate,
-   const CodeCompletionString &CCS) const {
+   const CodeCompletionString &CCS,
+   llvm::StringRef DocComment) const {
 SignatureInformation Result;
 const char *ReturnType = nullptr;
 
-Result.documentation = getDocumentation(CCS);
+Result.documentation = formatDocumentation(CCS, DocComment);
 
 for (const auto &Chunk : CCS) {
   switch (Chunk.Kind) {
@@ -802,7 +806,11 @@ clang::CodeCompleteOptions CodeCompleteO
   Result.

Re: r332458 - [AST] Added a helper to extract a user-friendly text of a comment.

2018-05-17 Thread Ilya Biryukov via cfe-commits
Terribly sorry for the breakage and many thanks for fixing this!

On Thu, May 17, 2018 at 9:04 AM Clement Courbet  wrote:

> I should have fixed it in r332576.
>
> On Wed, May 16, 2018 at 11:49 PM, Galina Kistanova via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Also few other builders are affected:
>>
>> http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test
>> http://lab.llvm.org:8011/builders/clang-lld-x86_64-2stage
>> http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu
>>
>>
>> Thanks
>>
>> Galina
>>
>> On Wed, May 16, 2018 at 12:58 PM, Galina Kistanova 
>> wrote:
>>
>>> Hello Ilya,
>>>
>>> This commit broke build step for couple of our builders:
>>>
>>> http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/8541
>>> http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu
>>>
>>> . . .
>>> FAILED:
>>> tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/CommentTextTest.cpp.o
>>> /usr/bin/c++   -DGTEST_HAS_RTTI=0 -DGTEST_HAS_TR1_TUPLE=0
>>> -DGTEST_LANG_CXX11=1 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
>>> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/unittests/AST
>>> -I/home/buildslave/buildslave1a/clang-with-lto-ubuntu/llvm.src/tools/clang/unittests/AST
>>> -I/home/buildslave/buildslave1a/clang-with-lto-ubuntu/llvm.src/tools/clang/include
>>> -Itools/clang/include -Iinclude
>>> -I/home/buildslave/buildslave1a/clang-with-lto-ubuntu/llvm.src/include
>>> -I/home/buildslave/buildslave1a/clang-with-lto-ubuntu/llvm.src/utils/unittest/googletest/include
>>> -I/home/buildslave/buildslave1a/clang-with-lto-ubuntu/llvm.src/utils/unittest/googlemock/include
>>> -fPIC -fvisibility-inlines-hidden -std=c++11 -Wall -W -Wno-unused-parameter
>>> -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic
>>> -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor
>>> -Wno-comment -ffunction-sections -fdata-sections -fno-common
>>> -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG
>>> -Wno-variadic-macros -fno-exceptions -fno-rtti -MD -MT
>>> tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/CommentTextTest.cpp.o -MF
>>> tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/CommentTextTest.cpp.o.d
>>> -o tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/CommentTextTest.cpp.o
>>> -c
>>> /home/buildslave/buildslave1a/clang-with-lto-ubuntu/llvm.src/tools/clang/unittests/AST/CommentTextTest.cpp
>>> /home/buildslave/buildslave1a/clang-with-lto-ubuntu/llvm.src/tools/clang/unittests/AST/CommentTextTest.cpp:62:1:
>>> error: unterminated raw string
>>>  R"cpp(
>>>  ^
>>> . . .
>>>
>>> Please have a look?
>>>
>>> The builder was already red and did not send notifications.
>>>
>>> Thanks
>>>
>>> Galina
>>>
>>>
>>>
>>> On Wed, May 16, 2018 at 5:30 AM, Ilya Biryukov via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
>>>> Author: ibiryukov
>>>> Date: Wed May 16 05:30:09 2018
>>>> New Revision: 332458
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=332458&view=rev
>>>> Log:
>>>> [AST] Added a helper to extract a user-friendly text of a comment.
>>>>
>>>> Summary:
>>>> The helper is used in clangd for documentation shown in code completion
>>>> and storing the docs in the symbols. See D45999.
>>>>
>>>> This patch reuses the code of the Doxygen comment lexer, disabling the
>>>> bits that do command and html tag parsing.
>>>> The new helper works on all comments, including non-doxygen comments.
>>>> However, it does not understand or transform any doxygen directives,
>>>> i.e. cannot extract brief text, etc.
>>>>
>>>> Reviewers: sammccall, hokein, ioeric
>>>>
>>>> Reviewed By: ioeric
>>>>
>>>> Subscribers: mgorny, cfe-commits
>>>>
>>>> Differential Revision: https://reviews.llvm.org/D46000
>>>>
>>>> Added:
>>>> cfe/trunk/unittests/AST/CommentTextTest.cpp
>>>> Modified:
>>>> cfe/trunk/include/clang/AST/CommentLexer.h
>>>> cfe/trunk/include/clang/AST/RawCommentList.h
>>>> cfe/trunk/lib/AST/CommentLexer.cpp
>>>> cfe/trunk/lib/AST/RawCommentList.cpp
>>>> cfe/trunk/unittests/

[clang-tools-extra] r332976 - [clangd] Remove ignored Preamble::CanReuse call from completion

2018-05-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue May 22 06:10:09 2018
New Revision: 332976

URL: http://llvm.org/viewvc/llvm-project?rev=332976&view=rev
Log:
[clangd] Remove ignored Preamble::CanReuse call from completion

Summary:
Now that the clients who relied on stats for files from preamble are
gone.

Reviewers: ioeric, sammccall

Reviewed By: ioeric

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=332976&r1=332975&r2=332976&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue May 22 06:10:09 2018
@@ -654,21 +654,11 @@ bool semaCodeComplete(std::unique_ptr ContentsBuffer =
   llvm::MemoryBuffer::getMemBufferCopy(Input.Contents, Input.FileName);
 
+  // The diagnostic options must be set before creating a CompilerInstance.
+  CI->getDiagnosticOpts().IgnoreWarnings = true;
   // We reuse the preamble whether it's valid or not. This is a
   // correctness/performance tradeoff: building without a preamble is slow, and
   // completion is latency-sensitive.
-  if (Input.Preamble) {
-auto Bounds =
-ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
-// FIXME(ibiryukov): Remove this call to CanReuse() after we'll fix
-// clients relying on getting stats for preamble files during code
-// completion.
-// Note that results of CanReuse() are ignored, see the comment above.
-Input.Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds,
- Input.VFS.get());
-  }
-  // The diagnostic options must be set before creating a CompilerInstance.
-  CI->getDiagnosticOpts().IgnoreWarnings = true;
   auto Clang = prepareCompilerInstance(
   std::move(CI), Input.Preamble, std::move(ContentsBuffer),
   std::move(Input.PCHs), std::move(Input.VFS), DummyDiagsConsumer);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r332978 - [clangd] Fix a typo. NFC

2018-05-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue May 22 06:29:37 2018
New Revision: 332978

URL: http://llvm.org/viewvc/llvm-project?rev=332978&view=rev
Log:
[clangd] Fix a typo. NFC

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=332978&r1=332977&r2=332978&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue May 22 06:29:37 2018
@@ -330,7 +330,7 @@ llvm::Optional ClangdServer::switc
 
   bool IsHeader = HeaderIter != std::end(HeaderExtensions);
 
-  // We can only switch between extensions known extensions.
+  // We can only switch between the known extensions.
   if (!IsSource && !IsHeader)
 return llvm::None;
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r333189 - [clangd] Serve comments for headers decls from dynamic index only

2018-05-24 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu May 24 07:49:23 2018
New Revision: 333189

URL: http://llvm.org/viewvc/llvm-project?rev=333189&view=rev
Log:
[clangd] Serve comments for headers decls from dynamic index only

Summary:
To fix a crash in code completion that occurrs when reading doc
comments from files that were updated after the preamble was
computed. In that case, the files on disk could've been changed and we
can't rely on finding the comment text with the same range anymore.

The current workaround is to not provide comments from the headers at
all and rely on the dynamic index instead.

A more principled solution would be to store contents of the files
read inside the preamble, but it is way harder to implement properly,
given that it would definitely increase the sizes of the preamble.

Together with D47272, this should fix all preamble-related crashes
we're aware of.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, ioeric, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=333189&r1=333188&r2=333189&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu May 24 07:49:23 2018
@@ -586,9 +586,11 @@ public:
   const auto *CCS = Candidate.CreateSignatureString(
   CurrentArg, S, *Allocator, CCTUInfo, true);
   assert(CCS && "Expected the CodeCompletionString to be non-null");
+  // FIXME: for headers, we need to get a comment from the index.
   SigHelp.signatures.push_back(ProcessOverloadCandidate(
   Candidate, *CCS,
-  getParameterDocComment(S.getASTContext(), Candidate, CurrentArg)));
+  getParameterDocComment(S.getASTContext(), Candidate, CurrentArg,
+ /*CommentsFromHeader=*/false)));
 }
   }
 
@@ -1030,7 +1032,8 @@ private:
   SemaCCS = Recorder->codeCompletionString(*SR);
   if (Opts.IncludeComments) {
 assert(Recorder->CCSema);
-DocComment = getDocComment(Recorder->CCSema->getASTContext(), *SR);
+DocComment = getDocComment(Recorder->CCSema->getASTContext(), *SR,
+   /*CommentsFromHeader=*/false);
   }
 }
 return Candidate.build(FileName, Scores, Opts, SemaCCS, Includes.get(), 
DocComment);

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=333189&r1=333188&r2=333189&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Thu May 24 
07:49:23 2018
@@ -10,6 +10,7 @@
 #include "CodeCompletionStrings.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/RawCommentList.h"
+#include "clang/Basic/SourceManager.h"
 #include 
 
 namespace clang {
@@ -122,10 +123,23 @@ void processSnippetChunks(const CodeComp
   }
 }
 
+std::string getFormattedComment(const ASTContext &Ctx, const RawComment &RC,
+bool CommentsFromHeaders) {
+  auto &SourceMgr = Ctx.getSourceManager();
+  // Parsing comments from invalid preamble can lead to crashes. So we only
+  // return comments from the main file when doing code completion. For
+  // indexing, we still read all the comments.
+  // FIXME: find a better fix, e.g. store file contents in the preamble or get
+  // doc comments from the index.
+  if (!CommentsFromHeaders && !SourceMgr.isWrittenInMainFile(RC.getLocStart()))
+return "";
+  return RC.getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
+}
 } // namespace
 
 std::string getDocComment(const ASTContext &Ctx,
-  const CodeCompletionResult &Result) {
+  const CodeCompletionResult &Result,
+  bool CommentsFromHeaders) {
   // FIXME: clang's completion also returns documentation for RK_Pattern if 
they
   // contain a pattern for ObjC properties. Unfortunately, there is no API to
   // get this declaration, so we don't show documentation in that case.
@@ -137,20 +151,20 @@ std::string getDocComment(const ASTConte
   const RawComment *RC = getCompletionComment(Ctx, Decl);
   if (!RC)
 return "";
-  return RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
+  return getFormattedComment(Ctx, 

[clang-tools-extra] r333196 - [clangd] Build index on preamble changes instead of the AST changes

2018-05-24 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu May 24 08:50:15 2018
New Revision: 333196

URL: http://llvm.org/viewvc/llvm-project?rev=333196&view=rev
Log:
[clangd] Build index on preamble changes instead of the AST changes

Summary:
This is more efficient and avoids data races when reading files that
come from the preamble. The staleness can occur when reading a file
from disk that changed after the preamble was built. This can lead to
crashes, e.g. when parsing comments.

We do not to rely on symbols from the main file anyway, since any info
that those provide can always be taken from the AST.

Reviewers: ioeric, sammccall

Reviewed By: ioeric

Subscribers: malaperle, klimek, javed.absar, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=333196&r1=333195&r2=333196&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu May 24 08:50:15 2018
@@ -17,6 +17,7 @@
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Refactoring/RefactoringResultConsumer.h"
 #include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
@@ -92,12 +93,14 @@ ClangdServer::ClangdServer(GlobalCompila
   // is parsed.
   // FIXME(ioeric): this can be slow and we may be able to index on less
   // critical paths.
-  WorkScheduler(Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
-FileIdx
-? [this](PathRef Path,
- ParsedAST *AST) { FileIdx->update(Path, AST); 
}
-: ASTParsedCallback(),
-Opts.UpdateDebounce) {
+  WorkScheduler(
+  Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
+  FileIdx
+  ? [this](PathRef Path, ASTContext &AST,
+   std::shared_ptr
+   PP) { FileIdx->update(Path, &AST, std::move(PP)); }
+  : PreambleParsedCallback(),
+  Opts.UpdateDebounce) {
   if (FileIdx && Opts.StaticIndex) {
 MergedIndex = mergeIndex(FileIdx.get(), Opts.StaticIndex);
 Index = MergedIndex.get();

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=333196&r1=333195&r2=333196&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu May 24 08:50:15 2018
@@ -13,6 +13,8 @@
 #include "Logger.h"
 #include "SourceCode.h"
 #include "Trace.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -25,7 +27,6 @@
 #include "clang/Sema/Sema.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
-#include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/CrashRecoveryContext.h"
@@ -86,6 +87,9 @@ private:
 
 class CppFilePreambleCallbacks : public PreambleCallbacks {
 public:
+  CppFilePreambleCallbacks(PathRef File, PreambleParsedCallback ParsedCallback)
+  : File(File), ParsedCallback(ParsedCallback) {}
+
   std::vector takeTopLevelDeclIDs() {
 return std::move(TopLevelDeclIDs);
   }
@@ -102,6 +106,13 @@ public:
 }
   }
 
+  void AfterExecute(CompilerInstance &CI) override {
+if (!ParsedCallback)
+  return;
+trace::Span Tracer("Running PreambleCallback");
+ParsedCallback(File, CI.getASTContext(), CI.getPreprocessorPtr());
+  }
+
   void HandleTopLevelDecl(DeclGroupRef DG) override {
 for (Decl *D : DG) {
   if (isa(D))
@@ -122,6 +133,8 @@ public:
   }
 
 private:
+  PathRef File;
+  PreambleParsedCallback ParsedCallback;
   std::vector TopLevelDecls;
   std::vector TopLevelDeclIDs;
   std::vector Inclusions;
@@ -277,9 +290,9 @@ ParsedAST::P

[clang-tools-extra] r333280 - [clangd] Temporarily disable the test that crashes under asan.

2018-05-25 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri May 25 07:55:18 2018
New Revision: 333280

URL: http://llvm.org/viewvc/llvm-project?rev=333280&view=rev
Log:
[clangd] Temporarily disable the test that crashes under asan.

It turns out that our fix did not solve the problem completely and the
crash due to stale preamble is still there under asan.
Disabling the test for now, will reenable it when landing a proper fix
for the problem.

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=333280&r1=333279&r2=333280&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri May 25 
07:55:18 2018
@@ -999,7 +999,8 @@ TEST(CompletionTest, NoIndexCompletionsI
   }
 }
 
-TEST(CompletionTest, DocumentationFromChangedFileCrash) {
+// FIXME: This still crashes under asan. Fix it and reenable the test.
+TEST(CompletionTest, DISABLED_DocumentationFromChangedFileCrash) {
   MockFSProvider FS;
   auto FooH = testPath("foo.h");
   auto FooCpp = testPath("foo.cpp");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r333369 - [clangd] Workaround the comments crash, reenable the test.

2018-05-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 28 02:54:51 2018
New Revision: 69

URL: http://llvm.org/viewvc/llvm-project?rev=69&view=rev
Log:
[clangd] Workaround the comments crash, reenable the test.

This fix is still quite fragile, the underlying problem is that the
code should not rely on source ranges coming from the preamble to be
correct when reading from the text buffers.
This is probably not possible to achieve in practice, so we would
probably have to keep the contents of old headers around for the
lifetime of the preamble.

Modified:
clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=69&r1=68&r2=69&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Mon May 28 
02:54:51 2018
@@ -9,6 +9,7 @@
 
 #include "CodeCompletionStrings.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceManager.h"
 #include 
@@ -123,17 +124,32 @@ void processSnippetChunks(const CodeComp
   }
 }
 
-std::string getFormattedComment(const ASTContext &Ctx, const RawComment &RC,
-bool CommentsFromHeaders) {
+bool canRequestComment(const ASTContext &Ctx, const NamedDecl &D,
+   bool CommentsFromHeaders) {
+  if (CommentsFromHeaders)
+return true;
   auto &SourceMgr = Ctx.getSourceManager();
-  // Parsing comments from invalid preamble can lead to crashes. So we only
-  // return comments from the main file when doing code completion. For
-  // indexing, we still read all the comments.
+  // Accessing comments for decls from  invalid preamble can lead to crashes.
+  // So we only return comments from the main file when doing code completion.
+  // For indexing, we still read all the comments.
   // FIXME: find a better fix, e.g. store file contents in the preamble or get
   // doc comments from the index.
-  if (!CommentsFromHeaders && !SourceMgr.isWrittenInMainFile(RC.getLocStart()))
-return "";
-  return RC.getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
+  auto canRequestForDecl = [&](const NamedDecl &D) -> bool {
+for (auto *Redecl : D.redecls()) {
+  auto Loc = SourceMgr.getSpellingLoc(Redecl->getLocation());
+  if (!SourceMgr.isWrittenInMainFile(Loc))
+return false;
+}
+return true;
+  };
+  // First, check the decl itself.
+  if (!canRequestForDecl(D))
+return false;
+  // Completion also returns comments for properties, corresponding to ObjC
+  // methods.
+  const ObjCMethodDecl *M = dyn_cast(&D);
+  const ObjCPropertyDecl *PDecl = M ? M->findPropertyDecl() : nullptr;
+  return !PDecl || canRequestForDecl(*PDecl);
 }
 } // namespace
 
@@ -145,26 +161,26 @@ std::string getDocComment(const ASTConte
   // get this declaration, so we don't show documentation in that case.
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
 return "";
-  auto Decl = Result.getDeclaration();
-  if (!Decl)
+  auto *Decl = Result.getDeclaration();
+  if (!Decl || !canRequestComment(Ctx, *Decl, CommentsFromHeaders))
 return "";
   const RawComment *RC = getCompletionComment(Ctx, Decl);
   if (!RC)
 return "";
-  return getFormattedComment(Ctx, *RC, CommentsFromHeaders);
+  return RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
 }
 
 std::string
 getParameterDocComment(const ASTContext &Ctx,
const CodeCompleteConsumer::OverloadCandidate &Result,
unsigned ArgIndex, bool CommentsFromHeaders) {
-  auto Func = Result.getFunction();
-  if (!Func)
+  auto *Func = Result.getFunction();
+  if (!Func || !canRequestComment(Ctx, *Func, CommentsFromHeaders))
 return "";
   const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex);
   if (!RC)
 return "";
-  return getFormattedComment(Ctx, *RC, CommentsFromHeaders);
+  return RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
 }
 
 void getLabelAndInsertText(const CodeCompletionString &CCS, std::string *Label,

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=69&r1=68&r2=69&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon May 28 
02:54:51 2018
@@ -1000,7 +1000,7 @@ TEST(CompletionTest, NoIndexCompletionsI
 }
 
 // FIXME: This still crashes under asan. Fix 

[clang-tools-extra] r333370 - [clangd] Fix leak sanitizers warnings in clangd

2018-05-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 28 05:11:37 2018
New Revision: 70

URL: http://llvm.org/viewvc/llvm-project?rev=70&view=rev
Log:
[clangd] Fix leak sanitizers  warnings in clangd

The commit includes two changes:
1. Set DisableFree to false when building the ParsedAST.
   This is sane default, since clangd never wants to leak the AST.
2. Make sure CompilerInstance created in code completion is passed to
   the FrontendAction::BeginSourceFile call.
   We have to do this to make sure the memory buffers of remapped
   files are properly freed.

Our tests do not produce any warnings under asan anymore.
The changes are mostly trivial, just moving the code around. So
sending without review.

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=70&r1=69&r2=70&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Mon May 28 05:11:37 2018
@@ -153,6 +153,10 @@ ParsedAST::Build(std::unique_ptr Buffer,
  std::shared_ptr PCHs,
  IntrusiveRefCntPtr VFS) {
+  assert(CI);
+  // Command-line parsing sets DisableFree to true by default, but we don't 
want
+  // to leak memory in clangd.
+  CI->getFrontendOpts().DisableFree = false;
   const PrecompiledPreamble *PreamblePCH =
   Preamble ? &Preamble->Preamble : nullptr;
 

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=70&r1=69&r2=70&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon May 28 05:11:37 2018
@@ -699,26 +699,13 @@ bool semaCodeComplete(std::unique_ptrgetFrontendOpts().DisableFree = false;
+  auto &FrontendOpts = CI->getFrontendOpts();
+  FrontendOpts.DisableFree = false;
+  FrontendOpts.SkipFunctionBodies = true;
   CI->getLangOpts()->CommentOpts.ParseAllComments = true;
-
-  std::unique_ptr ContentsBuffer =
-  llvm::MemoryBuffer::getMemBufferCopy(Input.Contents, Input.FileName);
-
-  // The diagnostic options must be set before creating a CompilerInstance.
-  CI->getDiagnosticOpts().IgnoreWarnings = true;
-  // We reuse the preamble whether it's valid or not. This is a
-  // correctness/performance tradeoff: building without a preamble is slow, and
-  // completion is latency-sensitive.
-  auto Clang = prepareCompilerInstance(
-  std::move(CI), Input.Preamble, std::move(ContentsBuffer),
-  std::move(Input.PCHs), std::move(Input.VFS), DummyDiagsConsumer);
-
   // Disable typo correction in Sema.
-  Clang->getLangOpts().SpellChecking = false;
-
-  auto &FrontendOpts = Clang->getFrontendOpts();
-  FrontendOpts.SkipFunctionBodies = true;
+  CI->getLangOpts()->SpellChecking = false;
+  // Setup code completion.
   FrontendOpts.CodeCompleteOpts = Options;
   FrontendOpts.CodeCompletionAt.FileName = Input.FileName;
   auto Offset = positionToOffset(Input.Contents, Input.Pos);
@@ -731,6 +718,18 @@ bool semaCodeComplete(std::unique_ptr ContentsBuffer =
+  llvm::MemoryBuffer::getMemBufferCopy(Input.Contents, Input.FileName);
+  // The diagnostic options must be set before creating a CompilerInstance.
+  CI->getDiagnosticOpts().IgnoreWarnings = true;
+  // We reuse the preamble whether it's valid or not. This is a
+  // correctness/performance tradeoff: building without a preamble is slow, and
+  // completion is latency-sensitive.
+  // NOTE: we must call BeginSourceFile after prepareCompilerInstance. 
Otherwise
+  // the remapped buffers do not get freed.
+  auto Clang = prepareCompilerInstance(
+  std::move(CI), Input.Preamble, std::move(ContentsBuffer),
+  std::move(Input.PCHs), std::move(Input.VFS), DummyDiagsConsumer);
   Clang->setCodeCompletionConsumer(Consumer.release());
 
   SyntaxOnlyAction Action;

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=70&r1=69&r2=70&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon May 28 
05:11:37 2018
@@ -18,6 +18,7 @@
 #include "TestFS.h"
 #include "index/MemIndex.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -1040,6 +1041,25 @@ TEST(CompletionTest, Documen

[clang-tools-extra] r333371 - [clangd] Remove accessors for top-level decls from preamble

2018-05-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 28 05:23:17 2018
New Revision: 71

URL: http://llvm.org/viewvc/llvm-project?rev=71&view=rev
Log:
[clangd] Remove accessors for top-level decls from preamble

Summary:
They cause lots of deserialization and are not actually used.
The ParsedAST accessor that previously returned those was renamed from
getTopLevelDecls to getLocalTopLevelDecls in order to avoid
confusion.

This change should considerably improve the speed of findDefinition
and other features that try to find AST nodes, corresponding to the
locations in the source code.

Reviewers: ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, mehdi_amini, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=71&r1=70&r2=71&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Mon May 28 05:23:17 2018
@@ -90,22 +90,8 @@ public:
   CppFilePreambleCallbacks(PathRef File, PreambleParsedCallback ParsedCallback)
   : File(File), ParsedCallback(ParsedCallback) {}
 
-  std::vector takeTopLevelDeclIDs() {
-return std::move(TopLevelDeclIDs);
-  }
-
   std::vector takeInclusions() { return std::move(Inclusions); }
 
-  void AfterPCHEmitted(ASTWriter &Writer) override {
-TopLevelDeclIDs.reserve(TopLevelDecls.size());
-for (Decl *D : TopLevelDecls) {
-  // Invalid top-level decls may not have been serialized.
-  if (D->isInvalidDecl())
-continue;
-  TopLevelDeclIDs.push_back(Writer.getDeclID(D));
-}
-  }
-
   void AfterExecute(CompilerInstance &CI) override {
 if (!ParsedCallback)
   return;
@@ -113,14 +99,6 @@ public:
 ParsedCallback(File, CI.getASTContext(), CI.getPreprocessorPtr());
   }
 
-  void HandleTopLevelDecl(DeclGroupRef DG) override {
-for (Decl *D : DG) {
-  if (isa(D))
-continue;
-  TopLevelDecls.push_back(D);
-}
-  }
-
   void BeforeExecute(CompilerInstance &CI) override {
 SourceMgr = &CI.getSourceManager();
   }
@@ -135,8 +113,6 @@ public:
 private:
   PathRef File;
   PreambleParsedCallback ParsedCallback;
-  std::vector TopLevelDecls;
-  std::vector TopLevelDeclIDs;
   std::vector Inclusions;
   SourceManager *SourceMgr = nullptr;
 };
@@ -204,28 +180,6 @@ ParsedAST::Build(std::unique_ptr Resolved;
-  Resolved.reserve(Preamble->TopLevelDeclIDs.size());
-
-  ExternalASTSource &Source = *getASTContext().getExternalSource();
-  for (serialization::DeclID TopLevelDecl : Preamble->TopLevelDeclIDs) {
-// Resolve the declaration ID to an actual declaration, possibly
-// deserializing the declaration in the process.
-if (Decl *D = Source.GetExternalDecl(TopLevelDecl))
-  Resolved.push_back(D);
-  }
-
-  TopLevelDecls.reserve(TopLevelDecls.size() +
-Preamble->TopLevelDeclIDs.size());
-  TopLevelDecls.insert(TopLevelDecls.begin(), Resolved.begin(), 
Resolved.end());
-
-  PreambleDeclsDeserialized = true;
-}
-
 ParsedAST::ParsedAST(ParsedAST &&Other) = default;
 
 ParsedAST &ParsedAST::operator=(ParsedAST &&Other) = default;
@@ -252,9 +206,8 @@ const Preprocessor &ParsedAST::getPrepro
   return Clang->getPreprocessor();
 }
 
-ArrayRef ParsedAST::getTopLevelDecls() {
-  ensurePreambleDeclsDeserialized();
-  return TopLevelDecls;
+ArrayRef ParsedAST::getLocalTopLevelDecls() {
+  return LocalTopLevelDecls;
 }
 
 const std::vector &ParsedAST::getDiagnostics() const { return Diags; }
@@ -264,7 +217,7 @@ std::size_t ParsedAST::getUsedBytes() co
   // FIXME(ibiryukov): we do not account for the dynamically allocated part of
   // Message and Fixes inside each diagnostic.
   return AST.getASTAllocatedMemory() + AST.getSideTableAllocatedMemory() +
- ::getUsedBytes(TopLevelDecls) + ::getUsedBytes(Diags);
+ ::getUsedBytes(LocalTopLevelDecls) + ::getUsedBytes(Diags);
 }
 
 const std::vector &ParsedAST::getInclusions() const {
@@ -272,21 +225,19 @@ const std::vector &ParsedAST:
 }
 
 PreambleData::PreambleData(PrecompiledPreamble Preamble,
-   std::vector TopLevelDeclIDs,
std::vector Diags,
std::vector Inclusions)
-: Preamble(std::move(Preamble)),
-  TopLevelDeclIDs(std::move(TopLevelDeclIDs)), Diags(std::move(Diags)),
+: Preamble(std::move(Preamble)), Diags(std::move(Diags)),
   Inclusions(std::move(Inclusions)) {}
 
 ParsedAST::ParsedAST(std::shared_ptr Preamble,
  std::unique_ptr Clang,
  std::unique_ptr Action,
-

[clang-tools-extra] r333373 - [clangd] Remove the outdated comment. NFC

2018-05-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 28 05:43:20 2018
New Revision: 73

URL: http://llvm.org/viewvc/llvm-project?rev=73&view=rev
Log:
[clangd] Remove the outdated comment. NFC

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=73&r1=72&r2=73&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon May 28 
05:43:20 2018
@@ -1000,7 +1000,6 @@ TEST(CompletionTest, NoIndexCompletionsI
   }
 }
 
-// FIXME: This still crashes under asan. Fix it and reenable the test.
 TEST(CompletionTest, DocumentationFromChangedFileCrash) {
   MockFSProvider FS;
   auto FooH = testPath("foo.h");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r314445 - [clangd] Skip informative qualifier chunks.

2017-09-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Sep 28 11:39:59 2017
New Revision: 314445

URL: http://llvm.org/viewvc/llvm-project?rev=314445&view=rev
Log:
[clangd] Skip informative qualifier chunks.

Summary:
Completion results look much nicer without them.
Informative qualifiers are stored for every method from a base class, even when
calling those methods does not require any qualifiers. For example,
struct Foo { int foo(); };
struct Bar : Foo { };
void test() { Bar(). // Completion item label was 'Foo::foo' before,
 // but inserted text was simply 'foo'.
 // We now simply show 'foo' in completion item label.

They effectively cluttered the completion list without providing much value.

Reviewers: bkramer, krasimir, rwols

Reviewed By: rwols

Subscribers: klimek, cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=314445&r1=31&r2=314445&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Sep 28 11:39:59 2017
@@ -409,6 +409,11 @@ private:
 
 }; // CompletionItemsCollector
 
+bool isInformativeQualifierChunk(CodeCompletionString::Chunk const &Chunk) {
+  return Chunk.Kind == CodeCompletionString::CK_Informative &&
+ StringRef(Chunk.Text).endswith("::");
+}
+
 class PlainTextCompletionItemsCollector final
 : public CompletionItemsCollector {
 
@@ -421,6 +426,11 @@ private:
   void ProcessChunks(const CodeCompletionString &CCS,
  CompletionItem &Item) const override {
 for (const auto &Chunk : CCS) {
+  // Informative qualifier chunks only clutter completion results, skip
+  // them.
+  if (isInformativeQualifierChunk(Chunk))
+continue;
+
   switch (Chunk.Kind) {
   case CodeCompletionString::CK_TypedText:
 // There's always exactly one CK_TypedText chunk.
@@ -453,6 +463,11 @@ private:
  CompletionItem &Item) const override {
 unsigned ArgCount = 0;
 for (const auto &Chunk : CCS) {
+  // Informative qualifier chunks only clutter completion results, skip
+  // them.
+  if (isInformativeQualifierChunk(Chunk))
+continue;
+
   switch (Chunk.Kind) {
   case CodeCompletionString::CK_TypedText:
 // The piece of text that the user is expected to type to match

Added: clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion-qualifiers.test?rev=314445&view=auto
==
--- clang-tools-extra/trunk/test/clangd/completion-qualifiers.test (added)
+++ clang-tools-extra/trunk/test/clangd/completion-qualifiers.test Thu Sep 28 
11:39:59 2017
@@ -0,0 +1,18 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+Content-Length: 297
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"class
 Foo {\n  public:\nint foo() const;\nint bar() const;\n};\n\nclass Bar 
: public Foo {\n  int foo() const;\n};\n\nvoid test() {\n  Bar().\n}"}}}
+Content-Length: 151
+
+{"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":11,"character":8}}}
+# CHECK: {"jsonrpc":"2.0","id":2,"result":[
+# CHECK-DAG: {"label":"foo() 
const","kind":2,"detail":"int","sortText":"200035foo","filterText":"foo","insertText":"foo","insertTextFormat":1}
+# CHECK-DAG: {"label":"bar() 
const","kind":2,"detail":"int","sortText":"37bar","filterText":"bar","insertText":"bar","insertTextFormat":1}
+# CHECK-DAG: {"label":"Foo::foo() 
const","kind":2,"detail":"int","sortText":"37foo","filterText":"foo","insertText":"foo","insertTextFormat":1}
+# CHECK: ]}
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r314677 - [clangd] Run clang-format on the source code. NFC.

2017-10-02 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Oct  2 08:10:41 2017
New Revision: 314677

URL: http://llvm.org/viewvc/llvm-project?rev=314677&view=rev
Log:
[clangd] Run clang-format on the source code. NFC.

Modified:
clang-tools-extra/trunk/clangd/ProtocolHandlers.h

Modified: clang-tools-extra/trunk/clangd/ProtocolHandlers.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ProtocolHandlers.h?rev=314677&r1=314676&r2=314677&view=diff
==
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.h (original)
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.h Mon Oct  2 08:10:41 2017
@@ -50,11 +50,11 @@ public:
   virtual void onGoToDefinition(TextDocumentPositionParams Params, StringRef 
ID,
 JSONOutput &Out) = 0;
   virtual void onSwitchSourceHeader(TextDocumentIdentifier Params, StringRef 
ID,
-JSONOutput &Out) = 0;  

+JSONOutput &Out) = 0;
 };
 
 void registerCallbackHandlers(JSONRPCDispatcher &Dispatcher, JSONOutput &Out,
- ProtocolCallbacks &Callbacks);
+  ProtocolCallbacks &Callbacks);
 
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r314678 - [clangd] Command line arg to specify compile_commands.json path

2017-10-02 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Oct  2 08:13:20 2017
New Revision: 314678

URL: http://llvm.org/viewvc/llvm-project?rev=314678&view=rev
Log:
[clangd] Command line arg to specify compile_commands.json path

Summary: Adds compileCommands command line argument to specify an absolute path 
directly to the requested compile_commands.json for flags.

Reviewed By: ilya-biryukov

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=314678&r1=314677&r2=314678&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Oct  2 08:13:20 2017
@@ -196,8 +196,9 @@ void ClangdLSPServer::onSwitchSourceHead
 
 ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, unsigned AsyncThreadsCount,
  bool SnippetCompletions,
- llvm::Optional ResourceDir)
-: Out(Out), CDB(/*Logger=*/Out),
+ llvm::Optional ResourceDir,
+ llvm::Optional CompileCommandsDir)
+: Out(Out), CDB(/*Logger=*/Out, std::move(CompileCommandsDir)),
   Server(CDB, /*DiagConsumer=*/*this, FSProvider, AsyncThreadsCount,
  SnippetCompletions, /*Logger=*/Out, ResourceDir) {}
 

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=314678&r1=314677&r2=314678&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Mon Oct  2 08:13:20 2017
@@ -27,9 +27,13 @@ class JSONOutput;
 /// dispatch and ClangdServer together.
 class ClangdLSPServer : private DiagnosticsConsumer, private ProtocolCallbacks 
{
 public:
+  /// If \p CompileCommandsDir has a value, compile_commands.json will be
+  /// loaded only from \p CompileCommandsDir. Otherwise, clangd will look
+  /// for compile_commands.json in all parent directories of each file.
   ClangdLSPServer(JSONOutput &Out, unsigned AsyncThreadsCount,
   bool SnippetCompletions,
-  llvm::Optional ResourceDir);
+  llvm::Optional ResourceDir,
+  llvm::Optional CompileCommandsDir);
 
   /// Run LSP server loop, receiving input for it from \p In. \p In must be
   /// opened in binary mode. Output will be written using Out variable passed 
to

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=314678&r1=314677&r2=314678&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Mon Oct  2 
08:13:20 2017
@@ -8,10 +8,10 @@
 //===-===//
 
 #include "GlobalCompilationDatabase.h"
+#include "Logger.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "Logger.h"
 
 namespace clang {
 namespace clangd {
@@ -38,8 +38,9 @@ tooling::CompileCommand getDefaultCompil
 }
 
 DirectoryBasedGlobalCompilationDatabase::
-DirectoryBasedGlobalCompilationDatabase(clangd::Logger &Logger)
-: Logger(Logger) {}
+DirectoryBasedGlobalCompilationDatabase(
+clangd::Logger &Logger, llvm::Optional CompileCommandsDir)
+: Logger(Logger), CompileCommandsDir(std::move(CompileCommandsDir)) {}
 
 std::vector
 DirectoryBasedGlobalCompilationDatabase::getCompileCommands(PathRef File) {
@@ -67,31 +68,50 @@ void DirectoryBasedGlobalCompilationData
 }
 
 tooling::CompilationDatabase *
-DirectoryBasedGlobalCompilationDatabase::getCompilationDatabase(PathRef File) {
-  std::lock_guard Lock(Mutex);
+DirectoryBasedGlobalCompilationDatabase::tryLoadDatabaseFromPath(PathRef File) 
{
 
   namespace path = llvm::sys::path;
+  auto CachedIt = CompilationDatabases.find(File);
 
   assert((path::is_absolute(File, path::Style::posix) ||
   path::is_absolute(File, path::Style::windows)) &&
  "path must be absolute");
 
-  for (auto Path = path::parent_path(File); !Path.empty();
-   Path = path::parent_path(Path)) {
+  if (CachedIt != CompilationDatabases.end(

[clang-tools-extra] r314989 - [clangd] Added async API to run code completion.

2017-10-05 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Oct  5 10:04:13 2017
New Revision: 314989

URL: http://llvm.org/viewvc/llvm-project?rev=314989&view=rev
Log:
[clangd] Added async API to run code completion.

Summary:
ClangdServer now provides async code completion API.
It is still used synchronously by ClangdLSPServer, more work is needed
to allow processing other requests in parallel while completion (or
any other request) is running.

Reviewers: klimek, bkramer, krasimir

Reviewed By: klimek

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=314989&r1=314988&r2=314989&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Oct  5 10:04:13 2017
@@ -149,6 +149,9 @@ void ClangdLSPServer::onCompletion(TextD
.codeComplete(Params.textDocument.uri.file,
  Position{Params.position.line,
   Params.position.character})
+   .get() // FIXME(ibiryukov): This could be made async if we
+  // had an API that would allow to attach callbacks to
+  // futures returned by ClangdServer.
.Value;
 
   std::string Completions;

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=314989&r1=314988&r2=314989&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Oct  5 10:04:13 2017
@@ -194,18 +194,19 @@ std::future ClangdServer::forceRep
  std::move(TaggedFS));
 }
 
-Tagged>
+std::future>>
 ClangdServer::codeComplete(PathRef File, Position Pos,
llvm::Optional OverridenContents,
IntrusiveRefCntPtr *UsedFS) {
-  std::string DraftStorage;
-  if (!OverridenContents) {
+  std::string Contents;
+  if (OverridenContents) {
+Contents = *OverridenContents;
+  } else {
 auto FileContents = DraftMgr.getDraft(File);
 assert(FileContents.Draft &&
"codeComplete is called for non-added document");
 
-DraftStorage = std::move(*FileContents.Draft);
-OverridenContents = DraftStorage;
+Contents = std::move(*FileContents.Draft);
   }
 
   auto TaggedFS = FSProvider.getTaggedFileSystem(File);
@@ -215,12 +216,36 @@ ClangdServer::codeComplete(PathRef File,
   std::shared_ptr Resources = Units.getFile(File);
   assert(Resources && "Calling completion on non-added file");
 
-  auto Preamble = Resources->getPossiblyStalePreamble();
-  std::vector Result = clangd::codeComplete(
-  File, Resources->getCompileCommand(),
-  Preamble ? &Preamble->Preamble : nullptr, *OverridenContents, Pos,
-  TaggedFS.Value, PCHs, SnippetCompletions, Logger);
-  return make_tagged(std::move(Result), TaggedFS.Tag);
+  using PackagedTask =
+  std::packaged_task>()>;
+
+  // Remember the current Preamble and use it when async task starts executing.
+  // At the point when async task starts executing, we may have a different
+  // Preamble in Resources. However, we assume the Preamble that we obtain here
+  // is reusable in completion more often.
+  std::shared_ptr Preamble =
+  Resources->getPossiblyStalePreamble();
+  // A task that will be run asynchronously.
+  PackagedTask Task([=]() mutable { // 'mutable' to reassign Preamble variable.
+if (!Preamble) {
+  // Maybe we built some preamble before processing this request.
+  Preamble = Resources->getPossiblyStalePreamble();
+}
+// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
+// both the old and the new version in case only one of them matches.
+
+std::vector Result = clangd::codeComplete(
+File, Resources->getCompileCommand(),
+Preamble ? &Preamble->Preamble : nullptr, Contents, Pos, 
TaggedFS.Value,
+PCHs, SnippetCompletions, Logger);
+return make_tagged(std::move(Result), std::move(TaggedFS.Tag));
+  });
+
+  auto Future = Task.get_future();
+  // FIXME(ibiryukov): to reduce overhead for wrapping the same callable
+  // multiple times, ClangdScheduler should return future<> itself.
+  WorkScheduler.addToFront([](PackagedTask Task) { Task(); }, std::move(Task));
+  return Future;
 }
 
 std::vector ClangdServer::formatRange(PathRef File,


[clang-tools-extra] r315028 - [clangd] Attempt to fix compilation with MSVC.

2017-10-05 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Oct  5 15:15:15 2017
New Revision: 315028

URL: http://llvm.org/viewvc/llvm-project?rev=315028&view=rev
Log:
[clangd] Attempt to fix compilation with MSVC.

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=315028&r1=315027&r2=315028&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Thu Oct  5 15:15:15 2017
@@ -50,6 +50,9 @@ typedef std::string VFSTag;
 /// FileSystemProvider when this value was computed.
 template  class Tagged {
 public:
+  // MSVC requires future<> arguments to be default-constructible.
+  Tagged() = default;
+
   template 
   Tagged(U &&Value, VFSTag Tag)
   : Value(std::forward(Value)), Tag(std::move(Tag)) {}
@@ -61,8 +64,8 @@ public:
   Tagged(Tagged &&Other)
   : Value(std::move(Other.Value)), Tag(std::move(Other.Tag)) {}
 
-  T Value;
-  VFSTag Tag;
+  T Value = T();
+  VFSTag Tag = VFSTag();
 };
 
 template 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r314989 - [clangd] Added async API to run code completion.

2017-10-06 Thread Ilya Biryukov via cfe-commits
Hi Douglas,

Fixed in r315028.
Sorry for the inconvenience.

On Thu, Oct 5, 2017 at 11:55 PM, Yung, Douglas 
wrote:

> Hi Ilya,
>
> Your change has broken the build on the PS4 Windows bot.
>
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_
> 64-scei-ps4-windows10pro-fast/builds/12525
>
> Can you take a look and fix it?
>
> Douglas Yung
>
> > -Original Message-
> > From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf
> Of
> > Ilya Biryukov via cfe-commits
> > Sent: Thursday, October 05, 2017 10:04
> > To: cfe-commits@lists.llvm.org
> > Subject: [clang-tools-extra] r314989 - [clangd] Added async API to run
> code
> > completion.
> >
> > Author: ibiryukov
> > Date: Thu Oct  5 10:04:13 2017
> > New Revision: 314989
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=314989&view=rev
> > Log:
> > [clangd] Added async API to run code completion.
> >
> > Summary:
> > ClangdServer now provides async code completion API.
> > It is still used synchronously by ClangdLSPServer, more work is needed to
> > allow processing other requests in parallel while completion (or any
> other
> > request) is running.
> >
> > Reviewers: klimek, bkramer, krasimir
> >
> > Reviewed By: klimek
> >
> > Subscribers: cfe-commits
> >
> > Differential Revision: https://reviews.llvm.org/D38583
> >
> > Modified:
> > clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
> > clang-tools-extra/trunk/clangd/ClangdServer.cpp
> > clang-tools-extra/trunk/clangd/ClangdServer.h
> > clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
> >
> > Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-
> > extra/trunk/clangd/ClangdLSPServer.cpp?rev=314989&r1=314988&r2=314989&
> view=dif
> > f
> > 
> ==
> > --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
> > +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Oct  5
> > +++ 10:04:13 2017
> > @@ -149,6 +149,9 @@ void ClangdLSPServer::onCompletion(TextD
> > .codeComplete(Params.textDocument.uri.file,
> >   Position{Params.position.line,
> >Params.position.character})
> > +   .get() // FIXME(ibiryukov): This could be made async
> if we
> > +  // had an API that would allow to attach
> callbacks
> > to
> > +  // futures returned by ClangdServer.
> > .Value;
> >
> >std::string Completions;
> >
> > Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-
> > extra/trunk/clangd/ClangdServer.cpp?rev=314989&
> r1=314988&r2=314989&view=diff
> > 
> ==
> > --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
> > +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Oct  5 10:04:13
> > +++ 2017
> > @@ -194,18 +194,19 @@ std::future ClangdServer::forceRep
> >   std::move(TaggedFS));  }
> >
> > -Tagged>
> > +std::future>>
> >  ClangdServer::codeComplete(PathRef File, Position Pos,
> > llvm::Optional OverridenContents,
> > IntrusiveRefCntPtr
> *UsedFS) {
> > -  std::string DraftStorage;
> > -  if (!OverridenContents) {
> > +  std::string Contents;
> > +  if (OverridenContents) {
> > +Contents = *OverridenContents;
> > +  } else {
> >  auto FileContents = DraftMgr.getDraft(File);
> >  assert(FileContents.Draft &&
> > "codeComplete is called for non-added document");
> >
> > -DraftStorage = std::move(*FileContents.Draft);
> > -OverridenContents = DraftStorage;
> > +Contents = std::move(*FileContents.Draft);
> >}
> >
> >auto TaggedFS = FSProvider.getTaggedFileSystem(File);
> > @@ -215,12 +216,36 @@ ClangdServer::codeComplete(PathRef File,
> >std::shared_ptr Resources = Units.getFile(File);
> >assert(Resources && "Calling completion on non-added file");
> >
> > -  auto Preamble = Resources->getPossiblyStalePreamble();
> > -  std::vector Result = 

[clang-tools-extra] r315055 - [clangd] Add textDocument/signatureHelp

2017-10-06 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Oct  6 04:54:17 2017
New Revision: 315055

URL: http://llvm.org/viewvc/llvm-project?rev=315055&view=rev
Log:
[clangd] Add textDocument/signatureHelp

Summary:
Makes clangd respond to a client's "textDocument/signatureHelp" request by
presenting function/method overloads.

Patch by Raoul Wols.

Reviewers: bkramer, ilya-biryukov, krasimir

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/signature-help.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/test/clangd/formatting.test
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=315055&r1=315054&r2=315055&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Fri Oct  6 04:54:17 2017
@@ -48,6 +48,7 @@ void ClangdLSPServer::onInitialize(Strin
   "documentOnTypeFormattingProvider": 
{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
   "codeActionProvider": true,
   "completionProvider": {"resolveProvider": false, 
"triggerCharacters": [".",">",":"]},
+  "signatureHelpProvider": {"triggerCharacters": ["(",","]},
   "definitionProvider": true
 }}})");
   if (IP.rootUri && !IP.rootUri->file.empty())
@@ -166,6 +167,18 @@ void ClangdLSPServer::onCompletion(TextD
   R"(,"result":[)" + Completions + R"(]})");
 }
 
+void ClangdLSPServer::onSignatureHelp(TextDocumentPositionParams Params,
+  StringRef ID, JSONOutput &Out) {
+  const auto SigHelp = SignatureHelp::unparse(
+  Server
+  .signatureHelp(
+  Params.textDocument.uri.file,
+  Position{Params.position.line, Params.position.character})
+  .Value);
+  Out.writeMessage(R"({"jsonrpc":"2.0","id":)" + ID.str() + R"(,"result":)" +
+   SigHelp + "}");
+}
+
 void ClangdLSPServer::onGoToDefinition(TextDocumentPositionParams Params,
StringRef ID, JSONOutput &Out) {
 

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=315055&r1=315054&r2=315055&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Fri Oct  6 04:54:17 2017
@@ -67,6 +67,8 @@ private:
 JSONOutput &Out) override;
   void onCompletion(TextDocumentPositionParams Params, StringRef ID,
 JSONOutput &Out) override;
+  void onSignatureHelp(TextDocumentPositionParams Params, StringRef ID,
+   JSONOutput &Out) override;
   void onGoToDefinition(TextDocumentPositionParams Params, StringRef ID,
 JSONOutput &Out) override;
   void onSwitchSourceHeader(TextDocumentIdentifier Params, StringRef ID,

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=315055&r1=315054&r2=315055&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Oct  6 04:54:17 2017
@@ -248,6 +248,35 @@ ClangdServer::codeComplete(PathRef File,
   return Future;
 }
 
+Tagged
+ClangdServer::signatureHelp(PathRef File, Position Pos,
+llvm::Optional OverridenContents,
+IntrusiveRefCntPtr *UsedFS) {
+  std::string DraftStorage;
+  if (!OverridenContents) {
+auto FileContents = DraftMgr.getDraft(File);
+assert(FileContents.Draft &&
+   "signatureHelp is called for non-added document");
+
+DraftStorage = std::move(*FileContents.Draft);
+OverridenContents = DraftStorage;
+  }
+
+  auto TaggedFS = FSProvider.getTaggedFileSystem(File);
+  if (UsedFS)
+*UsedFS = TaggedFS.Value;
+
+  std::shared_ptr Resources = Units.getFile(File);
+  assert(Res

[clang-tools-extra] r315065 - [clangd] Run clang-format on the source code. NFC.

2017-10-06 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Oct  6 07:39:39 2017
New Revision: 315065

URL: http://llvm.org/viewvc/llvm-project?rev=315065&view=rev
Log:
[clangd] Run clang-format on the source code. NFC.

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=315065&r1=315064&r2=315065&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Oct  6 07:39:39 2017
@@ -398,12 +398,11 @@ llvm::Optional ClangdServer::switc
   return NewPath.str().str(); // First str() to convert from SmallString to
   // StringRef, second to convert from 
StringRef
   // to std::string
-
+
 // Also check NewExt in upper-case, just in case.
 llvm::sys::path::replace_extension(NewPath, NewExt.upper());
 if (FS->exists(NewPath))
   return NewPath.str().str();
-
   }
 
   return llvm::None;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r315210 - [clangd] Added move-only function helpers.

2017-10-09 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Oct  9 09:26:26 2017
New Revision: 315210

URL: http://llvm.org/viewvc/llvm-project?rev=315210&view=rev
Log:
[clangd] Added move-only function helpers.

Summary:
They are now used in ClangdScheduler instead of deferred std::async
computations.
The results of `std::async` are much less effective and do not provide
a good abstraction for similar purposes, i.e. for storing additional callbacks
to clangd async tasks. The actual callback API will follow a bit later.

Reviewers: klimek, bkramer, sammccall, krasimir

Reviewed By: sammccall

Subscribers: cfe-commits

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

Added:
clang-tools-extra/trunk/clangd/Function.h
Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=315210&r1=315209&r2=315210&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Oct  9 09:26:26 2017
@@ -99,7 +99,7 @@ ClangdScheduler::ClangdScheduler(unsigne
   for (unsigned I = 0; I < AsyncThreadsCount; ++I) {
 Workers.push_back(std::thread([this]() {
   while (true) {
-std::future Request;
+UniqueFunction Request;
 
 // Pick request from the queue
 {
@@ -120,7 +120,7 @@ ClangdScheduler::ClangdScheduler(unsigne
   RequestQueue.pop_front();
 } // unlock Mutex
 
-Request.get();
+Request();
   }
 }));
   }

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=315210&r1=315209&r2=315210&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Oct  9 09:26:26 2017
@@ -20,6 +20,7 @@
 #include "llvm/ADT/StringRef.h"
 
 #include "ClangdUnit.h"
+#include "Function.h"
 #include "Protocol.h"
 
 #include 
@@ -132,9 +133,8 @@ public:
 
 {
   std::lock_guard Lock(Mutex);
-  RequestQueue.push_front(std::async(std::launch::deferred,
- std::forward(F),
- std::forward(As)...));
+  RequestQueue.push_front(
+  BindWithForward(std::forward(F), std::forward(As)...));
 }
 RequestCV.notify_one();
   }
@@ -149,9 +149,8 @@ public:
 
 {
   std::lock_guard Lock(Mutex);
-  RequestQueue.push_back(std::async(std::launch::deferred,
-std::forward(F),
-std::forward(As)...));
+  RequestQueue.push_back(
+  BindWithForward(std::forward(F), std::forward(As)...));
 }
 RequestCV.notify_one();
   }
@@ -167,7 +166,7 @@ private:
   bool Done = false;
   /// A queue of requests. Elements of this vector are async computations (i.e.
   /// results of calling std::async(std::launch::deferred, ...)).
-  std::deque> RequestQueue;
+  std::deque> RequestQueue;
   /// Condition variable to wake up worker threads.
   std::condition_variable RequestCV;
 };

Added: clang-tools-extra/trunk/clangd/Function.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Function.h?rev=315210&view=auto
==
--- clang-tools-extra/trunk/clangd/Function.h (added)
+++ clang-tools-extra/trunk/clangd/Function.h Mon Oct  9 09:26:26 2017
@@ -0,0 +1,136 @@
+//===--- Function.h - Utility callable wrappers  -*- 
C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file provides an analogue to std::function that supports move 
semantics.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FUNCTION_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FUNCTION_H
+
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// A move-only type-erasing function wrapper. Similar to `std::function`, but
+/// allows to store move-only callables.
+template  class UniqueFunction;
+
+template  class UniqueFunction {
+public:
+  UniqueFunction() = default;
+  UniqueFunction(std::nullptr_t) : UniqueFunction(){};
+
+  UniqueFunction(UniqueFunction const &) = delete;
+  UniqueFunction &operator=(UniqueFunction const &) = delete;
+
+  UniqueFunction(UniqueFunction &&) noexcept = default;
+  UniqueFunction &operator=(UniqueFunction &&) no

r315212 - Set PreprocessorOpts.GeneratePreamble=true in PrecompiledPreamble.

2017-10-09 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Oct  9 09:52:12 2017
New Revision: 315212

URL: http://llvm.org/viewvc/llvm-project?rev=315212&view=rev
Log:
Set PreprocessorOpts.GeneratePreamble=true in PrecompiledPreamble.

Summary:
It was previsouly set only in ASTUnit, but it should be set for all client of
PrecompiledPreamble.

Reviewers: erikjv, bkramer, klimek

Reviewed By: bkramer

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=315212&r1=315211&r2=315212&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Oct  9 09:52:12 2017
@@ -1698,7 +1698,6 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
   PreprocessorOptions &PPOpts = CI->getPreprocessorOpts();
   PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName;
   PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors;
-  PPOpts.GeneratePreamble = PrecompilePreambleAfterNParses != 0;
   PPOpts.SingleFileParseMode = SingleFileParse;
   
   // Override the resources path.

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=315212&r1=315211&r2=315212&view=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Mon Oct  9 09:52:12 2017
@@ -234,6 +234,8 @@ llvm::ErrorOr Preco
   FrontendOpts.OutputFile = PreamblePCHFile->getFilePath();
   PreprocessorOpts.PrecompiledPreambleBytes.first = 0;
   PreprocessorOpts.PrecompiledPreambleBytes.second = false;
+  // Inform preprocessor to record conditional stack when building the 
preamble.
+  PreprocessorOpts.GeneratePreamble = true;
 
   // Create the compiler instance to use for building the precompiled preamble.
   std::unique_ptr Clang(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r315213 - [clangd] Added a test for r315212.

2017-10-09 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Oct  9 09:53:00 2017
New Revision: 315213

URL: http://llvm.org/viewvc/llvm-project?rev=315213&view=rev
Log:
[clangd] Added a test for r315212.

Added:
clang-tools-extra/trunk/test/clangd/diagnostics-preamble.test

Added: clang-tools-extra/trunk/test/clangd/diagnostics-preamble.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostics-preamble.test?rev=315213&view=auto
==
--- clang-tools-extra/trunk/test/clangd/diagnostics-preamble.test (added)
+++ clang-tools-extra/trunk/test/clangd/diagnostics-preamble.test Mon Oct  9 
09:53:00 2017
@@ -0,0 +1,15 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+
+Content-Length: 206
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"#ifndef
 FOO\n#define FOO\nint a;\n#else\nint a = b;#endif\n\n\n"}}}
+# CHECK: 
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///main.cpp","diagnostics":[]}}
+
+Content-Length: 58
+
+{"jsonrpc":"2.0","id":2,"method":"shutdown","params":null}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r315214 - [clangd] Added a command-line arg to mirror clangd input into a file.

2017-10-09 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Oct  9 09:58:16 2017
New Revision: 315214

URL: http://llvm.org/viewvc/llvm-project?rev=315214&view=rev
Log:
[clangd] Added a command-line arg to mirror clangd input into a file.

Summary: The arg is useful for debugging and creating test cases.

Reviewers: bkramer, krasimir

Reviewed By: bkramer

Subscribers: klimek, cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/input-mirror.test
Modified:
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=315214&r1=315213&r2=315214&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Mon Oct  9 09:58:16 
2017
@@ -37,6 +37,14 @@ void JSONOutput::log(const Twine &Messag
   Logs.flush();
 }
 
+void JSONOutput::mirrorInput(const Twine &Message) {
+  if (!InputMirror)
+return;
+
+  *InputMirror << Message;
+  InputMirror->flush();
+}
+
 void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
   Output.log("Method ignored.\n");
   // Return that this method is unsupported.
@@ -147,6 +155,14 @@ void clangd::runLanguageServerLoop(std::
 continue;
   }
 
+  Out.mirrorInput(Line);
+  // Mirror '\n' that gets consumed by std::getline, but is not included in
+  // the resulting Line.
+  // Note that '\r' is part of Line, so we don't need to mirror it
+  // separately.
+  if (!In.eof())
+Out.mirrorInput("\n");
+
   llvm::StringRef LineRef(Line);
 
   // We allow YAML-style comments in headers. Technically this isn't part
@@ -163,9 +179,8 @@ void clangd::runLanguageServerLoop(std::
   if (LineRef.consume_front("Content-Length: ")) {
 if (ContentLength != 0) {
   Out.log("Warning: Duplicate Content-Length header received. "
-  "The previous value for this message ("
-  + std::to_string(ContentLength)
-  + ") was ignored.\n");
+  "The previous value for this message (" +
+  std::to_string(ContentLength) + ") was ignored.\n");
 }
 
 llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
@@ -185,15 +200,13 @@ void clangd::runLanguageServerLoop(std::
   // parser.
   std::vector JSON(ContentLength + 1, '\0');
   In.read(JSON.data(), ContentLength);
+  Out.mirrorInput(StringRef(JSON.data(), In.gcount()));
 
   // If the stream is aborted before we read ContentLength bytes, In
   // will have eofbit and failbit set.
   if (!In) {
-Out.log("Input was aborted. Read only "
-+ std::to_string(In.gcount())
-+ " bytes of expected "
-+ std::to_string(ContentLength)
-+ ".\n");
+Out.log("Input was aborted. Read only " + std::to_string(In.gcount()) +
+" bytes of expected " + std::to_string(ContentLength) + ".\n");
 break;
   }
 
@@ -209,8 +222,8 @@ void clangd::runLanguageServerLoop(std::
   if (IsDone)
 break;
 } else {
-  Out.log( "Warning: Missing Content-Length header, or message has zero "
-   "length.\n" );
+  Out.log("Warning: Missing Content-Length header, or message has zero "
+  "length.\n");
 }
   }
 }

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=315214&r1=315213&r2=315214&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Mon Oct  9 09:58:16 2017
@@ -24,8 +24,9 @@ namespace clangd {
 /// them.
 class JSONOutput : public Logger {
 public:
-  JSONOutput(llvm::raw_ostream &Outs, llvm::raw_ostream &Logs)
-  : Outs(Outs), Logs(Logs) {}
+  JSONOutput(llvm::raw_ostream &Outs, llvm::raw_ostream &Logs,
+ llvm::raw_ostream *InputMirror = nullptr)
+  : Outs(Outs), Logs(Logs), InputMirror(InputMirror) {}
 
   /// Emit a JSONRPC message.
   void writeMessage(const Twine &Message);
@@ -33,9 +34,15 @@ public:
   /// Write to the logging stream.
   void log(const Twine &Message) override;
 
+  /// Mirror \p Message into InputMirror stream. Does nothing if InputMirror is
+  /// null.
+  /// Unlike other methods of JSONOutput, mirrorInput is not thread-safe.
+  void mirrorInput(const Twine &Message);
+
 private:
   llvm::raw_ostream &Outs;
   llvm::raw_ostream &Logs;
+  llvm::raw_ostream *InputMirror;
 
   std::mu

Re: [clang-tools-extra] r315210 - [clangd] Added move-only function helpers.

2017-10-10 Thread Ilya Biryukov via cfe-commits
Will do, sorry about that.

On Oct 10, 2017 01:15, "Galina Kistanova"  wrote:

> Hello Ilya,
>
> This commit broke build on one of our builders:
>
> http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/16435
>
> Please have a look?
>
> Thanks
>
> Galina
>
>
> On Mon, Oct 9, 2017 at 9:26 AM, Ilya Biryukov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: ibiryukov
>> Date: Mon Oct  9 09:26:26 2017
>> New Revision: 315210
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=315210&view=rev
>> Log:
>> [clangd] Added move-only function helpers.
>>
>> Summary:
>> They are now used in ClangdScheduler instead of deferred std::async
>> computations.
>> The results of `std::async` are much less effective and do not provide
>> a good abstraction for similar purposes, i.e. for storing additional
>> callbacks
>> to clangd async tasks. The actual callback API will follow a bit later.
>>
>> Reviewers: klimek, bkramer, sammccall, krasimir
>>
>> Reviewed By: sammccall
>>
>> Subscribers: cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D38627
>>
>> Added:
>> clang-tools-extra/trunk/clangd/Function.h
>> Modified:
>> clang-tools-extra/trunk/clangd/ClangdServer.cpp
>> clang-tools-extra/trunk/clangd/ClangdServer.h
>>
>> Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> clangd/ClangdServer.cpp?rev=315210&r1=315209&r2=315210&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Oct  9 09:26:26
>> 2017
>> @@ -99,7 +99,7 @@ ClangdScheduler::ClangdScheduler(unsigne
>>for (unsigned I = 0; I < AsyncThreadsCount; ++I) {
>>  Workers.push_back(std::thread([this]() {
>>while (true) {
>> -std::future Request;
>> +UniqueFunction Request;
>>
>>  // Pick request from the queue
>>  {
>> @@ -120,7 +120,7 @@ ClangdScheduler::ClangdScheduler(unsigne
>>RequestQueue.pop_front();
>>  } // unlock Mutex
>>
>> -Request.get();
>> +Request();
>>}
>>  }));
>>}
>>
>> Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> clangd/ClangdServer.h?rev=315210&r1=315209&r2=315210&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
>> +++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Oct  9 09:26:26
>> 2017
>> @@ -20,6 +20,7 @@
>>  #include "llvm/ADT/StringRef.h"
>>
>>  #include "ClangdUnit.h"
>> +#include "Function.h"
>>  #include "Protocol.h"
>>
>>  #include 
>> @@ -132,9 +133,8 @@ public:
>>
>>  {
>>std::lock_guard Lock(Mutex);
>> -  RequestQueue.push_front(std::async(std::launch::deferred,
>> - std::forward(F),
>> - std::forward(As)...));
>> +  RequestQueue.push_front(
>> +  BindWithForward(std::forward(F),
>> std::forward(As)...));
>>  }
>>  RequestCV.notify_one();
>>}
>> @@ -149,9 +149,8 @@ public:
>>
>>  {
>>std::lock_guard Lock(Mutex);
>> -  RequestQueue.push_back(std::async(std::launch::deferred,
>> -std::forward(F),
>> -std::forward(As)...));
>> +  RequestQueue.push_back(
>> +  BindWithForward(std::forward(F),
>> std::forward(As)...));
>>  }
>>  RequestCV.notify_one();
>>}
>> @@ -167,7 +166,7 @@ private:
>>bool Done = false;
>>/// A queue of requests. Elements of this vector are async
>> computations (i.e.
>>/// results of calling std::async(std::launch::deferred, ...)).
>> -  std::deque> RequestQueue;
>> +  std::deque> RequestQueue;
>>/// Condition variable to wake up worker threads.
>>std::condition_variable RequestCV;
>>  };
>>
>> Added: clang-tools-extra/trunk/clangd/Function.h
>> URL: h

[clang-tools-extra] r315284 - [clangd] Fix compilation on gcc.

2017-10-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Oct 10 01:40:57 2017
New Revision: 315284

URL: http://llvm.org/viewvc/llvm-project?rev=315284&view=rev
Log:
[clangd] Fix compilation on gcc.

Modified:
clang-tools-extra/trunk/clangd/Function.h

Modified: clang-tools-extra/trunk/clangd/Function.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Function.h?rev=315284&r1=315283&r2=315284&view=diff
==
--- clang-tools-extra/trunk/clangd/Function.h (original)
+++ clang-tools-extra/trunk/clangd/Function.h Tue Oct 10 01:40:57 2017
@@ -106,8 +106,8 @@ private:
 public:
   template 
   auto operator()(RestArgs &&... Rest)
-  -> decltype(CallImpl(llvm::index_sequence_for(),
-   std::forward(Rest)...)) {
+  -> decltype(this->CallImpl(llvm::index_sequence_for(),
+ std::forward(Rest)...)) {
 
 #ifndef NDEBUG
 assert(!WasCalled && "Can only call result of BindWithForward once.");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r315210 - [clangd] Added move-only function helpers.

2017-10-10 Thread Ilya Biryukov via cfe-commits
Fixed in r315284.

On Tue, Oct 10, 2017 at 10:28 AM, Ilya Biryukov 
wrote:

> Will do, sorry about that.
>
> On Oct 10, 2017 01:15, "Galina Kistanova"  wrote:
>
>> Hello Ilya,
>>
>> This commit broke build on one of our builders:
>>
>> http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-
>> test/builds/16435
>>
>> Please have a look?
>>
>> Thanks
>>
>> Galina
>>
>>
>> On Mon, Oct 9, 2017 at 9:26 AM, Ilya Biryukov via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: ibiryukov
>>> Date: Mon Oct  9 09:26:26 2017
>>> New Revision: 315210
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=315210&view=rev
>>> Log:
>>> [clangd] Added move-only function helpers.
>>>
>>> Summary:
>>> They are now used in ClangdScheduler instead of deferred std::async
>>> computations.
>>> The results of `std::async` are much less effective and do not provide
>>> a good abstraction for similar purposes, i.e. for storing additional
>>> callbacks
>>> to clangd async tasks. The actual callback API will follow a bit later.
>>>
>>> Reviewers: klimek, bkramer, sammccall, krasimir
>>>
>>> Reviewed By: sammccall
>>>
>>> Subscribers: cfe-commits
>>>
>>> Differential Revision: https://reviews.llvm.org/D38627
>>>
>>> Added:
>>> clang-tools-extra/trunk/clangd/Function.h
>>> Modified:
>>> clang-tools-extra/trunk/clangd/ClangdServer.cpp
>>> clang-tools-extra/trunk/clangd/ClangdServer.h
>>>
>>> Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>>> clangd/ClangdServer.cpp?rev=315210&r1=315209&r2=315210&view=diff
>>> 
>>> ==
>>> --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
>>> +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Oct  9 09:26:26
>>> 2017
>>> @@ -99,7 +99,7 @@ ClangdScheduler::ClangdScheduler(unsigne
>>>for (unsigned I = 0; I < AsyncThreadsCount; ++I) {
>>>  Workers.push_back(std::thread([this]() {
>>>while (true) {
>>> -std::future Request;
>>> +UniqueFunction Request;
>>>
>>>  // Pick request from the queue
>>>  {
>>> @@ -120,7 +120,7 @@ ClangdScheduler::ClangdScheduler(unsigne
>>>RequestQueue.pop_front();
>>>  } // unlock Mutex
>>>
>>> -Request.get();
>>> +Request();
>>>}
>>>  }));
>>>}
>>>
>>> Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
>>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>>> clangd/ClangdServer.h?rev=315210&r1=315209&r2=315210&view=diff
>>> 
>>> ==
>>> --- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
>>> +++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Oct  9 09:26:26
>>> 2017
>>> @@ -20,6 +20,7 @@
>>>  #include "llvm/ADT/StringRef.h"
>>>
>>>  #include "ClangdUnit.h"
>>> +#include "Function.h"
>>>  #include "Protocol.h"
>>>
>>>  #include 
>>> @@ -132,9 +133,8 @@ public:
>>>
>>>  {
>>>std::lock_guard Lock(Mutex);
>>> -  RequestQueue.push_front(std::async(std::launch::deferred,
>>> - std::forward(F),
>>> - std::forward(As)...));
>>> +  RequestQueue.push_front(
>>> +  BindWithForward(std::forward(F),
>>> std::forward(As)...));
>>>  }
>>>  RequestCV.notify_one();
>>>}
>>> @@ -149,9 +149,8 @@ public:
>>>
>>>  {
>>>std::lock_guard Lock(Mutex);
>>> -  RequestQueue.push_back(std::async(std::launch::deferred,
>>> -std::forward(F),
>>> -std::forward(As)...));
>>> +  RequestQueue.push_back(
>>> +  BindWithForward(std::forward(F),
>>> std::forward(As)...));
>>>  }
>>>  RequestCV.notify_one();
>>>

[clang-tools-extra] r315287 - Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"

2017-10-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Oct 10 02:08:47 2017
New Revision: 315287

URL: http://llvm.org/viewvc/llvm-project?rev=315287&view=rev
Log:
Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"

This reverts commit r315242 and restores r315214.

To fix original failure, replaced non-portable `diff -Z` with portable
alternative: `diff -b`.

Added:
clang-tools-extra/trunk/test/clangd/input-mirror.test
Modified:
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=315287&r1=315286&r2=315287&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Oct 10 02:08:47 
2017
@@ -37,6 +37,14 @@ void JSONOutput::log(const Twine &Messag
   Logs.flush();
 }
 
+void JSONOutput::mirrorInput(const Twine &Message) {
+  if (!InputMirror)
+return;
+
+  *InputMirror << Message;
+  InputMirror->flush();
+}
+
 void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
   Output.log("Method ignored.\n");
   // Return that this method is unsupported.
@@ -147,6 +155,14 @@ void clangd::runLanguageServerLoop(std::
 continue;
   }
 
+  Out.mirrorInput(Line);
+  // Mirror '\n' that gets consumed by std::getline, but is not included in
+  // the resulting Line.
+  // Note that '\r' is part of Line, so we don't need to mirror it
+  // separately.
+  if (!In.eof())
+Out.mirrorInput("\n");
+
   llvm::StringRef LineRef(Line);
 
   // We allow YAML-style comments in headers. Technically this isn't part
@@ -163,9 +179,8 @@ void clangd::runLanguageServerLoop(std::
   if (LineRef.consume_front("Content-Length: ")) {
 if (ContentLength != 0) {
   Out.log("Warning: Duplicate Content-Length header received. "
-  "The previous value for this message ("
-  + std::to_string(ContentLength)
-  + ") was ignored.\n");
+  "The previous value for this message (" +
+  std::to_string(ContentLength) + ") was ignored.\n");
 }
 
 llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
@@ -185,15 +200,13 @@ void clangd::runLanguageServerLoop(std::
   // parser.
   std::vector JSON(ContentLength + 1, '\0');
   In.read(JSON.data(), ContentLength);
+  Out.mirrorInput(StringRef(JSON.data(), In.gcount()));
 
   // If the stream is aborted before we read ContentLength bytes, In
   // will have eofbit and failbit set.
   if (!In) {
-Out.log("Input was aborted. Read only "
-+ std::to_string(In.gcount())
-+ " bytes of expected "
-+ std::to_string(ContentLength)
-+ ".\n");
+Out.log("Input was aborted. Read only " + std::to_string(In.gcount()) +
+" bytes of expected " + std::to_string(ContentLength) + ".\n");
 break;
   }
 
@@ -209,8 +222,8 @@ void clangd::runLanguageServerLoop(std::
   if (IsDone)
 break;
 } else {
-  Out.log( "Warning: Missing Content-Length header, or message has zero "
-   "length.\n" );
+  Out.log("Warning: Missing Content-Length header, or message has zero "
+  "length.\n");
 }
   }
 }

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=315287&r1=315286&r2=315287&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Tue Oct 10 02:08:47 2017
@@ -24,8 +24,9 @@ namespace clangd {
 /// them.
 class JSONOutput : public Logger {
 public:
-  JSONOutput(llvm::raw_ostream &Outs, llvm::raw_ostream &Logs)
-  : Outs(Outs), Logs(Logs) {}
+  JSONOutput(llvm::raw_ostream &Outs, llvm::raw_ostream &Logs,
+ llvm::raw_ostream *InputMirror = nullptr)
+  : Outs(Outs), Logs(Logs), InputMirror(InputMirror) {}
 
   /// Emit a JSONRPC message.
   void writeMessage(const Twine &Message);
@@ -33,9 +34,15 @@ public:
   /// Write to the logging stream.
   void log(const Twine &Message) override;
 
+  /// Mirror \p Message into InputMirror stream. Does nothing if InputMirror is
+  /// null.
+  /// Unlike other methods of JSONOutput, mirrorInput is not thread-safe.
+  void mirrorInput(const Twine &Message);
+
 private:
   llvm::raw_ostream &Outs;
   llvm::raw_ostream &Logs;
+  llvm::raw_ostream *InputMirror;
 
   std::mutex StreamMutex;
 };

Modified: clang-tools-extra/trunk/clan

Re: [clang-tools-extra] r315214 - [clangd] Added a command-line arg to mirror clangd input into a file.

2017-10-10 Thread Ilya Biryukov via cfe-commits
Sorry about that, `diff -b` seems to work. Restored commit and changed to
`diff -b` in r315287.
Thanks for spotting and reverting this.

On Mon, Oct 9, 2017 at 8:45 PM, Bruno Cardoso Lopes  wrote:

> Hi,
>
> On Mon, Oct 9, 2017 at 9:58 AM, Ilya Biryukov via cfe-commits
>  wrote:
> > Author: ibiryukov
> > Date: Mon Oct  9 09:58:16 2017
> > New Revision: 315214
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=315214&view=rev
> > Log:
> > [clangd] Added a command-line arg to mirror clangd input into a file.
> >
> > Summary: The arg is useful for debugging and creating test cases.
> >
> > Reviewers: bkramer, krasimir
> >
> > Reviewed By: bkramer
> >
> > Subscribers: klimek, cfe-commits
> >
> > Differential Revision: https://reviews.llvm.org/D37970
> >
> > Added:
> > clang-tools-extra/trunk/test/clangd/input-mirror.test
> > Modified:
> > clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
> > clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
> > clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
> >
> > Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/
> JSONRPCDispatcher.cpp?rev=315214&r1=315213&r2=315214&view=diff
> > 
> ==
> > --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
> > +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Mon Oct  9
> 09:58:16 2017
> > @@ -37,6 +37,14 @@ void JSONOutput::log(const Twine &Messag
> >Logs.flush();
> >  }
> >
> > +void JSONOutput::mirrorInput(const Twine &Message) {
> > +  if (!InputMirror)
> > +return;
> > +
> > +  *InputMirror << Message;
> > +  InputMirror->flush();
> > +}
> > +
> >  void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef
> ID) {
> >Output.log("Method ignored.\n");
> >// Return that this method is unsupported.
> > @@ -147,6 +155,14 @@ void clangd::runLanguageServerLoop(std::
> >  continue;
> >}
> >
> > +  Out.mirrorInput(Line);
> > +  // Mirror '\n' that gets consumed by std::getline, but is not
> included in
> > +  // the resulting Line.
> > +  // Note that '\r' is part of Line, so we don't need to mirror it
> > +  // separately.
> > +  if (!In.eof())
> > +Out.mirrorInput("\n");
> > +
> >llvm::StringRef LineRef(Line);
> >
> >// We allow YAML-style comments in headers. Technically this
> isn't part
> > @@ -163,9 +179,8 @@ void clangd::runLanguageServerLoop(std::
> >if (LineRef.consume_front("Content-Length: ")) {
> >  if (ContentLength != 0) {
> >Out.log("Warning: Duplicate Content-Length header received. "
> > -  "The previous value for this message ("
> > -  + std::to_string(ContentLength)
> > -  + ") was ignored.\n");
> > +  "The previous value for this message (" +
> > +  std::to_string(ContentLength) + ") was ignored.\n");
> >  }
> >
> >  llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
> > @@ -185,15 +200,13 @@ void clangd::runLanguageServerLoop(std::
> >// parser.
> >std::vector JSON(ContentLength + 1, '\0');
> >In.read(JSON.data(), ContentLength);
> > +  Out.mirrorInput(StringRef(JSON.data(), In.gcount()));
> >
> >// If the stream is aborted before we read ContentLength bytes, In
> >// will have eofbit and failbit set.
> >if (!In) {
> > -Out.log("Input was aborted. Read only "
> > -+ std::to_string(In.gcount())
> > -+ " bytes of expected "
> > -+ std::to_string(ContentLength)
> > -+ ".\n");
> > +Out.log("Input was aborted. Read only " +
> std::to_string(In.gcount()) +
> > +" bytes of expected " + std::to_string(ContentLength) +
> ".\n");
> >  break;
> >}
> >
> > @@ -209,8 +222,8 @@ void clangd::runLanguageServerLoop(std::
> >if (IsDone)
> >  break;
> >  } else {
> > -  Out.log( "Warning: Missing Con

[clang-tools-extra] r315317 - [clangd] clang-format the source code. NFC.

2017-10-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Oct 10 07:21:04 2017
New Revision: 315317

URL: http://llvm.org/viewvc/llvm-project?rev=315317&view=rev
Log:
[clangd] clang-format the source code. NFC.

Modified:
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=315317&r1=315316&r2=315317&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Tue Oct 10 
07:21:04 2017
@@ -40,7 +40,7 @@ tooling::CompileCommand getDefaultCompil
 DirectoryBasedGlobalCompilationDatabase::
 DirectoryBasedGlobalCompilationDatabase(
 clangd::Logger &Logger, llvm::Optional CompileCommandsDir)
-: Logger(Logger), CompileCommandsDir(std::move(CompileCommandsDir)) {}
+: Logger(Logger), CompileCommandsDir(std::move(CompileCommandsDir)) {}
 
 std::vector
 DirectoryBasedGlobalCompilationDatabase::getCompileCommands(PathRef File) {

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=315317&r1=315316&r2=315317&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Tue Oct 10 07:21:04 2017
@@ -182,7 +182,8 @@ std::string Location::unparse(const Loca
 }
 
 llvm::Optional
-TextDocumentItem::parse(llvm::yaml::MappingNode *Params, clangd::Logger 
&Logger) {
+TextDocumentItem::parse(llvm::yaml::MappingNode *Params,
+clangd::Logger &Logger) {
   TextDocumentItem Result;
   for (auto &NextKeyValue : *Params) {
 auto *KeyString = dyn_cast(NextKeyValue.getKey());
@@ -552,7 +553,8 @@ TextDocumentContentChangeEvent::parse(ll
 }
 
 llvm::Optional
-FormattingOptions::parse(llvm::yaml::MappingNode *Params, clangd::Logger 
&Logger) {
+FormattingOptions::parse(llvm::yaml::MappingNode *Params,
+ clangd::Logger &Logger) {
   FormattingOptions Result;
   for (auto &NextKeyValue : *Params) {
 auto *KeyString = dyn_cast(NextKeyValue.getKey());
@@ -767,7 +769,8 @@ llvm::Optional Diagnostic::p
 }
 
 llvm::Optional
-CodeActionContext::parse(llvm::yaml::MappingNode *Params, clangd::Logger 
&Logger) {
+CodeActionContext::parse(llvm::yaml::MappingNode *Params,
+ clangd::Logger &Logger) {
   CodeActionContext Result;
   for (auto &NextKeyValue : *Params) {
 auto *KeyString = dyn_cast(NextKeyValue.getKey());
@@ -800,7 +803,8 @@ CodeActionContext::parse(llvm::yaml::Map
 }
 
 llvm::Optional
-CodeActionParams::parse(llvm::yaml::MappingNode *Params, clangd::Logger 
&Logger) {
+CodeActionParams::parse(llvm::yaml::MappingNode *Params,
+clangd::Logger &Logger) {
   CodeActionParams Result;
   for (auto &NextKeyValue : *Params) {
 auto *KeyString = dyn_cast(NextKeyValue.getKey());

Modified: clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp?rev=315317&r1=315316&r2=315317&view=diff
==
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp (original)
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp Tue Oct 10 07:21:04 2017
@@ -265,8 +265,8 @@ private:
 } // namespace
 
 void clangd::registerCallbackHandlers(JSONRPCDispatcher &Dispatcher,
- JSONOutput &Out,
- ProtocolCallbacks &Callbacks) {
+  JSONOutput &Out,
+  ProtocolCallbacks &Callbacks) {
   Dispatcher.registerHandler(
   "initialize", llvm::make_unique(Out, Callbacks));
   Dispatcher.registerHandler(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r315324 - [clangd] Added missing #includes to Function.h

2017-10-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Oct 10 09:12:50 2017
New Revision: 315324

URL: http://llvm.org/viewvc/llvm-project?rev=315324&view=rev
Log:
[clangd] Added missing #includes to Function.h

Modified:
clang-tools-extra/trunk/clangd/Function.h

Modified: clang-tools-extra/trunk/clangd/Function.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Function.h?rev=315324&r1=315323&r2=315324&view=diff
==
--- clang-tools-extra/trunk/clangd/Function.h (original)
+++ clang-tools-extra/trunk/clangd/Function.h Tue Oct 10 09:12:50 2017
@@ -14,6 +14,9 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FUNCTION_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FUNCTION_H
 
+#include "llvm/ADT/STLExtras.h"
+#include 
+#include 
 #include 
 #include 
 #include 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r315323 - [clangd] Added forgotten return in UniqueFunction.

2017-10-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Oct 10 09:12:47 2017
New Revision: 315323

URL: http://llvm.org/viewvc/llvm-project?rev=315323&view=rev
Log:
[clangd] Added forgotten return in UniqueFunction.

This hasn't bitten us because we only used functions returning
'void'.

Modified:
clang-tools-extra/trunk/clangd/Function.h

Modified: clang-tools-extra/trunk/clangd/Function.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Function.h?rev=315323&r1=315322&r2=315323&view=diff
==
--- clang-tools-extra/trunk/clangd/Function.h (original)
+++ clang-tools-extra/trunk/clangd/Function.h Tue Oct 10 09:12:47 2017
@@ -46,7 +46,7 @@ public:
 
   Ret operator()(Args... As) {
 assert(CallablePtr);
-CallablePtr->Call(std::forward(As)...);
+return CallablePtr->Call(std::forward(As)...);
   }
 
 private:


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r315325 - [clangd] Use UniqueFunction for deferred computations.

2017-10-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Oct 10 09:12:54 2017
New Revision: 315325

URL: http://llvm.org/viewvc/llvm-project?rev=315325&view=rev
Log:
[clangd] Use UniqueFunction for deferred computations.

Previsouly, `std::future` that were results of
`std::async(std::launch::deferred, ...` were used.

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=315325&r1=315324&r2=315325&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Oct 10 09:12:54 2017
@@ -413,8 +413,9 @@ std::future ClangdServer::schedule
 Tagged> TaggedFS) {
 
   assert(Contents.Draft && "Draft must have contents");
-  std::future>> DeferredRebuild =
-  Resources->deferRebuild(*Contents.Draft, TaggedFS.Value);
+  UniqueFunction>()>
+  DeferredRebuild =
+  Resources->deferRebuild(*Contents.Draft, TaggedFS.Value);
   std::promise DonePromise;
   std::future DoneFuture = DonePromise.get_future();
 
@@ -423,7 +424,7 @@ std::future ClangdServer::schedule
   VFSTag Tag = TaggedFS.Tag;
   auto ReparseAndPublishDiags =
   [this, FileStr, Version,
-   Tag](std::future>>
+   Tag](UniqueFunction>()>
 DeferredRebuild,
 std::promise DonePromise) -> void {
 FulfillPromiseGuard Guard(DonePromise);
@@ -432,7 +433,7 @@ std::future ClangdServer::schedule
 if (CurrentVersion != Version)
   return; // This request is outdated
 
-auto Diags = DeferredRebuild.get();
+auto Diags = DeferredRebuild();
 if (!Diags)
   return; // A new reparse was requested before this one completed.
 
@@ -467,11 +468,11 @@ ClangdServer::scheduleCancelRebuild(std:
 return DoneFuture;
   }
 
-  std::future DeferredCancel = Resources->deferCancelRebuild();
+  UniqueFunction DeferredCancel = Resources->deferCancelRebuild();
   auto CancelReparses = [Resources](std::promise DonePromise,
-std::future DeferredCancel) {
+UniqueFunction DeferredCancel) {
 FulfillPromiseGuard Guard(DonePromise);
-DeferredCancel.get();
+DeferredCancel();
   };
   WorkScheduler.addToFront(std::move(CancelReparses), std::move(DonePromise),
std::move(DeferredCancel));

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=315325&r1=315324&r2=315325&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Oct 10 09:12:54 2017
@@ -1121,9 +1121,9 @@ CppFile::CppFile(PathRef FileName, tooli
   ASTFuture = ASTPromise.get_future();
 }
 
-void CppFile::cancelRebuild() { deferCancelRebuild().get(); }
+void CppFile::cancelRebuild() { deferCancelRebuild()(); }
 
-std::future CppFile::deferCancelRebuild() {
+UniqueFunction CppFile::deferCancelRebuild() {
   std::unique_lock Lock(Mutex);
   // Cancel an ongoing rebuild, if any, and wait for it to finish.
   unsigned RequestRebuildCounter = ++this->RebuildCounter;
@@ -1143,7 +1143,7 @@ std::future CppFile::deferCancelRe
   RebuildCond.notify_all();
 
   std::shared_ptr That = shared_from_this();
-  return std::async(std::launch::deferred, [That, RequestRebuildCounter]() {
+  return [That, RequestRebuildCounter]() {
 std::unique_lock Lock(That->Mutex);
 CppFile *This = &*That;
 This->RebuildCond.wait(Lock, [This, RequestRebuildCounter]() {
@@ -1158,16 +1158,16 @@ std::future CppFile::deferCancelRe
 // Set empty results for Promises.
 That->PreamblePromise.set_value(nullptr);
 That->ASTPromise.set_value(std::make_shared(llvm::None));
-  });
+  };
 }
 
 llvm::Optional>
 CppFile::rebuild(StringRef NewContents,
  IntrusiveRefCntPtr VFS) {
-  return deferRebuild(NewContents, std::move(VFS)).get();
+  return deferRebuild(NewContents, std::move(VFS))();
 }
 
-std::future>>
+UniqueFunction>()>
 CppFile::deferRebuild(StringRef NewContents,
   IntrusiveRefCntPtr VFS) {
   std::shared_ptr OldPreamble;
@@ -1315,7 +1315,7 @@ CppFile::deferRebuild(StringRef NewConte
 return Diagnostics;
   };
 
-  return std::async(std::launch::deferred, FinishRebuild, NewContents.str());
+  return BindWithForward(FinishRebuild, NewContents.str());
 }
 
 std::shared_future>

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=315325&r1=315324&r2=315325&view=diff
=

[clang-tools-extra] r316311 - [clangd] Report proper kinds for 'Keyword' and 'Snippet' completion items.

2017-10-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Sun Oct 22 23:06:21 2017
New Revision: 316311

URL: http://llvm.org/viewvc/llvm-project?rev=316311&view=rev
Log:
[clangd] Report proper kinds for 'Keyword' and 'Snippet' completion items.

Reviewers: rwols, malaperle, krasimir, bkramer, sammccall

Reviewed By: rwols, sammccall

Subscribers: klimek, cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=316311&r1=316310&r2=316311&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Sun Oct 22 23:06:21 2017
@@ -268,8 +268,8 @@ template  bool futureIsReady(st
 
 namespace {
 
-CompletionItemKind getKind(CXCursorKind K) {
-  switch (K) {
+CompletionItemKind getKindOfDecl(CXCursorKind CursorKind) {
+  switch (CursorKind) {
   case CXCursor_MacroInstantiation:
   case CXCursor_MacroDefinition:
 return CompletionItemKind::Text;
@@ -311,6 +311,22 @@ CompletionItemKind getKind(CXCursorKind
   }
 }
 
+CompletionItemKind getKind(CodeCompletionResult::ResultKind ResKind,
+   CXCursorKind CursorKind) {
+  switch (ResKind) {
+  case CodeCompletionResult::RK_Declaration:
+return getKindOfDecl(CursorKind);
+  case CodeCompletionResult::RK_Keyword:
+return CompletionItemKind::Keyword;
+  case CodeCompletionResult::RK_Macro:
+return CompletionItemKind::Text; // unfortunately, there's no 'Macro'
+ // completion items in LSP.
+  case CodeCompletionResult::RK_Pattern:
+return CompletionItemKind::Snippet;
+  }
+  llvm_unreachable("Unhandled CodeCompletionResult::ResultKind.");
+}
+
 std::string escapeSnippet(const llvm::StringRef Text) {
   std::string Result;
   Result.reserve(Text.size()); // Assume '$', '}' and '\\' are rare.
@@ -395,7 +411,7 @@ private:
 ProcessChunks(CCS, Item);
 
 // Fill in the kind field of the CompletionItem.
-Item.kind = getKind(Result.CursorKind);
+Item.kind = getKind(Result.Kind, Result.CursorKind);
 
 FillSortText(CCS, Item);
 

Added: clang-tools-extra/trunk/test/clangd/completion-items-kinds.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion-items-kinds.test?rev=316311&view=auto
==
--- clang-tools-extra/trunk/test/clangd/completion-items-kinds.test (added)
+++ clang-tools-extra/trunk/test/clangd/completion-items-kinds.test Sun Oct 22 
23:06:21 2017
@@ -0,0 +1,37 @@
+# RUN: clangd -enable-snippets -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+Content-Length: 220
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"#define
 MACRO X\nint variable;\nstruct Struct {};\n int function();\nint X = "}}}
+Content-Length: 148
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":4,"character":7}}}
+Content-Length: 58
+# CHECK: {"jsonrpc":"2.0","id":1,"result":[
+#
+# Keyword
+# CHECK-DAG: 
{"label":"int","kind":14,"sortText":"50int","filterText":"int","insertText":"int","insertTextFormat":1}
+#
+# Code pattern
+# CHECK-DAG: 
{"label":"static_cast(expression)","kind":15,"sortText":"40static_cast","filterText":"static_cast","insertText":"static_cast<${1:type}>(${2:expression})","insertTextFormat":2}
+#
+# Struct
+# CHECK-DAG: 
{"label":"Struct","kind":7,"sortText":"50Struct","filterText":"Struct","insertText":"Struct","insertTextFormat":1}
+#
+# Macro
+# CHECK-DAG: 
{"label":"MACRO","kind":1,"sortText":"70MACRO","filterText":"MACRO","insertText":"MACRO","insertTextFormat":1}
+#
+# Variable
+# CHECK-DAG: 
{"label":"variable","kind":6,"detail":"int","sortText":"12variable","filterText":"variable","insertText":"variable","insertTextFormat":1}
+#
+# Function
+# CHECK-DAG: 
{"label":"function()","kind":3,"detail":"int","sortText":"12function","filterText":"function","insertText":"function()","insertTextFormat":1}
+#
+#
+# CHECK: ]}
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown","params":null}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r315323 - [clangd] Added forgotten return in UniqueFunction.

2017-10-23 Thread Ilya Biryukov via cfe-commits
Sorry for late response, was on vacation.

The following commit (r315325) adds code coverage for this case.
But you are correct, we were missing usages of the class with non-void
return type before that.


On Mon, Oct 16, 2017 at 7:12 PM, David Blaikie  wrote:

> Is there missing test coverage for this?
>
> On Tue, Oct 10, 2017 at 9:12 AM Ilya Biryukov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: ibiryukov
>> Date: Tue Oct 10 09:12:47 2017
>> New Revision: 315323
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=315323&view=rev
>> Log:
>> [clangd] Added forgotten return in UniqueFunction.
>>
>> This hasn't bitten us because we only used functions returning
>> 'void'.
>>
>> Modified:
>> clang-tools-extra/trunk/clangd/Function.h
>>
>> Modified: clang-tools-extra/trunk/clangd/Function.h
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
>> trunk/clangd/Function.h?rev=315323&r1=315322&r2=315323&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/clangd/Function.h (original)
>> +++ clang-tools-extra/trunk/clangd/Function.h Tue Oct 10 09:12:47 2017
>> @@ -46,7 +46,7 @@ public:
>>
>>Ret operator()(Args... As) {
>>  assert(CallablePtr);
>> -CallablePtr->Call(std::forward(As)...);
>> +return CallablePtr->Call(std::forward(As)...);
>>}
>>
>>  private:
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>


-- 
Regards,
Ilya Biryukov
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r316323 - [clangd] Updated outdated test comment. NFC.

2017-10-23 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Oct 23 07:08:52 2017
New Revision: 316323

URL: http://llvm.org/viewvc/llvm-project?rev=316323&view=rev
Log:
[clangd] Updated outdated test comment. NFC.

Modified:
clang-tools-extra/trunk/test/clangd/input-mirror.test

Modified: clang-tools-extra/trunk/test/clangd/input-mirror.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/input-mirror.test?rev=316323&r1=316322&r2=316323&view=diff
==
--- clang-tools-extra/trunk/test/clangd/input-mirror.test (original)
+++ clang-tools-extra/trunk/test/clangd/input-mirror.test Mon Oct 23 07:08:52 
2017
@@ -1,5 +1,5 @@
 # RUN: clangd -run-synchronously -input-mirror-file %t < %s
-# Note that we have to use '-Z' as -input-mirror-file does not have a newline 
at the end of file.
+# Note that we have to use '-b' as -input-mirror-file does not have a newline 
at the end of file.
 # RUN: diff -b %t %s
 # It is absolutely vital that this file has CRLF line endings.
 #


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r315287 - Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"

2017-10-23 Thread Ilya Biryukov via cfe-commits
Missed that, will do, thanks.

On Wed, Oct 11, 2017 at 1:39 AM, Bruno Cardoso Lopes <
bruno.card...@gmail.com> wrote:

> On Tue, Oct 10, 2017 at 2:08 AM, Ilya Biryukov via cfe-commits
>  wrote:
> > Author: ibiryukov
> > Date: Tue Oct 10 02:08:47 2017
> > New Revision: 315287
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=315287&view=rev
> > Log:
> > Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"
> >
> > This reverts commit r315242 and restores r315214.
> >
> > To fix original failure, replaced non-portable `diff -Z` with portable
> > alternative: `diff -b`.
> >
> > Added:
> > clang-tools-extra/trunk/test/clangd/input-mirror.test
> > Modified:
> > clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
> > clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
> > clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
> >
> > Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
> > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/
> JSONRPCDispatcher.cpp?rev=315287&r1=315286&r2=315287&view=diff
> > 
> ==
> > --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
> > +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Oct 10
> 02:08:47 2017
> > @@ -37,6 +37,14 @@ void JSONOutput::log(const Twine &Messag
> >Logs.flush();
> >  }
> >
> > +void JSONOutput::mirrorInput(const Twine &Message) {
> > +  if (!InputMirror)
> > +return;
> > +
> > +  *InputMirror << Message;
> > +  InputMirror->flush();
> > +}
> > +
> >  void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef
> ID) {
> >Output.log("Method ignored.\n");
> >// Return that this method is unsupported.
> > @@ -147,6 +155,14 @@ void clangd::runLanguageServerLoop(std::
> >  continue;
> >}
> >
> > +  Out.mirrorInput(Line);
> > +  // Mirror '\n' that gets consumed by std::getline, but is not
> included in
> > +  // the resulting Line.
> > +  // Note that '\r' is part of Line, so we don't need to mirror it
> > +  // separately.
> > +  if (!In.eof())
> > +Out.mirrorInput("\n");
> > +
> >llvm::StringRef LineRef(Line);
> >
> >// We allow YAML-style comments in headers. Technically this
> isn't part
> > @@ -163,9 +179,8 @@ void clangd::runLanguageServerLoop(std::
> >if (LineRef.consume_front("Content-Length: ")) {
> >  if (ContentLength != 0) {
> >Out.log("Warning: Duplicate Content-Length header received. "
> > -  "The previous value for this message ("
> > -  + std::to_string(ContentLength)
> > -  + ") was ignored.\n");
> > +  "The previous value for this message (" +
> > +  std::to_string(ContentLength) + ") was ignored.\n");
> >  }
> >
> >  llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
> > @@ -185,15 +200,13 @@ void clangd::runLanguageServerLoop(std::
> >// parser.
> >std::vector JSON(ContentLength + 1, '\0');
> >In.read(JSON.data(), ContentLength);
> > +  Out.mirrorInput(StringRef(JSON.data(), In.gcount()));
> >
> >// If the stream is aborted before we read ContentLength bytes, In
> >// will have eofbit and failbit set.
> >if (!In) {
> > -Out.log("Input was aborted. Read only "
> > -+ std::to_string(In.gcount())
> > -+ " bytes of expected "
> > -+ std::to_string(ContentLength)
> > -+ ".\n");
> > +Out.log("Input was aborted. Read only " +
> std::to_string(In.gcount()) +
> > +" bytes of expected " + std::to_string(ContentLength) +
> ".\n");
> >  break;
> >}
> >
> > @@ -209,8 +222,8 @@ void clangd::runLanguageServerLoop(std::
> >if (IsDone)
> >  break;
> >  } else {
> > -  Out.log( "Warning: Missing Content-Length header, or message has
> zero "
> > -   "length.\n" );
> > +  Out.log("Warning: Missing Content-Length header, or m

[clang-tools-extra] r316327 - [clangd] Allow to pass code completion opts to ClangdServer.

2017-10-23 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Oct 23 07:46:48 2017
New Revision: 316327

URL: http://llvm.org/viewvc/llvm-project?rev=316327&view=rev
Log:
[clangd] Allow to pass code completion opts to ClangdServer.

Reviewers: bkramer, krasimir, sammccall

Reviewed By: krasimir

Subscribers: klimek, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=316327&r1=316326&r2=316327&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Oct 23 07:46:48 2017
@@ -193,7 +193,9 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
  llvm::Optional CompileCommandsDir)
 : Out(Out), CDB(/*Logger=*/Out, std::move(CompileCommandsDir)),
   Server(CDB, /*DiagConsumer=*/*this, FSProvider, AsyncThreadsCount,
- SnippetCompletions, /*Logger=*/Out, ResourceDir) {}
+ clangd::CodeCompleteOptions(
+ /*EnableSnippetsAndCodePatterns=*/SnippetCompletions),
+ /*Logger=*/Out, ResourceDir) {}
 
 void ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=316327&r1=316326&r2=316327&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Oct 23 07:46:48 2017
@@ -144,15 +144,15 @@ ClangdScheduler::~ClangdScheduler() {
 ClangdServer::ClangdServer(GlobalCompilationDatabase &CDB,
DiagnosticsConsumer &DiagConsumer,
FileSystemProvider &FSProvider,
-   unsigned AsyncThreadsCount, bool SnippetCompletions,
+   unsigned AsyncThreadsCount,
+   clangd::CodeCompleteOptions CodeCompleteOpts,
clangd::Logger &Logger,
llvm::Optional ResourceDir)
 : Logger(Logger), CDB(CDB), DiagConsumer(DiagConsumer),
   FSProvider(FSProvider),
   ResourceDir(ResourceDir ? ResourceDir->str() : getStandardResourceDir()),
   PCHs(std::make_shared()),
-  SnippetCompletions(SnippetCompletions), WorkScheduler(AsyncThreadsCount) 
{
-}
+  CodeCompleteOpts(CodeCompleteOpts), WorkScheduler(AsyncThreadsCount) {}
 
 void ClangdServer::setRootPath(PathRef RootPath) {
   std::string NewRootPath = llvm::sys::path::convert_to_slash(
@@ -237,7 +237,7 @@ ClangdServer::codeComplete(PathRef File,
 std::vector Result = clangd::codeComplete(
 File, Resources->getCompileCommand(),
 Preamble ? &Preamble->Preamble : nullptr, Contents, Pos, 
TaggedFS.Value,
-PCHs, SnippetCompletions, Logger);
+PCHs, CodeCompleteOpts, Logger);
 return make_tagged(std::move(Result), std::move(TaggedFS.Tag));
   });
 

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=316327&r1=316326&r2=316327&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Oct 23 07:46:48 2017
@@ -209,7 +209,8 @@ public:
   ClangdServer(GlobalCompilationDatabase &CDB,
DiagnosticsConsumer &DiagConsumer,
FileSystemProvider &FSProvider, unsigned AsyncThreadsCount,
-   bool SnippetCompletions, clangd::Logger &Logger,
+   clangd::CodeCompleteOptions CodeCompleteOpts,
+   clangd::Logger &Logger,
llvm::Optional ResourceDir = llvm::None);
 
   /// Set the root path of the workspace.
@@ -309,7 +310,7 @@ private:
   // If set, this represents the workspace path.
   llvm::Optional RootPath;
   std::shared_ptr PCHs;
-  bool SnippetCompletions;
+  clangd::CodeCompleteOptions CodeCompleteOpts;
   /// Used to serialize diagnostic callbacks.
   /// FIXME(ibiryukov): get rid of an extra map and put all version counters
   /// into CppFile.

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=316327&r1=316326&r2=316327&view=diff

[clang-tools-extra] r316564 - [clangd] Handle exit notification (proper shutdown)

2017-10-25 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Oct 25 01:45:41 2017
New Revision: 316564

URL: http://llvm.org/viewvc/llvm-project?rev=316564&view=rev
Log:
[clangd] Handle exit notification (proper shutdown)

Summary:
This changes the onShutdown handler to do essentially nothing (for now), and
instead exits the runloop when we receive the exit notification from the client.

Some clients may wait on the reply from the shutdown request before sending an
exit notification. If we exit the runloop already in the shutdown request, a
client might block forever.

This also gives us the opportunity to do any global cleanups and/or
serializations of PCH preambles to disk, but I've left that out for now.

See the LSP protocol documentation for details.

Reviewers: malaperle, krasimir, bkramer, sammccall, ilya-biryukov

Reviewed By: malaperle, sammccall, ilya-biryukov

Subscribers: cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/shutdown-with-exit.test
clang-tools-extra/trunk/test/clangd/shutdown-without-exit.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/test/clangd/authority-less-uri.test
clang-tools-extra/trunk/test/clangd/completion-priorities.test
clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
clang-tools-extra/trunk/test/clangd/completion-snippet.test
clang-tools-extra/trunk/test/clangd/completion.test
clang-tools-extra/trunk/test/clangd/definitions.test
clang-tools-extra/trunk/test/clangd/diagnostics-preamble.test
clang-tools-extra/trunk/test/clangd/diagnostics.test
clang-tools-extra/trunk/test/clangd/did-change-watch-files.test
clang-tools-extra/trunk/test/clangd/extra-flags.test
clang-tools-extra/trunk/test/clangd/fixits.test
clang-tools-extra/trunk/test/clangd/formatting.test
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test
clang-tools-extra/trunk/test/clangd/input-mirror.test
clang-tools-extra/trunk/test/clangd/protocol.test
clang-tools-extra/trunk/test/clangd/signature-help.test
clang-tools-extra/trunk/test/clangd/unsupported-method.test

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=316564&r1=316563&r2=316564&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Oct 25 01:45:41 2017
@@ -56,9 +56,13 @@ void ClangdLSPServer::onInitialize(Ctx C
 }
 
 void ClangdLSPServer::onShutdown(Ctx C, ShutdownParams &Params) {
-  IsDone = true;
+  // Do essentially nothing, just say we're ready to exit.
+  ShutdownRequestReceived = true;
+  C.reply("null");
 }
 
+void ClangdLSPServer::onExit(Ctx C, ExitParams &Params) { IsDone = true; }
+
 void ClangdLSPServer::onDocumentDidOpen(Ctx C,
 DidOpenTextDocumentParams &Params) {
   if (Params.metadata && !Params.metadata->extraFlags.empty())
@@ -197,7 +201,7 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
  /*EnableSnippetsAndCodePatterns=*/SnippetCompletions),
  /*Logger=*/Out, ResourceDir) {}
 
-void ClangdLSPServer::run(std::istream &In) {
+bool ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");
 
   // Set up JSONRPCDispatcher.
@@ -213,6 +217,8 @@ void ClangdLSPServer::run(std::istream &
   // Make sure IsDone is set to true after this method exits to ensure 
assertion
   // at the start of the method fires if it's ever executed again.
   IsDone = true;
+
+  return ShutdownRequestReceived;
 }
 
 std::vector

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=316564&r1=316563&r2=316564&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Oct 25 01:45:41 2017
@@ -39,7 +39,9 @@ public:
   /// opened in binary mode. Output will be written using Out variable passed 
to
   /// class constructor. This method must not be executed more than once for
   /// each instance of ClangdLSPServer.
-  void run(std::istream &In);
+  ///
+  /// \return Wether we received a 'shutdown' request before an 'exit' request
+  bool run(std::istream &In);
 
 private:
   // Implement DiagnosticsConsumer.
@@ -50,6 +52,7 @@ private:
   // Implement ProtocolCallbac

[clang-tools-extra] r316565 - [clangd] Added a callback-based codeComplete in clangd.

2017-10-25 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Oct 25 02:35:10 2017
New Revision: 316565

URL: http://llvm.org/viewvc/llvm-project?rev=316565&view=rev
Log:
[clangd] Added a callback-based codeComplete in clangd.

Reviewers: klimek, bkramer, sammccall, krasimir

Reviewed By: sammccall

Subscribers: rwols, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=316565&r1=316564&r2=316565&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Oct 25 02:35:10 2017
@@ -198,6 +198,28 @@ std::future OverridenContents,
IntrusiveRefCntPtr *UsedFS) {
+  using ResultType = Tagged>;
+
+  std::promise ResultPromise;
+
+  auto Callback = [](std::promise ResultPromise,
+ ResultType Result) -> void {
+ResultPromise.set_value(std::move(Result));
+  };
+
+  std::future ResultFuture = ResultPromise.get_future();
+  codeComplete(BindWithForward(Callback, std::move(ResultPromise)), File, Pos,
+   OverridenContents, UsedFS);
+  return ResultFuture;
+}
+
+void ClangdServer::codeComplete(
+UniqueFunction>)> Callback,
+PathRef File, Position Pos, llvm::Optional OverridenContents,
+IntrusiveRefCntPtr *UsedFS) {
+  using CallbackType =
+  UniqueFunction>)>;
+
   std::string Contents;
   if (OverridenContents) {
 Contents = *OverridenContents;
@@ -216,9 +238,6 @@ ClangdServer::codeComplete(PathRef File,
   std::shared_ptr Resources = Units.getFile(File);
   assert(Resources && "Calling completion on non-added file");
 
-  using PackagedTask =
-  std::packaged_task>()>;
-
   // Remember the current Preamble and use it when async task starts executing.
   // At the point when async task starts executing, we may have a different
   // Preamble in Resources. However, we assume the Preamble that we obtain here
@@ -226,26 +245,25 @@ ClangdServer::codeComplete(PathRef File,
   std::shared_ptr Preamble =
   Resources->getPossiblyStalePreamble();
   // A task that will be run asynchronously.
-  PackagedTask Task([=]() mutable { // 'mutable' to reassign Preamble variable.
-if (!Preamble) {
-  // Maybe we built some preamble before processing this request.
-  Preamble = Resources->getPossiblyStalePreamble();
-}
-// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
-// both the old and the new version in case only one of them matches.
-
-std::vector Result = clangd::codeComplete(
-File, Resources->getCompileCommand(),
-Preamble ? &Preamble->Preamble : nullptr, Contents, Pos, 
TaggedFS.Value,
-PCHs, CodeCompleteOpts, Logger);
-return make_tagged(std::move(Result), std::move(TaggedFS.Tag));
-  });
-
-  auto Future = Task.get_future();
-  // FIXME(ibiryukov): to reduce overhead for wrapping the same callable
-  // multiple times, ClangdScheduler should return future<> itself.
-  WorkScheduler.addToFront([](PackagedTask Task) { Task(); }, std::move(Task));
-  return Future;
+  auto Task =
+  // 'mutable' to reassign Preamble variable.
+  [=](CallbackType Callback) mutable {
+if (!Preamble) {
+  // Maybe we built some preamble before processing this request.
+  Preamble = Resources->getPossiblyStalePreamble();
+}
+// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
+// both the old and the new version in case only one of them matches.
+
+std::vector Result = clangd::codeComplete(
+File, Resources->getCompileCommand(),
+Preamble ? &Preamble->Preamble : nullptr, Contents, Pos,
+TaggedFS.Value, PCHs, CodeCompleteOpts, Logger);
+
+Callback(make_tagged(std::move(Result), std::move(TaggedFS.Tag)));
+  };
+
+  WorkScheduler.addToFront(std::move(Task), std::move(Callback));
 }
 
 Tagged

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=316565&r1=316564&r2=316565&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Oct 25 02:35:10 2017
@@ -234,6 +234,9 @@ public:
   /// and AST and rebuild them from scratch.
   std::future forceReparse(PathRef File);
 
+  /// DEPRECATED. Please use a callback-based version, this API is deprecated
+  /// and will soon be removed.
+  ///
   /// Run code completion for \p File at \p Pos.
   ///
   /// Request is processed asynchronously. You can use the returned future to
@@ -253,6 +256

r340599 - [Tooling] Add a isSingleProcess() helper to ToolExecutor

2018-08-24 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Aug 24 02:03:29 2018
New Revision: 340599

URL: http://llvm.org/viewvc/llvm-project?rev=340599&view=rev
Log:
[Tooling] Add a isSingleProcess() helper to ToolExecutor

Summary:
Used in clangd's symbol builder to optimize for the common
shared-memory executor case.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: kadircet, cfe-commits

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

Modified:
cfe/trunk/include/clang/Tooling/AllTUsExecution.h
cfe/trunk/include/clang/Tooling/Execution.h
cfe/trunk/include/clang/Tooling/StandaloneExecution.h
cfe/trunk/unittests/Tooling/ExecutionTest.cpp

Modified: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/AllTUsExecution.h?rev=340599&r1=340598&r2=340599&view=diff
==
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h (original)
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h Fri Aug 24 02:03:29 2018
@@ -45,6 +45,8 @@ public:
 
   StringRef getExecutorName() const override { return ExecutorName; }
 
+  bool isSingleProcess() const override { return true; }
+
   using ToolExecutor::execute;
 
   llvm::Error

Modified: cfe/trunk/include/clang/Tooling/Execution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Execution.h?rev=340599&r1=340598&r2=340599&view=diff
==
--- cfe/trunk/include/clang/Tooling/Execution.h (original)
+++ cfe/trunk/include/clang/Tooling/Execution.h Fri Aug 24 02:03:29 2018
@@ -114,6 +114,13 @@ public:
   /// Returns the name of a specific executor.
   virtual StringRef getExecutorName() const = 0;
 
+  /// Should return true iff executor runs all actions in a single process.
+  /// Clients can use this signal to find out if they can collect results
+  /// in-memory (e.g. to avoid serialization costs of using ToolResults).
+  /// The single-process executors can still run multiple threads, but all
+  /// executions are guaranteed to share the same memory.
+  virtual bool isSingleProcess() const = 0;
+
   /// Executes each action with a corresponding arguments adjuster.
   virtual llvm::Error
   execute(llvm::ArrayRef<

Modified: cfe/trunk/include/clang/Tooling/StandaloneExecution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/StandaloneExecution.h?rev=340599&r1=340598&r2=340599&view=diff
==
--- cfe/trunk/include/clang/Tooling/StandaloneExecution.h (original)
+++ cfe/trunk/include/clang/Tooling/StandaloneExecution.h Fri Aug 24 02:03:29 
2018
@@ -52,6 +52,8 @@ public:
 
   StringRef getExecutorName() const override { return ExecutorName; }
 
+  bool isSingleProcess() const override { return true; }
+
   using ToolExecutor::execute;
 
   llvm::Error

Modified: cfe/trunk/unittests/Tooling/ExecutionTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ExecutionTest.cpp?rev=340599&r1=340598&r2=340599&view=diff
==
--- cfe/trunk/unittests/Tooling/ExecutionTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/ExecutionTest.cpp Fri Aug 24 02:03:29 2018
@@ -96,6 +96,8 @@ public:
 
   StringRef getExecutorName() const override { return ExecutorName; }
 
+  bool isSingleProcess() const override { return true; }
+
   llvm::Error
   execute(llvm::ArrayRef,
ArgumentsAdjuster>>) override {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r340600 - [clangd] Allow to merge symbols on-the-fly in global-symbol-builder

2018-08-24 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Aug 24 02:03:54 2018
New Revision: 340600

URL: http://llvm.org/viewvc/llvm-project?rev=340600&view=rev
Log:
[clangd] Allow to merge symbols on-the-fly in global-symbol-builder

Summary:
The new mode avoids serializing and deserializing YAML.
This results in better performance and less memory usage. Reduce phase
is now almost instant.

The default is to use the old mode going through YAML serialization to
allow migrating MapReduce clients that require the old mode to operate
properly. After we migrate the clients, we can switch the default to
the new mode.

Reviewers: hokein, ioeric, kbobyrev, sammccall

Reviewed By: ioeric

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

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

Modified:

clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp

Modified: 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=340600&r1=340599&r2=340600&view=diff
==
--- 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (original)
+++ 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 Fri Aug 24 02:03:54 2018
@@ -49,9 +49,33 @@ static llvm::cl::opt Assume
"not given, such headers will have relative paths."),
 llvm::cl::init(""));
 
+static llvm::cl::opt MergeOnTheFly(
+"merge-on-the-fly",
+llvm::cl::desc(
+"Merges symbols for each processed translation unit as soon "
+"they become available. This results in a smaller memory "
+"usage and an almost instant reduce stage. Optimal for running as a "
+"standalone tool, but cannot be used with multi-process executors like 
"
+"MapReduce."),
+llvm::cl::init(true), llvm::cl::Hidden);
+
+/// Responsible for aggregating symbols from each processed file and producing
+/// the final results. All methods in this class must be thread-safe,
+/// 'consumeSymbols' may be called from multiple threads.
+class SymbolsConsumer {
+public:
+  virtual ~SymbolsConsumer() = default;
+
+  /// Consume a SymbolSlab build for a file.
+  virtual void consumeSymbols(SymbolSlab Symbols) = 0;
+  /// Produce a resulting symbol slab, by combining  occurrences of the same
+  /// symbols across translation units.
+  virtual SymbolSlab mergeResults() = 0;
+};
+
 class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
 public:
-  SymbolIndexActionFactory(tooling::ExecutionContext *Ctx) : Ctx(Ctx) {}
+  SymbolIndexActionFactory(SymbolsConsumer &Consumer) : Consumer(Consumer) {}
 
   clang::FrontendAction *create() override {
 // Wraps the index action and reports collected symbols to the execution
@@ -61,10 +85,10 @@ public:
   WrappedIndexAction(std::shared_ptr C,
  std::unique_ptr Includes,
  const index::IndexingOptions &Opts,
- tooling::ExecutionContext *Ctx)
+ SymbolsConsumer &Consumer)
   : WrapperFrontendAction(
 index::createIndexingAction(C, Opts, nullptr)),
-Ctx(Ctx), Collector(C), Includes(std::move(Includes)),
+Consumer(Consumer), Collector(C), Includes(std::move(Includes)),
 PragmaHandler(collectIWYUHeaderMaps(this->Includes.get())) {}
 
   std::unique_ptr
@@ -91,14 +115,11 @@ public:
   return;
 }
 
-auto Symbols = Collector->takeSymbols();
-for (const auto &Sym : Symbols) {
-  Ctx->reportResult(Sym.ID.str(), SymbolToYAML(Sym));
-}
+Consumer.consumeSymbols(Collector->takeSymbols());
   }
 
 private:
-  tooling::ExecutionContext *Ctx;
+  SymbolsConsumer &Consumer;
   std::shared_ptr Collector;
   std::unique_ptr Includes;
   std::unique_ptr PragmaHandler;
@@ -118,30 +139,72 @@ public:
 CollectorOpts.Includes = Includes.get();
 return new WrappedIndexAction(
 std::make_shared(std::move(CollectorOpts)),
-std::move(Includes), IndexOpts, Ctx);
+std::move(Includes), IndexOpts, Consumer);
+  }
+
+  SymbolsConsumer &Consumer;
+};
+
+/// Stashes per-file results inside ExecutionContext, merges all of them at the
+/// end. Useful for running on MapReduce infrastructure to avoid keeping 
symbols
+/// from multiple files in memory.
+class ToolExecutorConsumer : public SymbolsConsumer {
+public:
+  ToolExecutorConsumer(ToolExecutor &Executor) : Executor(Executor) {}
+
+  void consumeSymbols(SymbolSlab Symbols) override {
+for (const auto &Sym : Symbols)
+  Executor.getExecutionContext()->reportResult(Sym.ID.str(),
+   SymbolToYAML(Sym));
+  }
+
+  SymbolSlab mergeResults() overrid

[clang-tools-extra] r340815 - [clangd] Add some trace::Spans. NFC

2018-08-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Aug 28 03:57:45 2018
New Revision: 340815

URL: http://llvm.org/viewvc/llvm-project?rev=340815&view=rev
Log:
[clangd] Add some trace::Spans. NFC

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/TUScheduler.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=340815&r1=340814&r2=340815&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Aug 28 03:57:45 2018
@@ -495,6 +495,7 @@ void ClangdServer::consumeDiagnostics(Pa
 }
 
 tooling::CompileCommand ClangdServer::getCompileCommand(PathRef File) {
+  trace::Span Span("GetCompileCommand");
   llvm::Optional C = CDB.getCompileCommand(File);
   if (!C) // FIXME: Suppress diagnostics? Let the user know?
 C = CDB.getFallbackCommand(File);

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=340815&r1=340814&r2=340815&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Tue Aug 28 03:57:45 2018
@@ -417,6 +417,7 @@ void ASTWorker::update(
 // Note *AST can be still be null if buildAST fails.
 if (*AST) {
   OnUpdated((*AST)->getDiagnostics());
+  trace::Span Span("Running main AST callback");
   Callbacks.onMainAST(FileName, **AST);
   DiagsWereReported = true;
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r340816 - [clangd] Remove unused parameter. NFC

2018-08-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Aug 28 04:04:07 2018
New Revision: 340816

URL: http://llvm.org/viewvc/llvm-project?rev=340816&view=rev
Log:
[clangd] Remove unused parameter. NFC

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=340816&r1=340815&r2=340816&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Aug 28 04:04:07 2018
@@ -77,8 +77,7 @@ class DeclarationAndMacrosFinder : publi
   Preprocessor &PP;
 
 public:
-  DeclarationAndMacrosFinder(raw_ostream &OS,
- const SourceLocation &SearchedLocation,
+  DeclarationAndMacrosFinder(const SourceLocation &SearchedLocation,
  ASTContext &AST, Preprocessor &PP)
   : SearchedLocation(SearchedLocation), AST(AST), PP(PP) {}
 
@@ -163,8 +162,8 @@ struct IdentifiedSymbol {
 };
 
 IdentifiedSymbol getSymbolAtPosition(ParsedAST &AST, SourceLocation Pos) {
-  auto DeclMacrosFinder = DeclarationAndMacrosFinder(
-  llvm::errs(), Pos, AST.getASTContext(), AST.getPreprocessor());
+  auto DeclMacrosFinder = DeclarationAndMacrosFinder(Pos, AST.getASTContext(),
+ AST.getPreprocessor());
   index::IndexingOptions IndexOpts;
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
@@ -324,7 +323,7 @@ class DocumentHighlightsFinder : public
   const ASTContext &AST;
 
 public:
-  DocumentHighlightsFinder(raw_ostream &OS, ASTContext &AST, Preprocessor &PP,
+  DocumentHighlightsFinder(ASTContext &AST, Preprocessor &PP,
std::vector &Decls)
   : Decls(Decls), AST(AST) {}
   std::vector takeHighlights() {
@@ -389,7 +388,7 @@ std::vector findDocum
   std::vector SelectedDecls = Symbols.Decls;
 
   DocumentHighlightsFinder DocHighlightsFinder(
-  llvm::errs(), AST.getASTContext(), AST.getPreprocessor(), SelectedDecls);
+  AST.getASTContext(), AST.getPreprocessor(), SelectedDecls);
 
   index::IndexingOptions IndexOpts;
   IndexOpts.SystemSymbolFilter =


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r340838 - Parse compile commands lazily in InterpolatingCompilationDatabase

2018-08-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Aug 28 09:15:56 2018
New Revision: 340838

URL: http://llvm.org/viewvc/llvm-project?rev=340838&view=rev
Log:
Parse compile commands lazily in InterpolatingCompilationDatabase

Summary:
This greatly reduces the time to read 'compile_commands.json'.
For Chromium on my machine it's now 0.7 seconds vs 30 seconds before the
change.

Reviewers: sammccall, jfb

Reviewed By: sammccall

Subscribers: mgrang, jfb, cfe-commits

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

Modified:
cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Modified: cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp?rev=340838&r1=340837&r2=340838&view=diff
==
--- cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/InterpolatingCompilationDatabase.cpp Tue Aug 28 
09:15:56 2018
@@ -123,8 +123,8 @@ static types::ID foldType(types::ID Lang
 struct TransferableCommand {
   // Flags that should not apply to all files are stripped from CommandLine.
   CompileCommand Cmd;
-  // Language detected from -x or the filename.
-  types::ID Type = types::TY_INVALID;
+  // Language detected from -x or the filename. Never TY_INVALID.
+  Optional Type;
   // Standard specified by -std.
   LangStandard::Kind Std = LangStandard::lang_unspecified;
 
@@ -171,7 +171,10 @@ struct TransferableCommand {
 
 if (Std != LangStandard::lang_unspecified) // -std take precedence over -x
   Type = toType(LangStandard::getLangStandardForKind(Std).getLanguage());
-Type = foldType(Type);
+Type = foldType(*Type);
+// The contract is to store None instead of TY_INVALID.
+if (Type == types::TY_INVALID)
+  Type = llvm::None;
   }
 
   // Produce a CompileCommand for \p filename, based on this one.
@@ -181,10 +184,10 @@ struct TransferableCommand {
 bool TypeCertain;
 auto TargetType = guessType(Filename, &TypeCertain);
 // If the filename doesn't determine the language (.h), transfer with -x.
-if (!TypeCertain) {
+if (TargetType != types::TY_INVALID && !TypeCertain && Type) {
   TargetType = types::onlyPrecompileType(TargetType) // header?
-   ? types::lookupHeaderTypeForSourceType(Type)
-   : Type;
+   ? types::lookupHeaderTypeForSourceType(*Type)
+   : *Type;
   Result.CommandLine.push_back("-x");
   Result.CommandLine.push_back(types::getTypeName(TargetType));
 }
@@ -217,28 +220,31 @@ private:
   }
 };
 
-// CommandIndex does the real work: given a filename, it produces the best
-// matching TransferableCommand by matching filenames. Basic strategy:
+// Given a filename, FileIndex picks the best matching file from the underlying
+// DB. This is the proxy file whose CompileCommand will be reused. The
+// heuristics incorporate file name, extension, and directory structure.
+// Strategy:
 // - Build indexes of each of the substrings we want to look up by.
 //   These indexes are just sorted lists of the substrings.
-// - Forward requests to the inner CDB. If it fails, we must pick a proxy.
 // - Each criterion corresponds to a range lookup into the index, so we only
 //   need O(log N) string comparisons to determine scores.
-// - We then break ties among the candidates with the highest score.
-class CommandIndex {
+//
+// Apart from path proximity signals, also takes file extensions into account
+// when scoring the candidates.
+class FileIndex {
 public:
-  CommandIndex(std::vector AllCommands)
-  : Commands(std::move(AllCommands)), Strings(Arena) {
+  FileIndex(std::vector Files)
+  : OriginalPaths(std::move(Files)), Strings(Arena) {
 // Sort commands by filename for determinism (index is a tiebreaker later).
-llvm::sort(
-Commands.begin(), Commands.end(),
-[](const TransferableCommand &Left, const TransferableCommand &Right) {
-  return Left.Cmd.Filename < Right.Cmd.Filename;
-});
-for (size_t I = 0; I < Commands.size(); ++I) {
-  StringRef Path =
-  Strings.save(StringRef(Commands[I].Cmd.Filename).lower());
-  Paths.push_back({Path, I});
+llvm::sort(OriginalPaths.begin(), OriginalPaths.end());
+Paths.reserve(OriginalPaths.size());
+Types.reserve(OriginalPaths.size());
+Stems.reserve(OriginalPaths.size());
+for (size_t I = 0; I < OriginalPaths.size(); ++I) {
+  StringRef Path = Strings.save(StringRef(OriginalPaths[I]).lower());
+
+  Paths.emplace_back(Path, I);
+  Types.push_back(foldType(guessType(Path)));
   Stems.emplace_back(sys::path::stem(Path), I);
   auto Dir = ++sys::path::rbegin(Path), DirEnd = sys::path::rend(Path);
   for (int J = 0; J < DirectorySegmentsIndexed && Dir != DirEnd; +

r340937 - [Tooling] Do not restore working dir in ClangTool

2018-08-29 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Aug 29 09:35:31 2018
New Revision: 340937

URL: http://llvm.org/viewvc/llvm-project?rev=340937&view=rev
Log:
[Tooling] Do not restore working dir in ClangTool

Summary:
Resolve all relative paths before running the tool instead.

This fixes the usage of ClangTool in AllTUsExecutor. The executor will
try running multiple ClangTool instances in parallel with compile
commands that usually have the same working directory.

Changing working directory is a global operation, so we end up
changing working directory in the middle of running other actions,
which leads to spurious compile errors.

Reviewers: ioeric, sammccall

Reviewed By: ioeric

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Tooling/Tooling.h
cfe/trunk/lib/Tooling/Tooling.cpp

Modified: cfe/trunk/include/clang/Tooling/Tooling.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=340937&r1=340936&r2=340937&view=diff
==
--- cfe/trunk/include/clang/Tooling/Tooling.h (original)
+++ cfe/trunk/include/clang/Tooling/Tooling.h Wed Aug 29 09:35:31 2018
@@ -459,6 +459,10 @@ inline std::unique_ptr getAbsolutePath(vfs::FileSystem &FS,
+StringRef File);
+
 /// Changes CommandLine to contain implicit flags that would have been
 /// defined had the compiler driver been invoked through the path InvokedAs.
 ///

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=340937&r1=340936&r2=340937&view=diff
==
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Wed Aug 29 09:35:31 2018
@@ -199,7 +199,8 @@ bool runToolOnCodeWithArgs(
FileName, ToolName);
 }
 
-std::string getAbsolutePath(StringRef File) {
+llvm::Expected getAbsolutePath(vfs::FileSystem &FS,
+StringRef File) {
   StringRef RelativePath(File);
   // FIXME: Should '.\\' be accepted on Win32?
   if (RelativePath.startswith("./")) {
@@ -207,13 +208,16 @@ std::string getAbsolutePath(StringRef Fi
   }
 
   SmallString<1024> AbsolutePath = RelativePath;
-  std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath);
-  assert(!EC);
-  (void)EC;
+  if (auto EC = FS.makeAbsolute(AbsolutePath))
+return llvm::errorCodeToError(EC);
   llvm::sys::path::native(AbsolutePath);
   return AbsolutePath.str();
 }
 
+std::string getAbsolutePath(StringRef File) {
+  return llvm::cantFail(getAbsolutePath(*vfs::getRealFileSystem(), File));
+}
+
 void addTargetAndModeForProgramName(std::vector &CommandLine,
 StringRef InvokedAs) {
   if (!CommandLine.empty() && !InvokedAs.empty()) {
@@ -411,15 +415,6 @@ int ClangTool::run(ToolAction *Action) {
   // This just needs to be some symbol in the binary.
   static int StaticSymbol;
 
-  std::string InitialDirectory;
-  if (llvm::ErrorOr CWD =
-  OverlayFileSystem->getCurrentWorkingDirectory()) {
-InitialDirectory = std::move(*CWD);
-  } else {
-llvm::report_fatal_error("Cannot detect current path: " +
- Twine(CWD.getError().message()));
-  }
-
   // First insert all absolute paths into the in-memory VFS. These are global
   // for all compile commands.
   if (SeenWorkingDirectories.insert("/").second)
@@ -431,9 +426,22 @@ int ClangTool::run(ToolAction *Action) {
 
   bool ProcessingFailed = false;
   bool FileSkipped = false;
+  // Compute all absolute paths before we run any actions, as those will change
+  // the working directory.
+  std::vector AbsolutePaths;
+  AbsolutePaths.reserve(SourcePaths.size());
   for (const auto &SourcePath : SourcePaths) {
-std::string File(getAbsolutePath(SourcePath));
+auto AbsPath = getAbsolutePath(*OverlayFileSystem, SourcePath);
+if (!AbsPath) {
+  llvm::errs() << "Skipping " << SourcePath
+   << ". Error while getting an absolute path: "
+   << llvm::toString(AbsPath.takeError()) << "\n";
+  continue;
+}
+AbsolutePaths.push_back(std::move(*AbsPath));
+  }
 
+  for (llvm::StringRef File : AbsolutePaths) {
 // Currently implementations of CompilationDatabase::getCompileCommands can
 // change the state of the file system (e.g.  prepare generated headers), 
so
 // this method needs to run right before we invoke the tool, as the next
@@ -498,11 +506,6 @@ int ClangTool::run(ToolAction *Action) {
 llvm::errs() << "Error while processing " << File << ".\n";
 ProcessingFailed = true;
   }
-  // Return to the initial directory to correctly resolve next file by
-  // relative path.
-  if 
(OverlayFileSystem->setCurrentWorkingDirectory(InitialDirectory.c_str()))
-

r341063 - [CodeComplete] Report location of opening parens for signature help

2018-08-30 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Aug 30 06:08:03 2018
New Revision: 341063

URL: http://llvm.org/viewvc/llvm-project?rev=341063&view=rev
Log:
[CodeComplete] Report location of opening parens for signature help

Summary: Used in clangd.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ioeric, kadircet, cfe-commits

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

Added:
cfe/trunk/test/CodeCompletion/paren_locs.cpp
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=341063&r1=341062&r2=341063&view=diff
==
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Thu Aug 30 06:08:03 2018
@@ -1114,9 +1114,13 @@ public:
   /// \param Candidates an array of overload candidates.
   ///
   /// \param NumCandidates the number of overload candidates
+  ///
+  /// \param OpenParLoc location of the opening parenthesis of the argument
+  ///list.
   virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
- unsigned NumCandidates) {}
+ unsigned NumCandidates,
+ SourceLocation OpenParLoc) {}
   //@}
 
   /// Retrieve the allocator that will be used to allocate
@@ -1166,7 +1170,8 @@ public:
 
   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
- unsigned NumCandidates) override;
+ unsigned NumCandidates,
+ SourceLocation OpenParLoc) override;
 
   bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results) 
override;
 

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=341063&r1=341062&r2=341063&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Aug 30 06:08:03 2018
@@ -10230,9 +10230,11 @@ public:
   const VirtSpecifiers *VS = nullptr);
   void CodeCompleteBracketDeclarator(Scope *S);
   void CodeCompleteCase(Scope *S);
-  void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef Args);
+  void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef Args,
+SourceLocation OpenParLoc);
   void CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc,
-   ArrayRef Args);
+   ArrayRef Args,
+   SourceLocation OpenParLoc);
   void CodeCompleteInitializer(Scope *S, Decl *D);
   void CodeCompleteReturn(Scope *S);
   void CodeCompleteAfterIf(Scope *S);

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=341063&r1=341062&r2=341063&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Aug 30 06:08:03 2018
@@ -1911,8 +1911,10 @@ namespace {
 
 void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
OverloadCandidate *Candidates,
-   unsigned NumCandidates) override {
-  Next.ProcessOverloadCandidates(S, CurrentArg, Candidates, NumCandidates);
+   unsigned NumCandidates,
+   SourceLocation OpenParLoc) override {
+  Next.ProcessOverloadCandidates(S, CurrentArg, Candidates, NumCandidates,
+ OpenParLoc);
 }
 
 CodeCompletionAllocator &getAllocator() override {

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=341063&r1=341062&r2=341063&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Aug 30 06:08:03 2018
@@ -2304,7 +2304,7 @@ Decl *Parser::ParseDeclarationAfterDecla
 auto ConstructorCompleter = [&, ThisVar

[clang-tools-extra] r341065 - [clangd] Report position of opening paren in singature help

2018-08-30 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Aug 30 06:14:31 2018
New Revision: 341065

URL: http://llvm.org/viewvc/llvm-project?rev=341065&view=rev
Log:
[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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341065&r1=341064&r2=341065&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Aug 30 06:14:31 2018
@@ -794,7 +794,17 @@ public:
 
   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
- unsigned NumCandidates) override {
+ unsigned NumCandidates,
+ SourceLocation OpenParLoc) override {
+assert(!OpenParLoc.isInvalid());
+SourceManager &SrcMgr = S.getSourceManager();
+OpenParLoc = SrcMgr.getFileLoc(OpenParLoc);
+if (SrcMgr.isInMainFile(OpenParLoc))
+  SigHelp.argListStart = sourceLocToPosition(SrcMgr, OpenParLoc);
+else
+  elog("Location oustide main file in signature help: {0}",
+   OpenParLoc.printToString(SrcMgr));
+
 std::vector ScoredSignatures;
 SigHelp.signatures.reserve(NumCandidates);
 ScoredSignatures.reserve(NumCandidates);

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=341065&r1=341064&r2=341065&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Thu Aug 30 06:14:31 2018
@@ -828,6 +828,13 @@ struct SignatureHelp {
 
   /// The active parameter of the active signature.
   int activeParameter = 0;
+
+  /// Position of the start of the argument list, including opening paren. e.g.
+  /// foo("first arg",   "second arg",
+  ///^-argListStart   ^-cursor
+  /// This is a clangd-specific extension, it is only available via C++ API and
+  /// not currently serialized for the LSP.
+  Position argListStart;
 };
 llvm::json::Value toJSON(const SignatureHelp &);
 

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=341065&r1=341064&r2=341065&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Thu Aug 30 
06:14:31 2018
@@ -825,8 +825,7 @@ TEST(CompletionTest, IgnoreCompleteInExc
 
   EXPECT_TRUE(Results.Completions.empty());
 }
-
-SignatureHelp signatures(StringRef Text,
+SignatureHelp signatures(StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;
   if (!IndexSymbols.empty())
@@ -840,9 +839,14 @@ SignatureHelp signatures(StringRef Text,
 
   ClangdServer Server(CDB, FS, DiagConsumer, Opts);
   auto File = testPath("foo.cpp");
+  runAddDocument(Server, File, Text);
+  return cantFail(runSignatureHelp(Server, File, Point));
+}
+
+SignatureHelp signatures(StringRef Text,
+ std::vector IndexSymbols = {}) {
   Annotations Test(Text);
-  runAddDocument(Server, File, Test.code());
-  return cantFail(runSignatureHelp(Server, File, Test.point()));
+  return signatures(Test.code(), Test.point(), std::move(IndexSymbols));
 }
 
 MATCHER_P(ParamsAre, P, "") {
@@ -907,6 +911,54 @@ TEST(SignatureHelpTest, ActiveArg) {
   EXPECT_EQ(1, Results.activeParameter);
 }
 
+TEST(SignatureHelpTest, OpeningParen) {
+  llvm::StringLiteral Tests[] = {// Recursive function call.
+ R"cpp(
+int foo(int a, int b, int c);
+int main() {
+  foo(foo $p^( foo(10, 10, 10), ^ )));
+})cpp",
+ // Functional type cast.
+ R"cpp(
+struct Foo {
+  Foo(int a, int b, int c);
+};
+int main() {
+  Foo $p^( 10, ^ );
+})cpp",
+ // New expression.
+ R"cpp(
+struct Foo {
+  Foo(int a, int b, int c);
+};
+int main() {
+  new Foo $p^( 10, ^ );
+})cpp",
+ // Macro expansion.

[clang-tools-extra] r341319 - [clangd] Handle errors before checking for cancelltion

2018-09-03 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Sep  3 07:39:34 2018
New Revision: 341319

URL: http://llvm.org/viewvc/llvm-project?rev=341319&view=rev
Log:
[clangd] Handle errors before checking for cancelltion

To avoid hitting assertions in llvm::Expected destructor.

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=341319&r1=341318&r2=341319&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Sep  3 07:39:34 2018
@@ -191,11 +191,10 @@ TaskHandle ClangdServer::codeComplete(Pa
   auto Task = [PCHs, Pos, FS, CodeCompleteOpts,
this](Path File, Callback CB,
  llvm::Expected IP) {
-if (isCancelled())
-  return CB(llvm::make_error());
-
 if (!IP)
   return CB(IP.takeError());
+if (isCancelled())
+  return CB(llvm::make_error());
 
 auto PreambleData = IP->Preamble;
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r341322 - [clangd] Avoid crashes in override completions

2018-09-03 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Sep  3 08:25:27 2018
New Revision: 341322

URL: http://llvm.org/viewvc/llvm-project?rev=341322&view=rev
Log:
[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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341322&r1=341321&r2=341322&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon Sep  3 08:25:27 2018
@@ -210,7 +210,7 @@ getNonOverridenMethodCompletionResults(c
   // These are stored by name to make querying fast in the later step.
   llvm::StringMap> Overrides;
   for (auto *Method : CR->methods()) {
-if (!Method->isVirtual())
+if (!Method->isVirtual() || !Method->getIdentifier())
   continue;
 Overrides[Method->getName()].push_back(Method);
   }
@@ -221,14 +221,14 @@ getNonOverridenMethodCompletionResults(c
 if (!BR)
   continue;
 for (auto *Method : BR->methods()) {
-  if (!Method->isVirtual())
+  if (!Method->isVirtual() || !Method->getIdentifier())
 continue;
   const auto it = Overrides.find(Method->getName());
   bool IsOverriden = false;
   if (it != Overrides.end()) {
 for (auto *MD : it->second) {
   // If the method in current body is not an overload of this virtual
-  // function, that it overrides this one.
+  // function, then it overrides this one.
   if (!S->IsOverload(MD, Method, false)) {
 IsOverriden = true;
 break;

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=341322&r1=341321&r2=341322&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon Sep  3 
08:25:27 2018
@@ -1765,6 +1765,21 @@ TEST(CompletionTest, SuggestOverrides) {
 Not(Contains(Labeled("void vfunc(bool param) 
override");
 }
 
+TEST(CompletionTest, OverridesNonIdentName) {
+  // Check the completions call does not crash.
+  completions(R"cpp(
+struct Base {
+  virtual ~Base() = 0;
+  virtual operator int() = 0;
+  virtual Base& operator+(Base&) = 0;
+};
+
+struct Derived : Base {
+  ^
+};
+  )cpp");
+}
+
 TEST(SpeculateCompletionFilter, Filters) {
   Annotations F(R"cpp($bof^
   $bol^


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r341366 - Adding HardLink Support to VirtualFileSystem.

2018-09-04 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Sep  4 07:15:53 2018
New Revision: 341366

URL: http://llvm.org/viewvc/llvm-project?rev=341366&view=rev
Log:
Adding HardLink Support to VirtualFileSystem.

Summary:
Added support of creating a hardlink from one file to another file.
After a hardlink is added between two files, both file will have the same:
  1. UniqueID (inode)
  2. Size
  3. Buffer

This will bring replay of compilation closer to the actual compilation. There 
are instances where clang checks for the UniqueID of the file/header to be 
loaded which leads to a different behavior during replay as all files have 
different UniqueIDs.

Patch by Utkarsh Saxena!

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/VirtualFileSystem.h
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp

Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=341366&r1=341365&r2=341366&view=diff
==
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Tue Sep  4 07:15:53 2018
@@ -323,6 +323,7 @@ public:
 namespace detail {
 
 class InMemoryDirectory;
+class InMemoryFile;
 
 } // namespace detail
 
@@ -332,6 +333,15 @@ class InMemoryFileSystem : public FileSy
   std::string WorkingDirectory;
   bool UseNormalizedPaths = true;
 
+  /// If HardLinkTarget is non-null, a hardlink is created to the To path which
+  /// must be a file. If it is null then it adds the file as the public 
addFile.
+  bool addFile(const Twine &Path, time_t ModificationTime,
+   std::unique_ptr Buffer,
+   Optional User, Optional Group,
+   Optional Type,
+   Optional Perms,
+   const detail::InMemoryFile *HardLinkTarget);
+
 public:
   explicit InMemoryFileSystem(bool UseNormalizedPaths = true);
   ~InMemoryFileSystem() override;
@@ -348,6 +358,20 @@ public:
Optional Type = None,
Optional Perms = None);
 
+  /// Add a hard link to a file.
+  /// Here hard links are not intended to be fully equivalent to the classical
+  /// filesystem. Both the hard link and the file share the same buffer and
+  /// status (and thus have the same UniqueID). Because of this there is no way
+  /// to distinguish between the link and the file after the link has been
+  /// added.
+  ///
+  /// The To path must be an existing file or a hardlink. The From file must 
not
+  /// have been added before. The To Path must not be a directory. The From 
Node
+  /// is added as a hard link which points to the resolved file of To Node.
+  /// \return true if the above condition is satisfied and hardlink was
+  /// successfully created, false otherwise.
+  bool addHardLink(const Twine &From, const Twine &To);
+
   /// Add a buffer to the VFS with a path. The VFS does not own the buffer.
   /// If present, User, Group, Type and Perms apply to the newly-created file
   /// or directory.

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=341366&r1=341365&r2=341366&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Tue Sep  4 07:15:53 2018
@@ -16,6 +16,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
@@ -25,9 +26,9 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Config/llvm-config.h"
-#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Chrono.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -466,57 +467,68 @@ namespace vfs {
 
 namespace detail {
 
-enum InMemoryNodeKind { IME_File, IME_Directory };
+enum InMemoryNodeKind { IME_File, IME_Directory, IME_HardLink };
 
 /// The in memory file system is a tree of Nodes. Every node can either be a
-/// file or a directory.
+/// file , hardlink or a directory.
 class InMemoryNode {
-  Status Stat;
   InMemoryNodeKind Kind;
-
-protected:
-  /// Return Stat.  This should only be used for internal/debugging use.  When
-  /// clients wants the Status of this node, they should use
-  /// \p getStatus(StringRef).
-  const Status &getStatus() const { return Stat; }
+  std::string FileName;
 
 public:
-  InMemoryNode(Status Stat, InMemoryNodeKind Kind)
-  : Stat(std::mo

Re: [clang-tools-extra] r341459 - [clangd] Avoid enum class+enumValN to avoid GCC bug(?), and use consistent style.

2018-09-06 Thread Ilya Biryukov via cfe-commits
+1 for consistent style, but why not use enum class everywhere instead?

On Wed, Sep 5, 2018 at 12:41 PM Sam McCall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: sammccall
> Date: Wed Sep  5 03:39:58 2018
> New Revision: 341459
>
> URL: http://llvm.org/viewvc/llvm-project?rev=341459&view=rev
> Log:
> [clangd] Avoid enum class+enumValN to avoid GCC bug(?), and use consistent
> style.
>
> Modified:
>
> clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
> clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
>
> Modified:
> clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=341459&r1=341458&r2=341459&view=diff
>
> ==
> ---
> clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
> (original)
> +++
> clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
> Wed Sep  5 03:39:58 2018
> @@ -60,7 +60,7 @@ static llvm::cl::opt MergeOnTheFly
>  "MapReduce."),
>  llvm::cl::init(true), llvm::cl::Hidden);
>
> -enum class Format { YAML, Binary };
> +enum Format { YAML, Binary };
>  static llvm::cl::opt
>  Format("format", llvm::cl::desc("Format of the index to be written"),
> llvm::cl::values(
>
> Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=341459&r1=341458&r2=341459&view=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
> +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Wed Sep  5 03:39:58
> 2018
> @@ -36,12 +36,6 @@ static llvm::cl::opt
> llvm::cl::desc("Use experimental Dex static index."),
> llvm::cl::init(true), llvm::cl::Hidden);
>
> -namespace {
> -
> -enum class PCHStorageFlag { Disk, Memory };
> -
> -} // namespace
> -
>  static llvm::cl::opt CompileCommandsDir(
>  "compile-commands-dir",
>  llvm::cl::desc("Specify a path to look for compile_commands.json. If
> path "
> @@ -54,10 +48,7 @@ static llvm::cl::opt
> llvm::cl::init(getDefaultAsyncThreadsCount()));
>
>  // FIXME: also support "plain" style where signatures are always omitted.
> -enum CompletionStyleFlag {
> -  Detailed,
> -  Bundled,
> -};
> +enum CompletionStyleFlag { Detailed, Bundled };
>  static llvm::cl::opt CompletionStyle(
>  "completion-style",
>  llvm::cl::desc("Granularity of code completion suggestions"),
> @@ -106,6 +97,7 @@ static llvm::cl::opt Test(
>  "Intended to simplify lit tests."),
>  llvm::cl::init(false), llvm::cl::Hidden);
>
> +enum PCHStorageFlag { Disk, Memory };
>  static llvm::cl::opt PCHStorage(
>  "pch-storage",
>  llvm::cl::desc("Storing PCHs in memory increases memory usages, but
> may "
> @@ -167,7 +159,6 @@ static llvm::cl::opt YamlSymbolFil
>  llvm::cl::init(""), llvm::cl::Hidden);
>
>  enum CompileArgsFrom { LSPCompileArgs, FilesystemCompileArgs };
> -
>  static llvm::cl::opt CompileArgsFrom(
>  "compile_args_from", llvm::cl::desc("The source of compile commands"),
>  llvm::cl::values(clEnumValN(LSPCompileArgs, "lsp",
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>


-- 
Regards,
Ilya Biryukov
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r341459 - [clangd] Avoid enum class+enumValN to avoid GCC bug(?), and use consistent style.

2018-09-06 Thread Ilya Biryukov via cfe-commits
Any pointers to the GCC bug/breakage mentioned?

On Thu, Sep 6, 2018 at 11:44 AM Ilya Biryukov  wrote:

> +1 for consistent style, but why not use enum class everywhere instead?
>
> On Wed, Sep 5, 2018 at 12:41 PM Sam McCall via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: sammccall
>> Date: Wed Sep  5 03:39:58 2018
>> New Revision: 341459
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=341459&view=rev
>> Log:
>> [clangd] Avoid enum class+enumValN to avoid GCC bug(?), and use
>> consistent style.
>>
>> Modified:
>>
>> clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
>> clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
>>
>> Modified:
>> clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=341459&r1=341458&r2=341459&view=diff
>>
>> ==
>> ---
>> clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
>> (original)
>> +++
>> clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
>> Wed Sep  5 03:39:58 2018
>> @@ -60,7 +60,7 @@ static llvm::cl::opt MergeOnTheFly
>>  "MapReduce."),
>>  llvm::cl::init(true), llvm::cl::Hidden);
>>
>> -enum class Format { YAML, Binary };
>> +enum Format { YAML, Binary };
>>  static llvm::cl::opt
>>  Format("format", llvm::cl::desc("Format of the index to be written"),
>> llvm::cl::values(
>>
>> Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=341459&r1=341458&r2=341459&view=diff
>>
>> ==
>> --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Wed Sep  5
>> 03:39:58 2018
>> @@ -36,12 +36,6 @@ static llvm::cl::opt
>> llvm::cl::desc("Use experimental Dex static index."),
>> llvm::cl::init(true), llvm::cl::Hidden);
>>
>> -namespace {
>> -
>> -enum class PCHStorageFlag { Disk, Memory };
>> -
>> -} // namespace
>> -
>>  static llvm::cl::opt CompileCommandsDir(
>>  "compile-commands-dir",
>>  llvm::cl::desc("Specify a path to look for compile_commands.json. If
>> path "
>> @@ -54,10 +48,7 @@ static llvm::cl::opt
>> llvm::cl::init(getDefaultAsyncThreadsCount()));
>>
>>  // FIXME: also support "plain" style where signatures are always omitted.
>> -enum CompletionStyleFlag {
>> -  Detailed,
>> -  Bundled,
>> -};
>> +enum CompletionStyleFlag { Detailed, Bundled };
>>  static llvm::cl::opt CompletionStyle(
>>  "completion-style",
>>  llvm::cl::desc("Granularity of code completion suggestions"),
>> @@ -106,6 +97,7 @@ static llvm::cl::opt Test(
>>  "Intended to simplify lit tests."),
>>  llvm::cl::init(false), llvm::cl::Hidden);
>>
>> +enum PCHStorageFlag { Disk, Memory };
>>  static llvm::cl::opt PCHStorage(
>>  "pch-storage",
>>  llvm::cl::desc("Storing PCHs in memory increases memory usages, but
>> may "
>> @@ -167,7 +159,6 @@ static llvm::cl::opt YamlSymbolFil
>>  llvm::cl::init(""), llvm::cl::Hidden);
>>
>>  enum CompileArgsFrom { LSPCompileArgs, FilesystemCompileArgs };
>> -
>>  static llvm::cl::opt CompileArgsFrom(
>>  "compile_args_from", llvm::cl::desc("The source of compile
>> commands"),
>>  llvm::cl::values(clEnumValN(LSPCompileArgs, "lsp",
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
> --
> Regards,
> Ilya Biryukov
>


-- 
Regards,
Ilya Biryukov
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r341538 - [clangd] Fix data race in async fuzzyFind tests.

2018-09-06 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Sep  6 04:04:56 2018
New Revision: 341538

URL: http://llvm.org/viewvc/llvm-project?rev=341538&view=rev
Log:
[clangd] Fix data race in async fuzzyFind tests.

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=341538&r1=341537&r2=341538&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Thu Sep  6 
04:04:56 2018
@@ -966,6 +966,7 @@ public:
   bool
   fuzzyFind(const FuzzyFindRequest &Req,
 llvm::function_ref Callback) const override {
+std::lock_guard Lock(Mut);
 Requests.push_back(Req);
 return true;
   }
@@ -981,12 +982,15 @@ public:
   size_t estimateMemoryUsage() const override { return 0; }
 
   const std::vector consumeRequests() const {
+std::lock_guard Lock(Mut);
 auto Reqs = std::move(Requests);
 Requests = {};
 return Reqs;
   }
 
 private:
+  // We need a mutex to handle async fuzzy find requests.
+  mutable std::mutex Mut;
   mutable std::vector Requests;
 };
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r341459 - [clangd] Avoid enum class+enumValN to avoid GCC bug(?), and use consistent style.

2018-09-06 Thread Ilya Biryukov via cfe-commits
I would generally vouch for strongly typed enums, because there're nicer in
many aspects (no implicit integer conversions, no enumerators thrown into
the namespaces).
With regards to naming conventions, PCHStorage::Memory or
CompletionStyle::Bundled look pretty neat to me, the usual alternative for
enums is coming up with prefixes, e.g. PS_Memory CS_Bundled.
It's shorter, but it's hard to remember which prefix to use (without the
prefix, it's also hard to keep all enum values in your head), while the
type name is evident from signature help or completion results and
completing EnumType:: yields full list of enumerators right away.

The "Flag" suffix in the enum names seems redundant, though, I have removed
it from the examples on purpose.
WDYT?

PS BTW, we definitely need to make enumerator completions work in more
cases than switch-case at some point.




On Thu, Sep 6, 2018 at 2:11 PM Sam McCall  wrote:

> It turned out to be a different bug: the problem was referring to
> `Format::YAML` in the initializer for a variable also named `Format`.
> This is legal but old versions of GCC get this wrong.
> As usual with buildbot failures, I was throwing things at the wall to see
> what sticks.
>
> Regarding style - either would work, there were 2x enum and 2x enum class.
> My reasons for leaning towards enum here is that for this command-line
> flag pattern
>  - it mainly leads to repeating the type name in a context where the type
> is obvious
>  - there's minimal risk/consequence to a namespace conflict as we're in an
> anonymous namespace in a CC file
>  - there's often not a second good name (need one for the flag + one for
> the enum), so it's a bad name that ends up repeated
> But if you feel strongly about it, feel free to flip it.
>
> On Thu, Sep 6, 2018 at 11:45 AM Ilya Biryukov 
> wrote:
>
>> Any pointers to the GCC bug/breakage mentioned?
>>
>> On Thu, Sep 6, 2018 at 11:44 AM Ilya Biryukov 
>> wrote:
>>
>>> +1 for consistent style, but why not use enum class everywhere instead?
>>>
>>> On Wed, Sep 5, 2018 at 12:41 PM Sam McCall via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: sammccall
 Date: Wed Sep  5 03:39:58 2018
 New Revision: 341459

 URL: http://llvm.org/viewvc/llvm-project?rev=341459&view=rev
 Log:
 [clangd] Avoid enum class+enumValN to avoid GCC bug(?), and use
 consistent style.

 Modified:

 clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

 Modified:
 clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=341459&r1=341458&r2=341459&view=diff

 ==
 ---
 clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (original)
 +++
 clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 Wed Sep  5 03:39:58 2018
 @@ -60,7 +60,7 @@ static llvm::cl::opt MergeOnTheFly
  "MapReduce."),
  llvm::cl::init(true), llvm::cl::Hidden);

 -enum class Format { YAML, Binary };
 +enum Format { YAML, Binary };
  static llvm::cl::opt
  Format("format", llvm::cl::desc("Format of the index to be
 written"),
 llvm::cl::values(

 Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=341459&r1=341458&r2=341459&view=diff

 ==
 --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
 +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Wed Sep  5
 03:39:58 2018
 @@ -36,12 +36,6 @@ static llvm::cl::opt
 llvm::cl::desc("Use experimental Dex static index."),
 llvm::cl::init(true), llvm::cl::Hidden);

 -namespace {
 -
 -enum class PCHStorageFlag { Disk, Memory };
 -
 -} // namespace
 -
  static llvm::cl::opt CompileCommandsDir(
  "compile-commands-dir",
  llvm::cl::desc("Specify a path to look for compile_commands.json.
 If path "
 @@ -54,10 +48,7 @@ static llvm::cl::opt
 llvm::cl::init(getDefaultAsyncThreadsCount()));

  // FIXME: also support "plain" style where signatures are always
 omitted.
 -enum CompletionStyleFlag {
 -  Detailed,
 -  Bundled,
 -};
 +enum CompletionStyleFlag { Detailed, Bundled };
  static llvm::cl::opt CompletionStyle(
  "completion-style",
  llvm::cl::desc("Granularity of code completion suggestions"),
 @@ -106,6 +97,7 @@ static llvm::cl::opt Test(
>>>

r341660 - [CodeComplete] Clearly distinguish signature help and code completion.

2018-09-07 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Sep  7 07:04:39 2018
New Revision: 341660

URL: http://llvm.org/viewvc/llvm-project?rev=341660&view=rev
Log:
[CodeComplete] Clearly distinguish signature help and code completion.

Summary:
Code completion in clang is actually a mix of two features:
- Code completion is a familiar feature. Results are exposed via the
  CodeCompleteConsumer::ProcessCodeCompleteResults callback.
- Signature help figures out if the current expression is an argument of
  some function call and shows corresponding signatures if so.
  Results are exposed via CodeCompleteConsumer::ProcessOverloadCandidates.

This patch refactors the implementation to untangle those two from each
other and makes some naming tweaks to avoid confusion when reading the
code.

The refactoring is required for signature help fixes, see D51038.

The only intended behavior change is the order of callbacks.
ProcessOverloadCandidates is now called before ProcessCodeCompleteResults.

Reviewers: sammccall, kadircet

Reviewed By: sammccall

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/CodeCompletion/call.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=341660&r1=341659&r2=341660&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Sep  7 07:04:39 2018
@@ -10231,6 +10231,7 @@ public:
   struct CodeCompleteExpressionData;
   void CodeCompleteExpression(Scope *S,
   const CodeCompleteExpressionData &Data);
+  void CodeCompleteExpression(Scope *S, QualType PreferredType);
   void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase,
SourceLocation OpLoc, bool IsArrow,
bool IsBaseExprStatement);
@@ -10241,11 +10242,14 @@ public:
   const VirtSpecifiers *VS = nullptr);
   void CodeCompleteBracketDeclarator(Scope *S);
   void CodeCompleteCase(Scope *S);
-  void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef Args,
-SourceLocation OpenParLoc);
-  void CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc,
-   ArrayRef Args,
-   SourceLocation OpenParLoc);
+  /// Reports signatures for a call to CodeCompleteConsumer and returns the
+  /// preferred type for the current argument. Returned type can be null.
+  QualType ProduceCallSignatureHelp(Scope *S, Expr *Fn, ArrayRef Args,
+SourceLocation OpenParLoc);
+  QualType ProduceConstructorSignatureHelp(Scope *S, QualType Type,
+   SourceLocation Loc,
+   ArrayRef Args,
+   SourceLocation OpenParLoc);
   void CodeCompleteInitializer(Scope *S, Decl *D);
   void CodeCompleteReturn(Scope *S);
   void CodeCompleteAfterIf(Scope *S);

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=341660&r1=341659&r2=341660&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Sep  7 07:04:39 2018
@@ -2302,16 +2302,17 @@ Decl *Parser::ParseDeclarationAfterDecla
 llvm::function_ref ExprListCompleter;
 auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
 auto ConstructorCompleter = [&, ThisVarDecl] {
-  Actions.CodeCompleteConstructor(
+  QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
   getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
   ThisDecl->getLocation(), Exprs, T.getOpenLocation());
+  Actions.CodeCompleteExpression(getCurScope(), PreferredType);
 };
 if (ThisVarDecl) {
   // ParseExpressionList can sometimes succeed even when ThisDecl is not
   // VarDecl. This is an error and it is reported in a call to
   // Actions.ActOnInitializerError(). However, we call
-  // CodeCompleteConstructor only on VarDecls, falling back to default
-  // completer in other cases.
+  // ProduceConstructorSignatureHelp only on VarDecls, falling back to
+  // default completer in other cases.
   ExprListCompleter = ConstructorCompleter;
 }
 

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=341660&r1=341659&r2=341660&view=diff
=

r341910 - [Tooling] Restore working dir in ClangTool.

2018-09-11 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Sep 11 00:29:09 2018
New Revision: 341910

URL: http://llvm.org/viewvc/llvm-project?rev=341910&view=rev
Log:
[Tooling] Restore working dir in ClangTool.

Summary:
And add an option to disable this behavior. The option is only used in
AllTUsExecutor to avoid races when running concurrently on multiple
threads.

This fixes PR38869 introduced by r340937.

Reviewers: ioeric, steveire

Reviewed By: ioeric

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Tooling/Tooling.h
cfe/trunk/lib/Tooling/AllTUsExecution.cpp
cfe/trunk/lib/Tooling/Tooling.cpp

Modified: cfe/trunk/include/clang/Tooling/Tooling.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=341910&r1=341909&r2=341910&view=diff
==
--- cfe/trunk/include/clang/Tooling/Tooling.h (original)
+++ cfe/trunk/include/clang/Tooling/Tooling.h Tue Sep 11 00:29:09 2018
@@ -356,6 +356,11 @@ public:
   /// append them to ASTs.
   int buildASTs(std::vector> &ASTs);
 
+  /// Sets whether working directory should be restored after calling run(). By
+  /// default, working directory is restored. However, it could be useful to
+  /// turn this off when running on multiple threads to avoid the raciness.
+  void setRestoreWorkingDir(bool RestoreCWD);
+
   /// Returns the file manager used in the tool.
   ///
   /// The file manager is shared between all translation units.
@@ -380,6 +385,8 @@ private:
   ArgumentsAdjuster ArgsAdjuster;
 
   DiagnosticConsumer *DiagConsumer = nullptr;
+
+  bool RestoreCWD = true;
 };
 
 template 

Modified: cfe/trunk/lib/Tooling/AllTUsExecution.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/AllTUsExecution.cpp?rev=341910&r1=341909&r2=341910&view=diff
==
--- cfe/trunk/lib/Tooling/AllTUsExecution.cpp (original)
+++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp Tue Sep 11 00:29:09 2018
@@ -104,7 +104,12 @@ llvm::Error AllTUsToolExecutor::execute(
   {
 llvm::ThreadPool Pool(ThreadCount == 0 ? llvm::hardware_concurrency()
: ThreadCount);
-
+llvm::SmallString<128> InitialWorkingDir;
+if (auto EC = llvm::sys::fs::current_path(InitialWorkingDir)) {
+  InitialWorkingDir = "";
+  llvm::errs() << "Error while getting current working directory: "
+   << EC.message() << "\n";
+}
 for (std::string File : Files) {
   Pool.async(
   [&](std::string Path) {
@@ -116,12 +121,19 @@ llvm::Error AllTUsToolExecutor::execute(
 for (const auto &FileAndContent : OverlayFiles)
   Tool.mapVirtualFile(FileAndContent.first(),
   FileAndContent.second);
+// Do not restore working dir from multiple threads to avoid races.
+Tool.setRestoreWorkingDir(false);
 if (Tool.run(Action.first.get()))
   AppendError(llvm::Twine("Failed to run action on ") + Path +
   "\n");
   },
   File);
 }
+if (!InitialWorkingDir.empty()) {
+  if (auto EC = llvm::sys::fs::set_current_path(InitialWorkingDir))
+llvm::errs() << "Error while restoring working directory: "
+ << EC.message() << "\n";
+}
   }
 
   if (!ErrorMsg.empty())

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=341910&r1=341909&r2=341910&view=diff
==
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Tue Sep 11 00:29:09 2018
@@ -441,6 +441,17 @@ int ClangTool::run(ToolAction *Action) {
 AbsolutePaths.push_back(std::move(*AbsPath));
   }
 
+  // Remember the working directory in case we need to restore it.
+  std::string InitialWorkingDir;
+  if (RestoreCWD) {
+if (auto CWD = OverlayFileSystem->getCurrentWorkingDirectory()) {
+  InitialWorkingDir = std::move(*CWD);
+} else {
+  llvm::errs() << "Could not get working directory: "
+   << CWD.getError().message() << "\n";
+}
+  }
+
   for (llvm::StringRef File : AbsolutePaths) {
 // Currently implementations of CompilationDatabase::getCompileCommands can
 // change the state of the file system (e.g.  prepare generated headers), 
so
@@ -508,6 +519,13 @@ int ClangTool::run(ToolAction *Action) {
   }
 }
   }
+
+  if (!InitialWorkingDir.empty()) {
+if (auto EC =
+OverlayFileSystem->setCurrentWorkingDirectory(InitialWorkingDir))
+  llvm::errs() << "Error when trying to restore working dir: "
+   << EC.message() << "\n";
+  }
   return ProcessingFailed ? 1 : (FileSkipped ? 2 : 0);
 }
 
@@ -544,6 +562,10 @@ int ClangTool::buildAS

[clang-tools-extra] r342123 - [clangd] Rename global-symbol-builder to clangd-indexer.

2018-09-13 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Sep 13 02:44:11 2018
New Revision: 342123

URL: http://llvm.org/viewvc/llvm-project?rev=342123&view=rev
Log:
[clangd] Rename global-symbol-builder to clangd-indexer.

Summary:
Given that the indexer binary is put directly into ./bin directory
when built, 'clangd-' prefix seems to provide better context to the
reader than 'global-'.

The new name is also shorter and easier to type.

Reviewers: ioeric, sammccall, kadircet

Reviewed By: ioeric, sammccall

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

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

Added:
clang-tools-extra/trunk/clangd/indexer/
clang-tools-extra/trunk/clangd/indexer/CMakeLists.txt
  - copied, changed from r342052, 
clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt
clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
  - copied, changed from r342052, 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
Removed:
clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt

clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt
clang-tools-extra/trunk/test/clangd/index-tools.test

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=342123&r1=342122&r2=342123&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Sep 13 02:44:11 2018
@@ -73,7 +73,7 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_
   add_subdirectory(fuzzer)
 endif()
 add_subdirectory(tool)
-add_subdirectory(global-symbol-builder)
+add_subdirectory(indexer)
 add_subdirectory(index/dex/dexp)
 
 if (LLVM_INCLUDE_BENCHMARKS)

Removed: clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt?rev=342122&view=auto
==
--- clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt 
(removed)
@@ -1,20 +0,0 @@
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
-
-set(LLVM_LINK_COMPONENTS
-Support
-)
-
-add_clang_executable(global-symbol-builder
-  GlobalSymbolBuilderMain.cpp
-  )
-
-target_link_libraries(global-symbol-builder
-  PRIVATE
-  clangAST
-  clangIndex
-  clangDaemon
-  clangBasic
-  clangFrontend
-  clangLex
-  clangTooling
-)

Removed: 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=342122&view=auto
==
--- 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (original)
+++ 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (removed)
@@ -1,285 +0,0 @@
-//===--- GlobalSymbolBuilderMain.cpp -*- 
C++-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-//
-// GlobalSymbolBuilder is a tool to extract symbols from a whole project.
-// This tool is **experimental** only. Don't use it in production code.
-//
-//===--===//
-
-#include "RIFF.h"
-#include "index/CanonicalIncludes.h"
-#include "index/Index.h"
-#include "index/Merge.h"
-#include "index/Serialization.h"
-#include "index/SymbolCollector.h"
-#include "index/SymbolYAML.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendActions.h"
-#include "clang/Index/IndexDataConsumer.h"
-#include "clang/Index/IndexingAction.h"
-#include "clang/Tooling/CommonOptionsParser.h"
-#include "clang/Tooling/Execution.h"
-#include "clang/Tooling/Tooling.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/Signals.h"
-#include "llvm/Support/ThreadPool.h"
-#include "llvm/Support/YAMLTraits.h"
-
-using namespace llvm;
-using namespace clang::tooling;
-using clang::clangd::SymbolSlab;
-
-namespace clang {
-namespace clangd {
-namespace {
-
-static llvm::cl::opt AssumedHeaderDir(
-"assume-header-dir",
-llvm::cl::desc("The index includes header that a symbol is defined in. "
-   "If the abs

Re: r342221 - [analyzer][UninitializedObjectChecker] Support for nonloc::LocAsInteger

2018-09-14 Thread Ilya Biryukov via cfe-commits
This introduced revision introduced a new warning:
../tools/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp:62:7:
warning: '(anonymous namespace)::NeedsCastLocField' has virtual functions
but non-virtual destructor [-Wnon-virtual-dtor]

Which is turned into an error on our integrates, so it breaks us. Could you
please take a look?
A simple workaround would be to make FieldNode destructor virtual.
Does that make sense?


On Fri, Sep 14, 2018 at 12:19 PM Kristof Umann via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: szelethus
> Date: Fri Sep 14 03:18:26 2018
> New Revision: 342221
>
> URL: http://llvm.org/viewvc/llvm-project?rev=342221&view=rev
> Log:
> [analyzer][UninitializedObjectChecker] Support for nonloc::LocAsInteger
>
> Differential Revision: https://reviews.llvm.org/D49437
>
> Modified:
>
> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>
> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
> cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
>
> Modified:
> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=342221&r1=342220&r2=342221&view=diff
>
> ==
> ---
> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
> (original)
> +++
> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
> Fri Sep 14 03:18:26 2018
> @@ -274,15 +274,15 @@ bool FindUninitializedFields::isNonUnion
>continue;
>  }
>
> -if (isDereferencableType(T)) {
> +SVal V = State->getSVal(FieldVal);
> +
> +if (isDereferencableType(T) || V.getAs()) {
>if (isDereferencableUninit(FR, LocalChain))
>  ContainsUninitField = true;
>continue;
>  }
>
>  if (isPrimitiveType(T)) {
> -  SVal V = State->getSVal(FieldVal);
> -
>if (isPrimitiveUninit(V)) {
>  if (addFieldToUninits(LocalChain.add(RegularField(FR
>ContainsUninitField = true;
>
> Modified:
> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=342221&r1=342220&r2=342221&view=diff
>
> ==
> ---
> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
> (original)
> +++
> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
> Fri Sep 14 03:18:26 2018
> @@ -57,9 +57,9 @@ public:
>}
>  };
>
> -/// Represents a void* field that needs to be casted back to its dynamic
> type
> -/// for a correct note message.
> -class NeedsCastLocField final : public FieldNode {
> +/// Represents a nonloc::LocAsInteger or void* field, that point to
> objects, but
> +/// needs to be casted back to its dynamic type for a correct note
> message.
> +class NeedsCastLocField : public FieldNode {
>QualType CastBackType;
>
>  public:
> @@ -71,7 +71,13 @@ public:
>}
>
>virtual void printPrefix(llvm::raw_ostream &Out) const override {
> -Out << "static_cast" << '<' << CastBackType.getAsString() << ">(";
> +// If this object is a nonloc::LocAsInteger.
> +if (getDecl()->getType()->isIntegerType())
> +  Out << "reinterpret_cast";
> +// If this pointer's dynamic type is different then it's static type.
> +else
> +  Out << "static_cast";
> +Out << '<' << CastBackType.getAsString() << ">(";
>}
>
>virtual void printNode(llvm::raw_ostream &Out) const override {
> @@ -106,11 +112,12 @@ static llvm::Optional d
>  bool FindUninitializedFields::isDereferencableUninit(
>  const FieldRegion *FR, FieldChainInfo LocalChain) {
>
> -  assert(isDereferencableType(FR->getDecl()->getType()) &&
> - "This method only checks dereferencable objects!");
> -
>SVal V = State->getSVal(FR);
>
> +  assert((isDereferencableType(FR->getDecl()->getType()) ||
> +  V.getAs()) &&
> + "This method only checks dereferencable objects!");
> +
>if (V.isUnknown() || V.getAs()) {
>  IsAnyFieldInitialized = true;
>  return false;
> @@ -196,13 +203,15 @@ static llvm::Optional d
>
>llvm::SmallSet VisitedRegions;
>
> -  // If the static type of the field is a void pointer, we need to cast
> it back
> -  // to the dynamic type before dereferencing.
> -  bool NeedsCastBack = isVoidPointer(FR->getDecl()->getType());
> -
>SVal V = State->getSVal(FR);
>assert(V.getAsRegion() && "V must have an underlying region!");
>
> +  // If the static type of the field is a void pointer, or it is a
> +  // nonloc::LocAsInteger, we need to cast it 

Re: r342221 - [analyzer][UninitializedObjectChecker] Support for nonloc::LocAsInteger

2018-09-14 Thread Ilya Biryukov via cfe-commits
Ah, the reason why it does not fire on other inheritors is because they're
final. Any reason to remove final from NeedsCastLocField?

On Fri, Sep 14, 2018 at 1:17 PM Ilya Biryukov  wrote:

> This introduced revision introduced a new warning:
> ../tools/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp:62:7:
> warning: '(anonymous namespace)::NeedsCastLocField' has virtual functions
> but non-virtual destructor [-Wnon-virtual-dtor]
>
> Which is turned into an error on our integrates, so it breaks us. Could
> you please take a look?
> A simple workaround would be to make FieldNode destructor virtual.
> Does that make sense?
>
>
> On Fri, Sep 14, 2018 at 12:19 PM Kristof Umann via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: szelethus
>> Date: Fri Sep 14 03:18:26 2018
>> New Revision: 342221
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=342221&view=rev
>> Log:
>> [analyzer][UninitializedObjectChecker] Support for nonloc::LocAsInteger
>>
>> Differential Revision: https://reviews.llvm.org/D49437
>>
>> Modified:
>>
>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>>
>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
>> cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
>>
>> Modified:
>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=342221&r1=342220&r2=342221&view=diff
>>
>> ==
>> ---
>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>> (original)
>> +++
>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>> Fri Sep 14 03:18:26 2018
>> @@ -274,15 +274,15 @@ bool FindUninitializedFields::isNonUnion
>>continue;
>>  }
>>
>> -if (isDereferencableType(T)) {
>> +SVal V = State->getSVal(FieldVal);
>> +
>> +if (isDereferencableType(T) || V.getAs()) {
>>if (isDereferencableUninit(FR, LocalChain))
>>  ContainsUninitField = true;
>>continue;
>>  }
>>
>>  if (isPrimitiveType(T)) {
>> -  SVal V = State->getSVal(FieldVal);
>> -
>>if (isPrimitiveUninit(V)) {
>>  if (addFieldToUninits(LocalChain.add(RegularField(FR
>>ContainsUninitField = true;
>>
>> Modified:
>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=342221&r1=342220&r2=342221&view=diff
>>
>> ==
>> ---
>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
>> (original)
>> +++
>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
>> Fri Sep 14 03:18:26 2018
>> @@ -57,9 +57,9 @@ public:
>>}
>>  };
>>
>> -/// Represents a void* field that needs to be casted back to its dynamic
>> type
>> -/// for a correct note message.
>> -class NeedsCastLocField final : public FieldNode {
>> +/// Represents a nonloc::LocAsInteger or void* field, that point to
>> objects, but
>> +/// needs to be casted back to its dynamic type for a correct note
>> message.
>> +class NeedsCastLocField : public FieldNode {
>>QualType CastBackType;
>>
>>  public:
>> @@ -71,7 +71,13 @@ public:
>>}
>>
>>virtual void printPrefix(llvm::raw_ostream &Out) const override {
>> -Out << "static_cast" << '<' << CastBackType.getAsString() << ">(";
>> +// If this object is a nonloc::LocAsInteger.
>> +if (getDecl()->getType()->isIntegerType())
>> +  Out << "reinterpret_cast";
>> +// If this pointer's dynamic type is different then it's static type.
>> +else
>> +  Out << "static_cast";
>> +Out << '<' << CastBackType.getAsString() << ">(";
>>}
>>
>>virtual void printNode(llvm::raw_ostream &Out) const override {
>> @@ -106,11 +112,12 @@ static llvm::Optional d
>>  bool FindUninitializedFields::isDereferencableUninit(
>>  const FieldRegion *FR, FieldChainInfo LocalChain) {
>>
>> -  assert(isDereferencableType(FR->getDecl()->getType()) &&
>> - "This method only checks dereferencable objects!");
>> -
>>SVal V = State->getSVal(FR);
>>
>> +  assert((isDereferencableType(FR->getDecl()->getType()) ||
>> +  V.getAs()) &&
>> + "This method only checks dereferencable objects!");
>> +
>>if (V.isUnknown() || V.getAs()) {
>>  IsAnyFieldInitialized = true;
>>  return false;
>> @@ -196,13 +203,15 @@ static llvm::Optional d
>>
>>llvm::SmallSet VisitedRegions;
>>
>> -  // If the static type of the field is a void pointer, we need to cast
>> it back
>> -  // to the dy

r342225 - [analyzer] Restore final on NeedsCastLocField. NFC

2018-09-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Sep 14 04:28:48 2018
New Revision: 342225

URL: http://llvm.org/viewvc/llvm-project?rev=342225&view=rev
Log:
[analyzer] Restore final on NeedsCastLocField. NFC

To fix compiler warning about non-virtual dtor introduced in r342221.

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=342225&r1=342224&r2=342225&view=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 Fri Sep 14 04:28:48 2018
@@ -59,7 +59,7 @@ public:
 
 /// Represents a nonloc::LocAsInteger or void* field, that point to objects, 
but
 /// needs to be casted back to its dynamic type for a correct note message.
-class NeedsCastLocField : public FieldNode {
+class NeedsCastLocField final : public FieldNode {
   QualType CastBackType;
 
 public:


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r342221 - [analyzer][UninitializedObjectChecker] Support for nonloc::LocAsInteger

2018-09-14 Thread Ilya Biryukov via cfe-commits
I've sent a quick workaround restoring final (r342225) to unbreak our
internal buildbots.

On Fri, Sep 14, 2018 at 1:20 PM Ilya Biryukov  wrote:

> Ah, the reason why it does not fire on other inheritors is because they're
> final. Any reason to remove final from NeedsCastLocField?
>
> On Fri, Sep 14, 2018 at 1:17 PM Ilya Biryukov 
> wrote:
>
>> This introduced revision introduced a new warning:
>> ../tools/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp:62:7:
>> warning: '(anonymous namespace)::NeedsCastLocField' has virtual functions
>> but non-virtual destructor [-Wnon-virtual-dtor]
>>
>> Which is turned into an error on our integrates, so it breaks us. Could
>> you please take a look?
>> A simple workaround would be to make FieldNode destructor virtual.
>> Does that make sense?
>>
>>
>> On Fri, Sep 14, 2018 at 12:19 PM Kristof Umann via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: szelethus
>>> Date: Fri Sep 14 03:18:26 2018
>>> New Revision: 342221
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=342221&view=rev
>>> Log:
>>> [analyzer][UninitializedObjectChecker] Support for nonloc::LocAsInteger
>>>
>>> Differential Revision: https://reviews.llvm.org/D49437
>>>
>>> Modified:
>>>
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>>>
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
>>> cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
>>>
>>> Modified:
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=342221&r1=342220&r2=342221&view=diff
>>>
>>> ==
>>> ---
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>>> (original)
>>> +++
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
>>> Fri Sep 14 03:18:26 2018
>>> @@ -274,15 +274,15 @@ bool FindUninitializedFields::isNonUnion
>>>continue;
>>>  }
>>>
>>> -if (isDereferencableType(T)) {
>>> +SVal V = State->getSVal(FieldVal);
>>> +
>>> +if (isDereferencableType(T) || V.getAs()) {
>>>if (isDereferencableUninit(FR, LocalChain))
>>>  ContainsUninitField = true;
>>>continue;
>>>  }
>>>
>>>  if (isPrimitiveType(T)) {
>>> -  SVal V = State->getSVal(FieldVal);
>>> -
>>>if (isPrimitiveUninit(V)) {
>>>  if (addFieldToUninits(LocalChain.add(RegularField(FR
>>>ContainsUninitField = true;
>>>
>>> Modified:
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=342221&r1=342220&r2=342221&view=diff
>>>
>>> ==
>>> ---
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
>>> (original)
>>> +++
>>> cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
>>> Fri Sep 14 03:18:26 2018
>>> @@ -57,9 +57,9 @@ public:
>>>}
>>>  };
>>>
>>> -/// Represents a void* field that needs to be casted back to its
>>> dynamic type
>>> -/// for a correct note message.
>>> -class NeedsCastLocField final : public FieldNode {
>>> +/// Represents a nonloc::LocAsInteger or void* field, that point to
>>> objects, but
>>> +/// needs to be casted back to its dynamic type for a correct note
>>> message.
>>> +class NeedsCastLocField : public FieldNode {
>>>QualType CastBackType;
>>>
>>>  public:
>>> @@ -71,7 +71,13 @@ public:
>>>}
>>>
>>>virtual void printPrefix(llvm::raw_ostream &Out) const override {
>>> -Out << "static_cast" << '<' << CastBackType.getAsString() << ">(";
>>> +// If this object is a nonloc::LocAsInteger.
>>> +if (getDecl()->getType()->isIntegerType())
>>> +  Out << "reinterpret_cast";
>>> +// If this pointer's dynamic type is different then it's static
>>> type.
>>> +else
>>> +  Out << "static_cast";
>>> +Out << '<' << CastBackType.getAsString() << ">(";
>>>}
>>>
>>>virtual void printNode(llvm::raw_ostream &Out) const override {
>>> @@ -106,11 +112,12 @@ static llvm::Optional d
>>>  bool FindUninitializedFields::isDereferencableUninit(
>>>  const FieldRegion *FR, FieldChainInfo LocalChain) {
>>>
>>> -  assert(isDereferencableType(FR->getDecl()->getType()) &&
>>> - "This method only checks dereferencable objects!");
>>> -
>>>SVal V = State->getSVal(FR);
>>>
>>> +  assert((isDereferencableType(FR->getDecl()->getType()) ||
>>> +  V.getAs()) &&
>>> + "This method only checks dereferencable objects!");
>>> +
>>>if (V.isUnk

[clang-tools-extra] r342226 - [clangd] Update IndexerMain.cpp file comment after rename. NFC

2018-09-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Sep 14 04:39:05 2018
New Revision: 342226

URL: http://llvm.org/viewvc/llvm-project?rev=342226&view=rev
Log:
[clangd] Update IndexerMain.cpp file comment after rename. NFC

Modified:
clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp

Modified: clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp?rev=342226&r1=342225&r2=342226&view=diff
==
--- clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp Fri Sep 14 04:39:05 
2018
@@ -1,4 +1,4 @@
-//===--- GlobalSymbolBuilderMain.cpp -*- 
C++-*-===//
+//===--- IndexerMain.cpp -*- 
C++-*-===//
 //
 // The LLVM Compiler Infrastructure
 //


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r337627 - Fold dangling-field warning into general initialization lifetime checks.

2018-07-22 Thread Ilya Biryukov via cfe-commits
Hi Richard,

this commit seems to cause invalid warning in the following example:

struct foo {
  foo(char *x) : x_(&x[10]) {} //
private:
  char *x_;
};

The warning itself:
1.cpp:2:21: warning: initializing pointer member 'x_' with the stack
address of parameter 'x' [-Wdangling-field]

I'll revert the change to unbreak our integrate.


On Sat, Jul 21, 2018 at 12:31 AM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Fri Jul 20 15:25:55 2018
> New Revision: 337627
>
> URL: http://llvm.org/viewvc/llvm-project?rev=337627&view=rev
> Log:
> Fold dangling-field warning into general initialization lifetime checks.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
> cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=337627&r1=337626&r2=337627&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 20
> 15:25:55 2018
> @@ -7870,11 +7870,11 @@ def note_ref_var_local_bind : Note<
>  // Check for initializing a member variable with the address or a
> reference to
>  // a constructor parameter.
>  def warn_bind_ref_member_to_parameter : Warning<
> -  "binding reference member %0 to stack allocated parameter %1">,
> -  InGroup;
> +  "binding reference member %0 to stack allocated "
> +  "%select{variable|parameter}2 %1">, InGroup;
>  def warn_init_ptr_member_to_parameter_addr : Warning<
> -  "initializing pointer member %0 with the stack address of parameter
> %1">,
> -  InGroup;
> +  "initializing pointer member %0 with the stack address of "
> +  "%select{variable|parameter}2 %1">, InGroup;
>  def note_ref_or_ptr_member_declared_here : Note<
>"%select{reference|pointer}0 member declared here">;
>
>
> Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=337627&r1=337626&r2=337627&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Jul 20 15:25:55 2018
> @@ -3946,53 +3946,6 @@ Sema::BuildMemInitializer(Decl *Construc
>return BuildBaseInitializer(BaseType, TInfo, Init, ClassDecl,
> EllipsisLoc);
>  }
>
> -/// Checks a member initializer expression for cases where reference (or
> -/// pointer) members are bound to by-value parameters (or their
> addresses).
> -static void CheckForDanglingReferenceOrPointer(Sema &S, ValueDecl *Member,
> -   Expr *Init,
> -   SourceLocation IdLoc) {
> -  QualType MemberTy = Member->getType();
> -
> -  // We only handle pointers and references currently.
> -  // FIXME: Would this be relevant for ObjC object pointers? Or block
> pointers?
> -  if (!MemberTy->isReferenceType() && !MemberTy->isPointerType())
> -return;
> -
> -  const bool IsPointer = MemberTy->isPointerType();
> -  if (IsPointer) {
> -if (const UnaryOperator *Op
> -  = dyn_cast(Init->IgnoreParenImpCasts())) {
> -  // The only case we're worried about with pointers requires taking
> the
> -  // address.
> -  if (Op->getOpcode() != UO_AddrOf)
> -return;
> -
> -  Init = Op->getSubExpr();
> -} else {
> -  // We only handle address-of expression initializers for pointers.
> -  return;
> -}
> -  }
> -
> -  if (const DeclRefExpr *DRE =
> dyn_cast(Init->IgnoreParens())) {
> -// We only warn when referring to a non-reference parameter
> declaration.
> -const ParmVarDecl *Parameter = dyn_cast(DRE->getDecl());
> -if (!Parameter || Parameter->getType()->isReferenceType())
> -  return;
> -
> -S.Diag(Init->getExprLoc(),
> -   IsPointer ? diag::warn_init_ptr_member_to_parameter_addr
> - : diag::warn_bind_ref_member_to_parameter)
> -  << Member << Parameter << Init->getSourceRange();
> -  } else {
> -// Other initializers are fine.
> -return;
> -  }
> -
> -  S.Diag(Member->getLocation(),
> diag::note_ref_or_ptr_member_declared_here)
> -<< (unsigned)IsPointer;
> -}
> -
>  MemInitResult
>  Sema::BuildMemberInitializer(ValueDecl *Member, Expr *Init,
>   SourceLocation IdLoc) {
> @@ -4047,8 +4000,6 @@ Sema::BuildMemberInitializer(ValueDecl *
>  if (MemberInit.isInvalid())
>return true;
>
> -CheckForDanglingReferenceOrPointer(*this, Member, MemberInit.get(),
> IdLoc);
> -
>  // C++11 [class.base.init]p7:
>  /

r337671 - Revert "Fold dangling-field warning into general initialization lifetime checks."

2018-07-22 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Sun Jul 22 23:32:36 2018
New Revision: 337671

URL: http://llvm.org/viewvc/llvm-project?rev=337671&view=rev
Log:
Revert "Fold dangling-field warning into general initialization lifetime 
checks."

This reverts commit r337627.
After the change, clang started producing invalid warning on the following code:
struct foo {
  foo(char *x) : x_(&x[10]) {}
private:
  char *x_;
};

1.cpp:2:21: warning: initializing pointer member 'x_' with the stack address of 
parameter 'x' [-Wdangling-field]

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=337671&r1=337670&r2=337671&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Jul 22 23:32:36 
2018
@@ -7870,11 +7870,11 @@ def note_ref_var_local_bind : Note<
 // Check for initializing a member variable with the address or a reference to
 // a constructor parameter.
 def warn_bind_ref_member_to_parameter : Warning<
-  "binding reference member %0 to stack allocated "
-  "%select{variable|parameter}2 %1">, InGroup;
+  "binding reference member %0 to stack allocated parameter %1">,
+  InGroup;
 def warn_init_ptr_member_to_parameter_addr : Warning<
-  "initializing pointer member %0 with the stack address of "
-  "%select{variable|parameter}2 %1">, InGroup;
+  "initializing pointer member %0 with the stack address of parameter %1">,
+  InGroup;
 def note_ref_or_ptr_member_declared_here : Note<
   "%select{reference|pointer}0 member declared here">;
 

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=337671&r1=337670&r2=337671&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Jul 22 23:32:36 2018
@@ -3946,6 +3946,53 @@ Sema::BuildMemInitializer(Decl *Construc
   return BuildBaseInitializer(BaseType, TInfo, Init, ClassDecl, EllipsisLoc);
 }
 
+/// Checks a member initializer expression for cases where reference (or
+/// pointer) members are bound to by-value parameters (or their addresses).
+static void CheckForDanglingReferenceOrPointer(Sema &S, ValueDecl *Member,
+   Expr *Init,
+   SourceLocation IdLoc) {
+  QualType MemberTy = Member->getType();
+
+  // We only handle pointers and references currently.
+  // FIXME: Would this be relevant for ObjC object pointers? Or block pointers?
+  if (!MemberTy->isReferenceType() && !MemberTy->isPointerType())
+return;
+
+  const bool IsPointer = MemberTy->isPointerType();
+  if (IsPointer) {
+if (const UnaryOperator *Op
+  = dyn_cast(Init->IgnoreParenImpCasts())) {
+  // The only case we're worried about with pointers requires taking the
+  // address.
+  if (Op->getOpcode() != UO_AddrOf)
+return;
+
+  Init = Op->getSubExpr();
+} else {
+  // We only handle address-of expression initializers for pointers.
+  return;
+}
+  }
+
+  if (const DeclRefExpr *DRE = dyn_cast(Init->IgnoreParens())) {
+// We only warn when referring to a non-reference parameter declaration.
+const ParmVarDecl *Parameter = dyn_cast(DRE->getDecl());
+if (!Parameter || Parameter->getType()->isReferenceType())
+  return;
+
+S.Diag(Init->getExprLoc(),
+   IsPointer ? diag::warn_init_ptr_member_to_parameter_addr
+ : diag::warn_bind_ref_member_to_parameter)
+  << Member << Parameter << Init->getSourceRange();
+  } else {
+// Other initializers are fine.
+return;
+  }
+
+  S.Diag(Member->getLocation(), diag::note_ref_or_ptr_member_declared_here)
+<< (unsigned)IsPointer;
+}
+
 MemInitResult
 Sema::BuildMemberInitializer(ValueDecl *Member, Expr *Init,
  SourceLocation IdLoc) {
@@ -4000,6 +4047,8 @@ Sema::BuildMemberInitializer(ValueDecl *
 if (MemberInit.isInvalid())
   return true;
 
+CheckForDanglingReferenceOrPointer(*this, Member, MemberInit.get(), IdLoc);
+
 // C++11 [class.base.init]p7:
 //   The initialization of each base and member constitutes a
 //   full-expression.

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=337671&r1=337670&r2=337671&view=diff
==
--- cfe/trunk/

Re: r337627 - Fold dangling-field warning into general initialization lifetime checks.

2018-07-22 Thread Ilya Biryukov via cfe-commits
Reverted in r337671

On Mon, Jul 23, 2018 at 8:24 AM Ilya Biryukov  wrote:

> Hi Richard,
>
> this commit seems to cause invalid warning in the following example:
>
> struct foo {
>   foo(char *x) : x_(&x[10]) {} //
> private:
>   char *x_;
> };
>
> The warning itself:
> 1.cpp:2:21: warning: initializing pointer member 'x_' with the stack
> address of parameter 'x' [-Wdangling-field]
>
> I'll revert the change to unbreak our integrate.
>
>
> On Sat, Jul 21, 2018 at 12:31 AM Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Fri Jul 20 15:25:55 2018
>> New Revision: 337627
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=337627&view=rev
>> Log:
>> Fold dangling-field warning into general initialization lifetime checks.
>>
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> cfe/trunk/lib/Sema/SemaInit.cpp
>> cfe/trunk/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
>> cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=337627&r1=337626&r2=337627&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 20
>> 15:25:55 2018
>> @@ -7870,11 +7870,11 @@ def note_ref_var_local_bind : Note<
>>  // Check for initializing a member variable with the address or a
>> reference to
>>  // a constructor parameter.
>>  def warn_bind_ref_member_to_parameter : Warning<
>> -  "binding reference member %0 to stack allocated parameter %1">,
>> -  InGroup;
>> +  "binding reference member %0 to stack allocated "
>> +  "%select{variable|parameter}2 %1">, InGroup;
>>  def warn_init_ptr_member_to_parameter_addr : Warning<
>> -  "initializing pointer member %0 with the stack address of parameter
>> %1">,
>> -  InGroup;
>> +  "initializing pointer member %0 with the stack address of "
>> +  "%select{variable|parameter}2 %1">, InGroup;
>>  def note_ref_or_ptr_member_declared_here : Note<
>>"%select{reference|pointer}0 member declared here">;
>>
>>
>> Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=337627&r1=337626&r2=337627&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Jul 20 15:25:55 2018
>> @@ -3946,53 +3946,6 @@ Sema::BuildMemInitializer(Decl *Construc
>>return BuildBaseInitializer(BaseType, TInfo, Init, ClassDecl,
>> EllipsisLoc);
>>  }
>>
>> -/// Checks a member initializer expression for cases where reference (or
>> -/// pointer) members are bound to by-value parameters (or their
>> addresses).
>> -static void CheckForDanglingReferenceOrPointer(Sema &S, ValueDecl
>> *Member,
>> -   Expr *Init,
>> -   SourceLocation IdLoc) {
>> -  QualType MemberTy = Member->getType();
>> -
>> -  // We only handle pointers and references currently.
>> -  // FIXME: Would this be relevant for ObjC object pointers? Or block
>> pointers?
>> -  if (!MemberTy->isReferenceType() && !MemberTy->isPointerType())
>> -return;
>> -
>> -  const bool IsPointer = MemberTy->isPointerType();
>> -  if (IsPointer) {
>> -if (const UnaryOperator *Op
>> -  = dyn_cast(Init->IgnoreParenImpCasts())) {
>> -  // The only case we're worried about with pointers requires taking
>> the
>> -  // address.
>> -  if (Op->getOpcode() != UO_AddrOf)
>> -return;
>> -
>> -  Init = Op->getSubExpr();
>> -} else {
>> -  // We only handle address-of expression initializers for pointers.
>> -  return;
>> -}
>> -  }
>> -
>> -  if (const DeclRefExpr *DRE =
>> dyn_cast(Init->IgnoreParens())) {
>> -// We only warn when referring to a non-reference parameter
>> declaration.
>> -const ParmVarDecl *Parameter = dyn_cast(DRE->getDecl());
>> -if (!Parameter || Parameter->getType()->isReferenceType())
>> -  return;
>> -
>> -S.Diag(Init->getExprLoc(),
>> -   IsPointer ? diag::warn_init_ptr_member_to_parameter_addr
>> - : diag::warn_bind_ref_member_to_parameter)
>> -  << Member << Parameter << Init->getSourceRange();
>> -  } else {
>> -// Other initializers are fine.
>> -return;
>> -  }
>> -
>> -  S.Diag(Member->getLocation(),
>> diag::note_ref_or_ptr_member_declared_here)
>> -<< (unsigned)IsPointer;
>> -}
>> -
>>  MemInitResult
>>  Sema::BuildMemberInitializer(ValueDecl *Member, Expr *Init,
>>   SourceLocation IdLoc) {
>> @@ -4047,8 +4000,6 @@ Sema::Build

[clang-tools-extra] r338012 - [clangd] Do not rebuild AST if inputs have not changed

2018-07-26 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Jul 26 02:21:07 2018
New Revision: 338012

URL: http://llvm.org/viewvc/llvm-project?rev=338012&view=rev
Log:
[clangd] Do not rebuild AST if inputs have not changed

Summary:
If the contents are the same, the update most likely comes from the
fact that compile commands were invalidated. In that case we want to
avoid rebuilds in case the compile commands are actually the same.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: simark, javed.absar, MaskRay, jkorous, arphaman, jfb, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/test/clangd/extra-flags.test
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestFS.cpp
clang-tools-extra/trunk/unittests/clangd/TestFS.h

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=338012&r1=338011&r2=338012&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Thu Jul 26 02:21:07 2018
@@ -324,6 +324,11 @@ void ASTWorker::update(
 ParseInputs Inputs, WantDiagnostics WantDiags,
 llvm::unique_function)> OnUpdated) {
   auto Task = [=](decltype(OnUpdated) OnUpdated) mutable {
+// Will be used to check if we can avoid rebuilding the AST.
+bool InputsAreTheSame =
+std::tie(FileInputs.CompileCommand, FileInputs.Contents) ==
+std::tie(Inputs.CompileCommand, Inputs.Contents);
+
 tooling::CompileCommand OldCommand = std::move(FileInputs.CompileCommand);
 FileInputs = Inputs;
 // Remove the old AST if it's still in cache.
@@ -343,16 +348,38 @@ void ASTWorker::update(
   return;
 }
 
-std::shared_ptr NewPreamble = buildPreamble(
-FileName, *Invocation, getPossiblyStalePreamble(), OldCommand, Inputs,
-PCHs, StorePreambleInMemory, PreambleCallback);
+std::shared_ptr OldPreamble =
+getPossiblyStalePreamble();
+std::shared_ptr NewPreamble =
+buildPreamble(FileName, *Invocation, OldPreamble, OldCommand, Inputs,
+  PCHs, StorePreambleInMemory, PreambleCallback);
+
+bool CanReuseAST = InputsAreTheSame && (OldPreamble == NewPreamble);
 {
   std::lock_guard Lock(Mutex);
   if (NewPreamble)
 LastBuiltPreamble = NewPreamble;
 }
+// Before doing the expensive AST reparse, we want to release our reference
+// to the old preamble, so it can be freed if there are no other references
+// to it.
+OldPreamble.reset();
 PreambleWasBuilt.notify();
 
+if (CanReuseAST) {
+  // Take a shortcut and don't build the AST, neither the inputs nor the
+  // preamble have changed.
+  // Note that we do not report the diagnostics, since they should not have
+  // changed either. All the clients should handle the lack of OnUpdated()
+  // call anyway, to handle empty result from buildAST.
+  // FIXME(ibiryukov): the AST could actually change if non-preamble
+  // includes changed, but we choose to ignore it.
+  // FIXME(ibiryukov): should we refresh the cache in IdleASTs for the
+  // current file at this point?
+  log("Skipping rebuild of the AST for {0}, inputs are the same.",
+  FileName);
+  return;
+}
 // Build the AST for diagnostics.
 llvm::Optional AST =
 buildAST(FileName, std::move(Invocation), Inputs, NewPreamble, PCHs);

Modified: clang-tools-extra/trunk/test/clangd/extra-flags.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/extra-flags.test?rev=338012&r1=338011&r2=338012&view=diff
==
--- clang-tools-extra/trunk/test/clangd/extra-flags.test (original)
+++ clang-tools-extra/trunk/test/clangd/extra-flags.test Thu Jul 26 02:21:07 
2018
@@ -23,7 +23,7 @@
 # CHECK-NEXT:"uri": "file://{{.*}}/foo.c"
 # CHECK-NEXT:  }
 ---
-{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":2},"contentChanges":[{"text":"int
 main() { int i; return i; }"}]}}
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":2},"contentChanges":[{"text":"int
 main() { int i; return i+1; }"}]}}
 #  CHECK:  "method": "textDocument/publishDiagnostics",
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [

Modified: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp?rev=338012&r1=338011&r2=338012&view=diff
==
--- clang-tools-extra/trunk/unittes

[clang-tools-extra] r338021 - [clangd] Fix (most) naming warnings from clang-tidy. NFC

2018-07-26 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Jul 26 05:05:31 2018
New Revision: 338021

URL: http://llvm.org/viewvc/llvm-project?rev=338021&view=rev
Log:
[clangd] Fix (most) naming warnings from clang-tidy. NFC

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/clangd/index/SymbolYAML.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=338021&r1=338020&r2=338021&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Jul 26 05:05:31 2018
@@ -121,7 +121,7 @@ void clangd::dumpAST(ParsedAST &AST, llv
 }
 
 llvm::Optional
-ParsedAST::Build(std::unique_ptr CI,
+ParsedAST::build(std::unique_ptr CI,
  std::shared_ptr Preamble,
  std::unique_ptr Buffer,
  std::shared_ptr PCHs,
@@ -367,7 +367,7 @@ llvm::Optional clangd::buildA
 // dirs.
   }
 
-  return ParsedAST::Build(
+  return ParsedAST::build(
   llvm::make_unique(*Invocation), Preamble,
   llvm::MemoryBuffer::getMemBufferCopy(Inputs.Contents), PCHs, Inputs.FS);
 }

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=338021&r1=338020&r2=338021&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h Thu Jul 26 05:05:31 2018
@@ -68,7 +68,7 @@ public:
   /// Attempts to run Clang and store parsed AST. If \p Preamble is non-null
   /// it is reused during parsing.
   static llvm::Optional
-  Build(std::unique_ptr CI,
+  build(std::unique_ptr CI,
 std::shared_ptr Preamble,
 std::unique_ptr Buffer,
 std::shared_ptr PCHs,

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=338021&r1=338020&r2=338021&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Jul 26 05:05:31 2018
@@ -704,7 +704,7 @@ public:
   CurrentArg, S, *Allocator, CCTUInfo, true);
   assert(CCS && "Expected the CodeCompletionString to be non-null");
   // FIXME: for headers, we need to get a comment from the index.
-  SigHelp.signatures.push_back(ProcessOverloadCandidate(
+  SigHelp.signatures.push_back(processOverloadCandidate(
   Candidate, *CCS,
   getParameterDocComment(S.getASTContext(), Candidate, CurrentArg,
  /*CommentsFromHeaders=*/false)));
@@ -719,7 +719,7 @@ private:
   // FIXME(ioeric): consider moving CodeCompletionString logic here to
   // CompletionString.h.
   SignatureInformation
-  ProcessOverloadCandidate(const OverloadCandidate &Candidate,
+  processOverloadCandidate(const OverloadCandidate &Candidate,
const CodeCompletionString &CCS,
llvm::StringRef DocComment) const {
 SignatureInformation Result;

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=338021&r1=338020&r2=338021&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Thu Jul 26 
05:05:31 2018
@@ -32,7 +32,7 @@ void appendEscapeSnippet(const llvm::Str
   }
 }
 
-bool LooksLikeDocComment(llvm::StringRef CommentText) {
+bool looksLikeDocComment(llvm::StringRef CommentText) {
   // We don't report comments that only contain "special" chars.
   // This avoids reporting various delimiters, like:
   //   =
@@ -67,7 +67,7 @@ std::string getDocComment(const ASTConte
   // write them into PCH, because they are racy and slow to load.
   asse

[clang-tools-extra] r338037 - [clangd] Use 'const Twine&' instead of 'Twine'. NFC

2018-07-26 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Jul 26 09:13:52 2018
New Revision: 338037

URL: http://llvm.org/viewvc/llvm-project?rev=338037&view=rev
Log:
[clangd] Use 'const Twine&' instead of 'Twine'. NFC

To fix clang-tidy warning

Modified:
clang-tools-extra/trunk/clangd/Threading.cpp
clang-tools-extra/trunk/clangd/Threading.h

Modified: clang-tools-extra/trunk/clangd/Threading.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.cpp?rev=338037&r1=338036&r2=338037&view=diff
==
--- clang-tools-extra/trunk/clangd/Threading.cpp (original)
+++ clang-tools-extra/trunk/clangd/Threading.cpp Thu Jul 26 09:13:52 2018
@@ -50,7 +50,7 @@ bool AsyncTaskRunner::wait(Deadline D) c
   [&] { return InFlightTasks == 0; });
 }
 
-void AsyncTaskRunner::runAsync(llvm::Twine Name,
+void AsyncTaskRunner::runAsync(const llvm::Twine &Name,
llvm::unique_function Action) {
   {
 std::lock_guard Lock(Mutex);

Modified: clang-tools-extra/trunk/clangd/Threading.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.h?rev=338037&r1=338036&r2=338037&view=diff
==
--- clang-tools-extra/trunk/clangd/Threading.h (original)
+++ clang-tools-extra/trunk/clangd/Threading.h Thu Jul 26 09:13:52 2018
@@ -108,7 +108,7 @@ public:
   void wait() const { (void)wait(Deadline::infinity()); }
   LLVM_NODISCARD bool wait(Deadline D) const;
   // The name is used for tracing and debugging (e.g. to name a spawned 
thread).
-  void runAsync(llvm::Twine Name, llvm::unique_function Action);
+  void runAsync(const llvm::Twine &Name, llvm::unique_function Action);
 
 private:
   mutable std::mutex Mutex;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r338124 - [clang-tidy] Fix a crash in fuchsia-multiple-inheritance

2018-07-27 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Jul 27 07:05:39 2018
New Revision: 338124

URL: http://llvm.org/viewvc/llvm-project?rev=338124&view=rev
Log:
[clang-tidy] Fix a crash in fuchsia-multiple-inheritance

Summary: See the test case for a repro.

Reviewers: juliehockett, ioeric, hokein, aaron.ballman

Reviewed By: hokein

Subscribers: lebedev.ri, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp?rev=338124&r1=338123&r2=338124&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp Fri 
Jul 27 07:05:39 2018
@@ -30,6 +30,7 @@ AST_MATCHER(CXXRecordDecl, hasBases) {
 // previously.
 void MultipleInheritanceCheck::addNodeToInterfaceMap(const CXXRecordDecl *Node,
  bool isInterface) {
+  assert(Node->getIdentifier());
   StringRef Name = Node->getIdentifier()->getName();
   InterfaceMap.insert(std::make_pair(Name, isInterface));
 }
@@ -39,6 +40,7 @@ void MultipleInheritanceCheck::addNodeTo
 // interface status for the current node is not yet known.
 bool MultipleInheritanceCheck::getInterfaceStatus(const CXXRecordDecl *Node,
   bool &isInterface) const {
+  assert(Node->getIdentifier());
   StringRef Name = Node->getIdentifier()->getName();
   llvm::StringMapConstIterator Pair = InterfaceMap.find(Name);
   if (Pair == InterfaceMap.end())
@@ -59,6 +61,9 @@ bool MultipleInheritanceCheck::isCurrent
 }
 
 bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) {
+  if (!Node->getIdentifier())
+return false;
+
   // Short circuit the lookup if we have analyzed this record before.
   bool PreviousIsInterfaceResult;
   if (getInterfaceStatus(Node, PreviousIsInterfaceResult))

Modified: 
clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp?rev=338124&r1=338123&r2=338124&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp 
Fri Jul 27 07:05:39 2018
@@ -134,3 +134,14 @@ template struct B : virtual
 
 template struct C {};
 template struct D : C {};
+
+// Check clang_tidy does not crash on this code.
+template 
+struct WithTemplBase : T {
+  WithTemplBase();
+};
+
+int test_no_crash() {
+  auto foo = []() {};
+  WithTemplBase();
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r338241 - [clangd] Fix a comment. NFC

2018-07-30 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Jul 30 04:46:25 2018
New Revision: 338241

URL: http://llvm.org/viewvc/llvm-project?rev=338241&view=rev
Log:
[clangd] Fix a comment. NFC

Modified:
clang-tools-extra/trunk/clangd/TUScheduler.cpp

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=338241&r1=338240&r2=338241&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Mon Jul 30 04:46:25 2018
@@ -367,11 +367,11 @@ void ASTWorker::update(
 PreambleWasBuilt.notify();
 
 if (CanReuseAST) {
-  // Take a shortcut and don't build the AST, neither the inputs nor the
+  // Take a shortcut and don't build the AST if neither the inputs nor the
   // preamble have changed.
   // Note that we do not report the diagnostics, since they should not have
   // changed either. All the clients should handle the lack of OnUpdated()
-  // call anyway, to handle empty result from buildAST.
+  // call anyway to handle empty result from buildAST.
   // FIXME(ibiryukov): the AST could actually change if non-preamble
   // includes changed, but we choose to ignore it.
   // FIXME(ibiryukov): should we refresh the cache in IdleASTs for the


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r338255 - [CodeComplete] Fix the crash in code completion on access checking

2018-07-30 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Jul 30 08:19:05 2018
New Revision: 338255

URL: http://llvm.org/viewvc/llvm-project?rev=338255&view=rev
Log:
[CodeComplete] Fix the crash in code completion on access checking

Started crashing in r337453. See the added test case for the crash repro.

The fix reverts part of r337453 that causes the crash and does
not actually break anything when reverted.

Added:
cfe/trunk/test/Index/complete-access-checks-crash.cpp
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=338255&r1=338254&r2=338255&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Jul 30 08:19:05 2018
@@ -1303,34 +1303,8 @@ namespace {
 void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
bool InBaseClass) override {
   bool Accessible = true;
-  if (Ctx) {
-DeclContext *AccessingCtx = Ctx;
-// If ND comes from a base class, set the naming class back to the
-// derived class if the search starts from the derived class (i.e.
-// InBaseClass is true).
-//
-// Example:
-//   class B { protected: int X; }
-//   class D : public B { void f(); }
-//   void D::f() { this->^; }
-// The completion after "this->" will have `InBaseClass` set to true 
and
-// `Ctx` set to "B", when looking up in `B`. We need to set the actual
-// accessing context (i.e. naming class) to "D" so that access can be
-// calculated correctly.
-if (InBaseClass && isa(Ctx)) {
-  CXXRecordDecl *RC = nullptr;
-  // Get the enclosing record.
-  for (DeclContext *DC = CurContext; !DC->isFileContext();
-   DC = DC->getParent()) {
-if ((RC = dyn_cast(DC)))
-  break;
-  }
-  if (RC)
-AccessingCtx = RC;
-}
-Accessible = Results.getSema().IsSimplyAccessible(ND, AccessingCtx);
-  }
-
+  if (Ctx)
+Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx);
   ResultBuilder::Result Result(ND, Results.getBasePriority(ND), nullptr,
false, Accessible, FixIts);
   Results.AddResult(Result, CurContext, Hiding, InBaseClass);

Added: cfe/trunk/test/Index/complete-access-checks-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-access-checks-crash.cpp?rev=338255&view=auto
==
--- cfe/trunk/test/Index/complete-access-checks-crash.cpp (added)
+++ cfe/trunk/test/Index/complete-access-checks-crash.cpp Mon Jul 30 08:19:05 
2018
@@ -0,0 +1,13 @@
+struct Base {
+protected:
+  bool bar();
+};
+struct Derived : Base {
+};
+
+struct X {
+  int foo() {
+Derived(). // RUN: c-index-test -code-completion-at=%s:10:15 %s | 
FileCheck %s
+// CHECK: bar{{.*}}(inaccessible)
+  }
+};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r337453 - [CodeComplete] Fix accessibilty of protected members from base class.

2018-07-30 Thread Ilya Biryukov via cfe-commits
Prtially reverted the commit in r338255 to fix a very frequent crash.
The code seemed obviously wrong there (calling accessibility checking,
passing a possibly unrelated class) and the tests didn't break after
reverting it.

Let me know if I missed anything.

On Thu, Jul 19, 2018 at 3:37 PM Eric Liu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ioeric
> Date: Thu Jul 19 06:32:00 2018
> New Revision: 337453
>
> URL: http://llvm.org/viewvc/llvm-project?rev=337453&view=rev
> Log:
> [CodeComplete] Fix accessibilty of protected members from base class.
>
> Summary:
> Currently, protected members from base classes are marked as
> inaccessible when completing in derived class. This patch fixes the
> problem by
> setting the naming class correctly when looking up results in base class
> according to [11.2.p5].
>
> Reviewers: aaron.ballman, sammccall, rsmith
>
> Reviewed By: aaron.ballman
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D49421
>
> Modified:
> cfe/trunk/lib/Sema/SemaAccess.cpp
> cfe/trunk/lib/Sema/SemaCodeComplete.cpp
> cfe/trunk/test/Index/complete-access-checks.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=337453&r1=337452&r2=337453&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaAccess.cpp Thu Jul 19 06:32:00 2018
> @@ -11,6 +11,7 @@
>  //
>
>  
> //===--===//
>
> +#include "clang/Basic/Specifiers.h"
>  #include "clang/Sema/SemaInternal.h"
>  #include "clang/AST/ASTContext.h"
>  #include "clang/AST/CXXInheritance.h"
> @@ -1856,29 +1857,31 @@ void Sema::CheckLookupAccess(const Looku
>}
>  }
>
> -/// Checks access to Decl from the given class. The check will take access
> +/// Checks access to Target from the given class. The check will take
> access
>  /// specifiers into account, but no member access expressions and such.
>  ///
> -/// \param Decl the declaration to check if it can be accessed
> +/// \param Target the declaration to check if it can be accessed
>  /// \param Ctx the class/context from which to start the search
> -/// \return true if the Decl is accessible from the Class, false
> otherwise.
> -bool Sema::IsSimplyAccessible(NamedDecl *Decl, DeclContext *Ctx) {
> +/// \return true if the Target is accessible from the Class, false
> otherwise.
> +bool Sema::IsSimplyAccessible(NamedDecl *Target, DeclContext *Ctx) {
>if (CXXRecordDecl *Class = dyn_cast(Ctx)) {
> -if (!Decl->isCXXClassMember())
> +if (!Target->isCXXClassMember())
>return true;
>
> +if (Target->getAccess() == AS_public)
> +  return true;
>  QualType qType = Class->getTypeForDecl()->getCanonicalTypeInternal();
> +// The unprivileged access is AS_none as we don't know how the member
> was
> +// accessed, which is described by the access in DeclAccessPair.
> +// `IsAccessible` will examine the actual access of Target (i.e.
> +// Decl->getAccess()) when calculating the access.
>  AccessTarget Entity(Context, AccessedEntity::Member, Class,
> -DeclAccessPair::make(Decl, Decl->getAccess()),
> -qType);
> -if (Entity.getAccess() == AS_public)
> -  return true;
> -
> +DeclAccessPair::make(Target, AS_none), qType);
>  EffectiveContext EC(CurContext);
>  return ::IsAccessible(*this, EC, Entity) != ::AR_inaccessible;
>}
> -
> -  if (ObjCIvarDecl *Ivar = dyn_cast(Decl)) {
> +
> +  if (ObjCIvarDecl *Ivar = dyn_cast(Target)) {
>  // @public and @package ivars are always accessible.
>  if (Ivar->getCanonicalAccessControl() == ObjCIvarDecl::Public ||
>  Ivar->getCanonicalAccessControl() == ObjCIvarDecl::Package)
>
> Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=337453&r1=337452&r2=337453&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Jul 19 06:32:00 2018
> @@ -1303,8 +1303,33 @@ namespace {
>  void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
> bool InBaseClass) override {
>bool Accessible = true;
> -  if (Ctx)
> -Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx);
> +  if (Ctx) {
> +DeclContext *AccessingCtx = Ctx;
> +// If ND comes from a base class, set the naming class back to the
> +// derived class if the search starts from the derived class (i.e.
> +// InBaseClass is true).
> +//
> +// Example:
> +//   class B { protected: int X; }
> +//   class D : public B 

[clang-tools-extra] r338256 - [clangd] Do not remove AST from cache if nothing changed

2018-07-30 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Jul 30 08:30:45 2018
New Revision: 338256

URL: http://llvm.org/viewvc/llvm-project?rev=338256&view=rev
Log:
[clangd] Do not remove AST from cache if nothing changed

We were previously clearing the AST cache if the inputs and the
preamble were the same, which is not desired.

Modified:
clang-tools-extra/trunk/clangd/TUScheduler.cpp

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=338256&r1=338255&r2=338256&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Mon Jul 30 08:30:45 2018
@@ -331,8 +331,6 @@ void ASTWorker::update(
 
 tooling::CompileCommand OldCommand = std::move(FileInputs.CompileCommand);
 FileInputs = Inputs;
-// Remove the old AST if it's still in cache.
-IdleASTs.take(this);
 
 log("Updating file {0} with command [{1}] {2}", FileName,
 Inputs.CompileCommand.Directory,
@@ -342,6 +340,8 @@ void ASTWorker::update(
 buildCompilerInvocation(Inputs);
 if (!Invocation) {
   elog("Could not build CompilerInvocation for file {0}", FileName);
+  // Remove the old AST if it's still in cache.
+  IdleASTs.take(this);
   // Make sure anyone waiting for the preamble gets notified it could not
   // be built.
   PreambleWasBuilt.notify();
@@ -380,6 +380,9 @@ void ASTWorker::update(
   FileName);
   return;
 }
+// Remove the old AST if it's still in cache.
+IdleASTs.take(this);
+
 // Build the AST for diagnostics.
 llvm::Optional AST =
 buildAST(FileName, std::move(Invocation), Inputs, NewPreamble, PCHs);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r338260 - [clangd] Remove outdated comment. NFC

2018-07-30 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Jul 30 08:55:13 2018
New Revision: 338260

URL: http://llvm.org/viewvc/llvm-project?rev=338260&view=rev
Log:
[clangd] Remove outdated comment. NFC

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=338260&r1=338259&r2=338260&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Jul 30 08:55:13 2018
@@ -107,8 +107,6 @@ public:
   /// \p File is already tracked. Also schedules parsing of the AST for it on a
   /// separate thread. When the parsing is complete, DiagConsumer passed in
   /// constructor will receive onDiagnosticsReady callback.
-  /// When \p SkipCache is true, compile commands will always be requested from
-  /// compilation database even if they were cached in previous invocations.
   void addDocument(PathRef File, StringRef Contents,
WantDiagnostics WD = WantDiagnostics::Auto);
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r337453 - [CodeComplete] Fix accessibilty of protected members from base class.

2018-07-31 Thread Ilya Biryukov via cfe-commits
I actually tried to pass the correct derived scope to
CodeCompletionDeclConsumer on construction, it was not a lot of code and I
think this should fix the problem you're describing.
I'll send a patch.

On Tue, Jul 31, 2018 at 11:33 AM Eric Liu  wrote:

> Thanks a lot for looking into this!
>
> You are right, the change in SemaAccess seemed to have done the job to fix
> the protected member bug in specific. I think I made the change in
> SemaCodeComplete before SemaAccess and didn't realized the previous one was
> unnecessary to fix the tests. I think the accessing context/naming class is
> still wrong though. Basically, we want the naming class to be the derived
> class instead of the base class if the access is from a derived class.
> Without this,  accessibility check is relaxed, but it probably doesn't have
> very negative impact on code completion experience, so I think it's okay to
> revert the change in SemaCodeComplete. Thanks again!
>
> On Mon, Jul 30, 2018 at 5:22 PM Ilya Biryukov 
> wrote:
>
>> Prtially reverted the commit in r338255 to fix a very frequent crash.
>> The code seemed obviously wrong there (calling accessibility checking,
>> passing a possibly unrelated class) and the tests didn't break after
>> reverting it.
>>
>> Let me know if I missed anything.
>>
>> On Thu, Jul 19, 2018 at 3:37 PM Eric Liu via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: ioeric
>>> Date: Thu Jul 19 06:32:00 2018
>>> New Revision: 337453
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=337453&view=rev
>>> Log:
>>> [CodeComplete] Fix accessibilty of protected members from base class.
>>>
>>> Summary:
>>> Currently, protected members from base classes are marked as
>>> inaccessible when completing in derived class. This patch fixes the
>>> problem by
>>> setting the naming class correctly when looking up results in base class
>>> according to [11.2.p5].
>>>
>>> Reviewers: aaron.ballman, sammccall, rsmith
>>>
>>> Reviewed By: aaron.ballman
>>>
>>> Subscribers: cfe-commits
>>>
>>> Differential Revision: https://reviews.llvm.org/D49421
>>>
>>> Modified:
>>> cfe/trunk/lib/Sema/SemaAccess.cpp
>>> cfe/trunk/lib/Sema/SemaCodeComplete.cpp
>>> cfe/trunk/test/Index/complete-access-checks.cpp
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=337453&r1=337452&r2=337453&view=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaAccess.cpp Thu Jul 19 06:32:00 2018
>>> @@ -11,6 +11,7 @@
>>>  //
>>>
>>>  
>>> //===--===//
>>>
>>> +#include "clang/Basic/Specifiers.h"
>>>  #include "clang/Sema/SemaInternal.h"
>>>  #include "clang/AST/ASTContext.h"
>>>  #include "clang/AST/CXXInheritance.h"
>>> @@ -1856,29 +1857,31 @@ void Sema::CheckLookupAccess(const Looku
>>>}
>>>  }
>>>
>>> -/// Checks access to Decl from the given class. The check will take
>>> access
>>> +/// Checks access to Target from the given class. The check will take
>>> access
>>>  /// specifiers into account, but no member access expressions and such.
>>>  ///
>>> -/// \param Decl the declaration to check if it can be accessed
>>> +/// \param Target the declaration to check if it can be accessed
>>>  /// \param Ctx the class/context from which to start the search
>>> -/// \return true if the Decl is accessible from the Class, false
>>> otherwise.
>>> -bool Sema::IsSimplyAccessible(NamedDecl *Decl, DeclContext *Ctx) {
>>> +/// \return true if the Target is accessible from the Class, false
>>> otherwise.
>>> +bool Sema::IsSimplyAccessible(NamedDecl *Target, DeclContext *Ctx) {
>>>if (CXXRecordDecl *Class = dyn_cast(Ctx)) {
>>> -if (!Decl->isCXXClassMember())
>>> +if (!Target->isCXXClassMember())
>>>return true;
>>>
>>> +if (Target->getAccess() == AS_public)
>>> +  return true;
>>>  QualType qType =
>>> Class->getTypeForDecl()->getCanonicalTypeInternal();
>>> +// The unprivileged access is AS_none as we don't know how the
>>> member was
>>> +// accessed, which is described by the access in DeclAccessPair.
>>> +// `IsAccessible` will examine the actual access of Target (i.e.
>>> +// Decl->getAccess()) when calculating the access.
>>>  AccessTarget Entity(Context, AccessedEntity::Member, Class,
>>> -DeclAccessPair::make(Decl, Decl->getAccess()),
>>> -qType);
>>> -if (Entity.getAccess() == AS_public)
>>> -  return true;
>>> -
>>> +DeclAccessPair::make(Target, AS_none), qType);
>>>  EffectiveContext EC(CurContext);
>>>  return ::IsAccessible(*this, EC, Entity) != ::AR_inaccessible;
>>>}
>>> -
>>> -  if (ObjCIvarDecl *Ivar = dyn_cast(Decl)) {
>>> +
>>> +  if (ObjCIvarDecl *Ivar = dyn_cast(Target)) {
>>>  // @public 

[clang-tools-extra] r338361 - [clangd] Report diagnostics even if WantDiags::No AST was reused

2018-07-31 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Jul 31 04:47:52 2018
New Revision: 338361

URL: http://llvm.org/viewvc/llvm-project?rev=338361&view=rev
Log:
[clangd] Report diagnostics even if WantDiags::No AST was reused

Summary:
After r338256, clangd stopped reporting diagnostics if WantDiags::No request
is followed by a WantDiags::Yes request but the AST can be reused.

Reviewers: ioeric

Reviewed By: ioeric

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

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

Modified:
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=338361&r1=338360&r2=338361&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Tue Jul 31 04:47:52 2018
@@ -228,6 +228,9 @@ private:
   Semaphore &Barrier;
   /// Inputs, corresponding to the current state of AST.
   ParseInputs FileInputs;
+  /// Whether the diagnostics for the current FileInputs were reported to the
+  /// users before.
+  bool DiagsWereReported = false;
   /// Size of the last AST
   /// Guards members used by both TUScheduler and the worker thread.
   mutable std::mutex Mutex;
@@ -330,7 +333,9 @@ void ASTWorker::update(
 std::tie(Inputs.CompileCommand, Inputs.Contents);
 
 tooling::CompileCommand OldCommand = std::move(FileInputs.CompileCommand);
+bool PrevDiagsWereReported = DiagsWereReported;
 FileInputs = Inputs;
+DiagsWereReported = false;
 
 log("Updating file {0} with command [{1}] {2}", FileName,
 Inputs.CompileCommand.Directory,
@@ -366,34 +371,44 @@ void ASTWorker::update(
 OldPreamble.reset();
 PreambleWasBuilt.notify();
 
-if (CanReuseAST) {
-  // Take a shortcut and don't build the AST if neither the inputs nor the
-  // preamble have changed.
-  // Note that we do not report the diagnostics, since they should not have
-  // changed either. All the clients should handle the lack of OnUpdated()
-  // call anyway to handle empty result from buildAST.
-  // FIXME(ibiryukov): the AST could actually change if non-preamble
-  // includes changed, but we choose to ignore it.
-  // FIXME(ibiryukov): should we refresh the cache in IdleASTs for the
-  // current file at this point?
-  log("Skipping rebuild of the AST for {0}, inputs are the same.",
-  FileName);
-  return;
+if (!CanReuseAST) {
+  IdleASTs.take(this); // Remove the old AST if it's still in cache.
+} else {
+  // Since we don't need to rebuild the AST, we might've already reported
+  // the diagnostics for it.
+  if (PrevDiagsWereReported) {
+DiagsWereReported = true;
+// Take a shortcut and don't report the diagnostics, since they should
+// not changed. All the clients should handle the lack of OnUpdated()
+// call anyway to handle empty result from buildAST.
+// FIXME(ibiryukov): the AST could actually change if non-preamble
+// includes changed, but we choose to ignore it.
+// FIXME(ibiryukov): should we refresh the cache in IdleASTs for the
+// current file at this point?
+log("Skipping rebuild of the AST for {0}, inputs are the same.",
+FileName);
+return;
+  }
+}
+
+// Get the AST for diagnostics.
+llvm::Optional> AST = IdleASTs.take(this);
+if (!AST) {
+  llvm::Optional NewAST =
+  buildAST(FileName, std::move(Invocation), Inputs, NewPreamble, PCHs);
+  AST = NewAST ? llvm::make_unique(std::move(*NewAST)) : 
nullptr;
 }
-// Remove the old AST if it's still in cache.
-IdleASTs.take(this);
 
-// Build the AST for diagnostics.
-llvm::Optional AST =
-buildAST(FileName, std::move(Invocation), Inputs, NewPreamble, PCHs);
 // We want to report the diagnostics even if this update was cancelled.
 // It seems more useful than making the clients wait indefinitely if they
 // spam us with updates.
-if (WantDiags != WantDiagnostics::No && AST)
-  OnUpdated(AST->getDiagnostics());
+// Note *AST can be still be null if buildAST fails.
+if (WantDiags != WantDiagnostics::No && *AST) {
+  OnUpdated((*AST)->getDiagnostics());
+  DiagsWereReported = true;
+}
 // Stash the AST in the cache for further use.
-IdleASTs.put(this,
- AST ? llvm::make_unique(std::move(*AST)) : 
nullptr);
+IdleASTs.put(this, std::move(*AST));
   };
 
   startTask("Update", Bind(Task, std::move(OnUpdated)), WantDiags);

Modified: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TUSchedul

[clang-tools-extra] r338378 - [clangd] Do not build AST if no diagnostics were requested

2018-07-31 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Jul 31 06:45:37 2018
New Revision: 338378

URL: http://llvm.org/viewvc/llvm-project?rev=338378&view=rev
Log:
[clangd] Do not build AST if no diagnostics were requested

Summary:
It can be removed from the cache before the first access anyway, so
building it can be a waste of time.

Reviewers: ioeric

Reviewed By: ioeric

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

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

Modified:
clang-tools-extra/trunk/clangd/TUScheduler.cpp

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=338378&r1=338377&r2=338378&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Tue Jul 31 06:45:37 2018
@@ -391,6 +391,10 @@ void ASTWorker::update(
   }
 }
 
+// We only need to build the AST if diagnostics were requested.
+if (WantDiags == WantDiagnostics::No)
+  return;
+
 // Get the AST for diagnostics.
 llvm::Optional> AST = IdleASTs.take(this);
 if (!AST) {
@@ -398,12 +402,11 @@ void ASTWorker::update(
   buildAST(FileName, std::move(Invocation), Inputs, NewPreamble, PCHs);
   AST = NewAST ? llvm::make_unique(std::move(*NewAST)) : 
nullptr;
 }
-
 // We want to report the diagnostics even if this update was cancelled.
 // It seems more useful than making the clients wait indefinitely if they
 // spam us with updates.
 // Note *AST can be still be null if buildAST fails.
-if (WantDiags != WantDiagnostics::No && *AST) {
+if (*AST) {
   OnUpdated((*AST)->getDiagnostics());
   DiagsWereReported = true;
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r338578 - [Format] Fix for bug 35641

2018-08-01 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Aug  1 08:32:56 2018
New Revision: 338578

URL: http://llvm.org/viewvc/llvm-project?rev=338578&view=rev
Log:
[Format] Fix for bug 35641

Summary:
Bug was caused due to comments at the start of scope. For a code like:
```
int func() { //
  int b;
  int c;
}
```
the comment at the first line gets IndentAndNestingLevel (1,1) whereas
the following declarations get only (0,1) which prevents them from insertion
of a new scope. So, I changed the AlignTokenSequence to look at previous
*non-comment* token when deciding whether to introduce a new scope into
stack or not.

Patch by Kadir Cetinkaya!

Reviewers: rsmith, djasper

Reviewed By: djasper

Subscribers: lebedev.ri, cfe-commits, klimek

Tags: #clang

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

Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=338578&r1=338577&r2=338578&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Wed Aug  1 08:32:56 2018
@@ -255,8 +255,14 @@ AlignTokenSequence(unsigned Start, unsig
 Changes[ScopeStack.back()].indentAndNestingLevel())
   ScopeStack.pop_back();
 
+// Compare current token to previous non-comment token to ensure whether
+// it is in a deeper scope or not.
+unsigned PreviousNonComment = i - 1;
+while (PreviousNonComment > Start &&
+   Changes[PreviousNonComment].Tok->is(tok::comment))
+  PreviousNonComment--;
 if (i != Start && Changes[i].indentAndNestingLevel() >
-  Changes[i - 1].indentAndNestingLevel())
+  Changes[PreviousNonComment].indentAndNestingLevel())
   ScopeStack.push_back(i);
 
 bool InsideNestedScope = ScopeStack.size() != 0;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=338578&r1=338577&r2=338578&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Aug  1 08:32:56 2018
@@ -9804,6 +9804,14 @@ TEST_F(FormatTest, AlignConsecutiveDecla
   "});\n",
   Alignment);
   Alignment.PointerAlignment = FormatStyle::PAS_Right;
+
+  // See llvm.org/PR35641
+  Alignment.AlignConsecutiveDeclarations = true;
+  verifyFormat("int func() { //\n"
+   "  int  b;\n"
+   "  unsigned c;\n"
+   "}",
+   Alignment);
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D42742: [clangd] Use pthread instead of thread_local to support more runtimes.

2018-02-06 Thread Ilya Biryukov via cfe-commits
It probably tries doing a standalone build of clang without LLVM.
clang/config.h doesn't seem to include the HAVE_PTHREAD_GETSPECIFIC used in
Context.cpp.
We can either add the corresponding macro to clang's config.h or follow
jyknight's suggestions and figure out if we can remove pthread-specific
code and fix the buildbot in a different way.



On Tue, Feb 6, 2018 at 10:59 AM Mike Lothian via Phabricator <
revi...@reviews.llvm.org> wrote:

> FireBurn added a comment.
>
> This breaks compilation for me on Gentoo's clang-.ebuild
>
> The following patch fixes things for me
>
>   commit a4c071b16bbbc84bbb96d90b51bed8a12127 (HEAD -> master)
>   Author: Mike Lothian 
>   Date:   Tue Feb 6 09:55:41 2018 +
>
>   [clangd] Fix include to use Clang's config.h
>
>   This fixes:
>
>   [clangd] Use pthread instead of thread_local to support more
> runtimes.
>
>   diff --git a/clangd/Context.cpp b/clangd/Context.cpp
>   index 23006778..aed832f4 100644
>   --- a/clangd/Context.cpp
>   +++ b/clangd/Context.cpp
>   @@ -8,7 +8,7 @@
>
>  
> //===-===//
>
>#include "Context.h"
>   -#include "llvm/Config/config.h"
>   +#include "clang/Config/config.h"
>#include 
>
>// The thread-local Context is scoped in a function to avoid init-order
> issues.
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D42742
>
>
>
>

-- 
Regards,
Ilya Biryukov
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r324356 - [clangd] The new threading implementation

2018-02-06 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Feb  6 07:53:42 2018
New Revision: 324356

URL: http://llvm.org/viewvc/llvm-project?rev=324356&view=rev
Log:
[clangd] The new threading implementation

Summary:
In the new threading model clangd creates one thread per file to manage
the AST and one thread to process each of the incoming requests.
The number of actively running threads is bounded by the semaphore to
avoid overloading the system.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, mgorny, jkorous-apple, ioeric, hintonda, cfe-commits

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

Added:
clang-tools-extra/trunk/unittests/clangd/ThreadingTests.cpp
Removed:
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/clangd/Threading.cpp
clang-tools-extra/trunk/clangd/Threading.h
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=324356&r1=324355&r2=324356&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Tue Feb  6 07:53:42 2018
@@ -6,7 +6,6 @@ add_clang_library(clangDaemon
   ClangdLSPServer.cpp
   ClangdServer.cpp
   ClangdUnit.cpp
-  ClangdUnitStore.cpp
   CodeComplete.cpp
   CodeCompletionStrings.cpp
   CompileArgsCache.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=324356&r1=324355&r2=324356&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Tue Feb  6 07:53:42 2018
@@ -11,7 +11,6 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
 
 #include "ClangdUnit.h"
-#include "ClangdUnitStore.h"
 #include "CodeComplete.h"
 #include "CompileArgsCache.h"
 #include "DraftStore.h"

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=324356&r1=324355&r2=324356&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h Tue Feb  6 07:53:42 2018
@@ -151,6 +151,8 @@ using ASTParsedCallback = std::function<
 
 /// Manages resources, required by clangd. Allows to rebuild file with new
 /// contents, and provides AST and Preamble for it.
+/// NOTE: Threading-related bits of CppFile are now deprecated and will be
+/// removed soon.
 class CppFile : public std::enable_shared_from_this {
 public:
   // We only allow to create CppFile as shared_ptr, because a future returned 
by
@@ -178,6 +180,7 @@ public:
   /// that will wait for any ongoing rebuilds to finish and actually set the 
AST
   /// and Preamble to nulls. It can be run on a different thread. This function
   /// is useful to cancel ongoing rebuilds, if any, before removing CppFile.
+  /// DEPRECATED. This function will be removed soon, please do not use it.
   UniqueFunction deferCancelRebuild();
 
   /// Rebuild AST and Preamble synchronously on the calling thread.
@@ -200,6 +203,7 @@ public:
   /// The future to finish rebuild returns a list of diagnostics built during
   /// reparse, or None, if another deferRebuild was called before this
   /// rebuild was finished.
+  /// DEPRECATED. This function will be removed soon, please do not use it.
   UniqueFunction>()>
   deferRebuild(ParseInputs &&Inputs);
 

Removed: clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp?rev=324355&view=auto
==
--- clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp (removed)
@@ -1,37 +0,0 @@
-//===--- ClangdUnitStore.cpp - A ClangdUnits container ---*-C++-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "ClangdUnitStore.h"
-#include "llvm/Support/Path.h"
-#include 
-
-using namespace clang::clangd;
-using namespace clang;
-
-std::shared_ptr CppFileCollection::removeIfPresent(PathRe

[clang-tools-extra] r324361 - [clangd] Fixed compilation on Windows buildbot.

2018-02-06 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Feb  6 08:32:36 2018
New Revision: 324361

URL: http://llvm.org/viewvc/llvm-project?rev=324361&view=rev
Log:
[clangd] Fixed compilation on Windows buildbot.

Modified:
clang-tools-extra/trunk/unittests/clangd/ThreadingTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/ThreadingTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ThreadingTests.cpp?rev=324361&r1=324360&r2=324361&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/ThreadingTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/ThreadingTests.cpp Tue Feb  6 
08:32:36 2018
@@ -17,7 +17,11 @@ class ThreadingTest : public ::testing::
 
 TEST_F(ThreadingTest, TaskRunner) {
   const int TasksCnt = 100;
-  const int IncrementsPerTask = 1000;
+  // This should be const, but MSVC does not allow to use const vars in lambdas
+  // without capture. On the other hand, clang gives a warning that capture of
+  // const var is not required.
+  // Making it non-const makes both compilers happy.
+  int IncrementsPerTask = 1000;
 
   std::mutex Mutex;
   int Counter(0); /* GUARDED_BY(Mutex) */
@@ -25,7 +29,7 @@ TEST_F(ThreadingTest, TaskRunner) {
 AsyncTaskRunner Tasks;
 auto scheduleIncrements = [&]() {
   for (int TaskI = 0; TaskI < TasksCnt; ++TaskI) {
-Tasks.runAsync([&Counter, &Mutex]() {
+Tasks.runAsync([&Counter, &Mutex, IncrementsPerTask]() {
   for (int Increment = 0; Increment < IncrementsPerTask; ++Increment) {
 std::lock_guard Lock(Mutex);
 ++Counter;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r324363 - [clangd] Fixed a bug in the new threading implementation.

2018-02-06 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Feb  6 09:22:58 2018
New Revision: 324363

URL: http://llvm.org/viewvc/llvm-project?rev=324363&view=rev
Log:
[clangd] Fixed a bug in the new threading implementation.

This should fix the buildbots.

Modified:
clang-tools-extra/trunk/clangd/Threading.cpp

Modified: clang-tools-extra/trunk/clangd/Threading.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.cpp?rev=324363&r1=324362&r2=324363&view=diff
==
--- clang-tools-extra/trunk/clangd/Threading.cpp (original)
+++ clang-tools-extra/trunk/clangd/Threading.cpp Tue Feb  6 09:22:58 2018
@@ -40,12 +40,13 @@ void AsyncTaskRunner::runAsync(UniqueFun
   }
 
   auto CleanupTask = llvm::make_scope_exit([this]() {
-std::unique_lock Lock(Mutex);
+std::lock_guard Lock(Mutex);
 int NewTasksCnt = --InFlightTasks;
-Lock.unlock();
-
-if (NewTasksCnt == 0)
+if (NewTasksCnt == 0) {
+  // Note: we can't unlock here because we don't want the object to be
+  // destroyed before we notify.
   TasksReachedZero.notify_one();
+}
   });
 
   std::thread(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r324382 - [clangd] Attempt to unbreak windows buildbots.

2018-02-06 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Feb  6 11:09:44 2018
New Revision: 324382

URL: http://llvm.org/viewvc/llvm-project?rev=324382&view=rev
Log:
[clangd] Attempt to unbreak windows buildbots.

Some buildbots are breaking on trace.test due to using Linux's path
separators. This commit should unbreak them.

Modified:
clang-tools-extra/trunk/test/clangd/trace.test

Modified: clang-tools-extra/trunk/test/clangd/trace.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/trace.test?rev=324382&r1=324381&r2=324382&view=diff
==
--- clang-tools-extra/trunk/test/clangd/trace.test (original)
+++ clang-tools-extra/trunk/test/clangd/trace.test Tue Feb  6 11:09:44 2018
@@ -10,7 +10,7 @@
 #  CHECK: "name": "Preamble"
 #  CHECK: },
 # Finish building the preamble, with filename.
-#  CHECK: "File": "{{.*}}/foo.c"
+#  CHECK: "File": "{{.*(/|\\)}}foo.c"
 # CHECK-NEXT: },
 # CHECK-NEXT: "ph": "E"
 # Start building the file.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r324386 - Revert "[clangd] The new threading implementation" (r324356)

2018-02-06 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue Feb  6 11:22:40 2018
New Revision: 324386

URL: http://llvm.org/viewvc/llvm-project?rev=324386&view=rev
Log:
Revert "[clangd] The new threading implementation" (r324356)

And the follow-up changes r324361 and r324363.
These changes seem to break two buildbots:
  - http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/14091
  - 
http://lab.llvm.org:8011/builders/clang-x86_64-linux-selfhost-modules-2/builds/16001

We will need to investigate what went wrong and resubmit the changes
afterwards.

Added:
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
Removed:
clang-tools-extra/trunk/unittests/clangd/ThreadingTests.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/clangd/Threading.cpp
clang-tools-extra/trunk/clangd/Threading.h
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=324386&r1=324385&r2=324386&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Tue Feb  6 11:22:40 2018
@@ -6,6 +6,7 @@ add_clang_library(clangDaemon
   ClangdLSPServer.cpp
   ClangdServer.cpp
   ClangdUnit.cpp
+  ClangdUnitStore.cpp
   CodeComplete.cpp
   CodeCompletionStrings.cpp
   CompileArgsCache.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=324386&r1=324385&r2=324386&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Tue Feb  6 11:22:40 2018
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
 
 #include "ClangdUnit.h"
+#include "ClangdUnitStore.h"
 #include "CodeComplete.h"
 #include "CompileArgsCache.h"
 #include "DraftStore.h"

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=324386&r1=324385&r2=324386&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h Tue Feb  6 11:22:40 2018
@@ -151,8 +151,6 @@ using ASTParsedCallback = std::function<
 
 /// Manages resources, required by clangd. Allows to rebuild file with new
 /// contents, and provides AST and Preamble for it.
-/// NOTE: Threading-related bits of CppFile are now deprecated and will be
-/// removed soon.
 class CppFile : public std::enable_shared_from_this {
 public:
   // We only allow to create CppFile as shared_ptr, because a future returned 
by
@@ -180,7 +178,6 @@ public:
   /// that will wait for any ongoing rebuilds to finish and actually set the 
AST
   /// and Preamble to nulls. It can be run on a different thread. This function
   /// is useful to cancel ongoing rebuilds, if any, before removing CppFile.
-  /// DEPRECATED. This function will be removed soon, please do not use it.
   UniqueFunction deferCancelRebuild();
 
   /// Rebuild AST and Preamble synchronously on the calling thread.
@@ -203,7 +200,6 @@ public:
   /// The future to finish rebuild returns a list of diagnostics built during
   /// reparse, or None, if another deferRebuild was called before this
   /// rebuild was finished.
-  /// DEPRECATED. This function will be removed soon, please do not use it.
   UniqueFunction>()>
   deferRebuild(ParseInputs &&Inputs);
 

Added: clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp?rev=324386&view=auto
==
--- clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp (added)
+++ clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp Tue Feb  6 11:22:40 2018
@@ -0,0 +1,37 @@
+//===--- ClangdUnitStore.cpp - A ClangdUnits container ---*-C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangdUnitStore.h"
+#include "llvm/Support/Path.h"
+#include 
+
+using namespace clang::clangd;
+using namespace clang;
+
+std::shared_ptr CppFileCollection::removeIfPresent(PathRef File) {
+  std::lock_guard Lock(Mutex);
+
+  auto It

[clang-tools-extra] r324575 - Resubmit "[clangd] The new threading implementation"

2018-02-07 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Feb  7 23:37:35 2018
New Revision: 324575

URL: http://llvm.org/viewvc/llvm-project?rev=324575&view=rev
Log:
Resubmit "[clangd] The new threading implementation"

Initially submitted as r324356 and reverted in r324386.

This change additionally contains a fix to crashes of the buildbots.
The source of the crash was undefined behaviour caused by
std::future<> whose std::promise<> was destroyed without calling
set_value().

Added:
clang-tools-extra/trunk/unittests/clangd/ThreadingTests.cpp
Removed:
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/clangd/Threading.cpp
clang-tools-extra/trunk/clangd/Threading.h
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=324575&r1=324574&r2=324575&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Wed Feb  7 23:37:35 2018
@@ -6,7 +6,6 @@ add_clang_library(clangDaemon
   ClangdLSPServer.cpp
   ClangdServer.cpp
   ClangdUnit.cpp
-  ClangdUnitStore.cpp
   CodeComplete.cpp
   CodeCompletionStrings.cpp
   CompileArgsCache.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=324575&r1=324574&r2=324575&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Feb  7 23:37:35 2018
@@ -146,23 +146,10 @@ std::future ClangdServer::addDocum
  std::move(TaggedFS));
 }
 
-std::future ClangdServer::removeDocument(PathRef File) {
+void ClangdServer::removeDocument(PathRef File) {
   DraftMgr.removeDraft(File);
   CompileArgs.invalidate(File);
-
-  std::promise DonePromise;
-  std::future DoneFuture = DonePromise.get_future();
-
-  auto Callback = BindWithForward(
-  [](std::promise DonePromise, llvm::Error Err) {
-if (Err)
-  ignoreError(std::move(Err));
-DonePromise.set_value();
-  },
-  std::move(DonePromise));
-
-  WorkScheduler.remove(File, std::move(Callback));
-  return DoneFuture;
+  WorkScheduler.remove(File);
 }
 
 std::future ClangdServer::forceReparse(PathRef File) {

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=324575&r1=324574&r2=324575&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Feb  7 23:37:35 2018
@@ -11,7 +11,6 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
 
 #include "ClangdUnit.h"
-#include "ClangdUnitStore.h"
 #include "CodeComplete.h"
 #include "CompileArgsCache.h"
 #include "DraftStore.h"
@@ -158,11 +157,7 @@ public:
 
   /// Remove \p File from list of tracked files, schedule a request to free
   /// resources associated with it.
-  /// \return A future that will become ready when the file is removed and all
-  /// associated resources are freed.
-  /// FIXME: don't return futures here, LSP does not require a response for 
this
-  /// request.
-  std::future removeDocument(PathRef File);
+  void removeDocument(PathRef File);
 
   /// Force \p File to be reparsed using the latest contents.
   /// Will also check if CompileCommand, provided by GlobalCompilationDatabase

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=324575&r1=324574&r2=324575&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h Wed Feb  7 23:37:35 2018
@@ -151,6 +151,8 @@ using ASTParsedCallback = std::function<
 
 /// Manages resources, required by clangd. Allows to rebuild file with new
 /// contents, and provides AST and Preamble for it.
+/// NOTE: Threading-related bits of CppFile are now deprecated and will be
+/// removed soon.
 class CppFile : public std::enable_shared_from_this {
 public:
   // We only allow to create Cp

[clang-tools-extra] r324599 - [clangd] Update include guard in Annotations.h. NFC

2018-02-08 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Feb  8 04:46:34 2018
New Revision: 324599

URL: http://llvm.org/viewvc/llvm-project?rev=324599&view=rev
Log:
[clangd] Update include guard in Annotations.h. NFC

Modified:
clang-tools-extra/trunk/unittests/clangd/Annotations.h

Modified: clang-tools-extra/trunk/unittests/clangd/Annotations.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/Annotations.h?rev=324599&r1=324598&r2=324599&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/Annotations.h (original)
+++ clang-tools-extra/trunk/unittests/clangd/Annotations.h Thu Feb  8 04:46:34 
2018
@@ -27,8 +27,8 @@
 // to define general overlapping ranges.
 //
 //===-===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_ANNOTATIONS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_ANNOTATIONS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_ANNOTATIONS_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_ANNOTATIONS_H
 #include "Protocol.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r324725 - [clangd] Remove threading-related code from ClangdUnit.h

2018-02-09 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Feb  9 02:17:23 2018
New Revision: 324725

URL: http://llvm.org/viewvc/llvm-project?rev=324725&view=rev
Log:
[clangd] Remove threading-related code from ClangdUnit.h

Reviewers: sammccall, hokein, ioeric

Reviewed By: sammccall

Subscribers: klimek, jkorous-apple, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=324725&r1=324724&r2=324725&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Fri Feb  9 02:17:23 2018
@@ -25,6 +25,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include 
+#include 
 #include 
 #include 
 #include 

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=324725&r1=324724&r2=324725&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Fri Feb  9 02:17:23 2018
@@ -29,7 +29,6 @@
 #include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 
 using namespace clang::clangd;
 using namespace clang;
@@ -234,10 +233,6 @@ private:
   llvm::Optional LangOpts;
 };
 
-template  bool futureIsReady(std::shared_future const &Future) {
-  return Future.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
-}
-
 } // namespace
 
 void clangd::dumpAST(ParsedAST &AST, llvm::raw_ostream &OS) {
@@ -250,7 +245,6 @@ ParsedAST::Build(std::unique_ptr Buffer,
  std::shared_ptr PCHs,
  IntrusiveRefCntPtr VFS) {
-
   std::vector ASTDiags;
   StoreDiagsConsumer UnitDiagsConsumer(/*ref*/ ASTDiags);
 
@@ -380,344 +374,145 @@ ParsedAST::ParsedAST(std::shared_ptrAction);
 }
 
-ParsedASTWrapper::ParsedASTWrapper(ParsedASTWrapper &&Wrapper)
-: AST(std::move(Wrapper.AST)) {}
-
-ParsedASTWrapper::ParsedASTWrapper(llvm::Optional AST)
-: AST(std::move(AST)) {}
-
-std::shared_ptr
-CppFile::Create(PathRef FileName, bool StorePreamblesInMemory,
-std::shared_ptr PCHs,
-ASTParsedCallback ASTCallback) {
-  return std::shared_ptr(new CppFile(FileName, StorePreamblesInMemory,
-  std::move(PCHs),
-  std::move(ASTCallback)));
-}
-
 CppFile::CppFile(PathRef FileName, bool StorePreamblesInMemory,
  std::shared_ptr PCHs,
  ASTParsedCallback ASTCallback)
 : FileName(FileName), StorePreamblesInMemory(StorePreamblesInMemory),
-  RebuildCounter(0), RebuildInProgress(false), ASTMemUsage(0),
-  PreambleMemUsage(0), PCHs(std::move(PCHs)),
-  ASTCallback(std::move(ASTCallback)) {
+  PCHs(std::move(PCHs)), ASTCallback(std::move(ASTCallback)) {
   log("Created CppFile for " + FileName);
-
-  std::lock_guard Lock(Mutex);
-  LatestAvailablePreamble = nullptr;
-  PreamblePromise.set_value(nullptr);
-  PreambleFuture = PreamblePromise.get_future();
-
-  ASTPromise.set_value(std::make_shared(llvm::None));
-  ASTFuture = ASTPromise.get_future();
-}
-
-void CppFile::cancelRebuild() { deferCancelRebuild()(); }
-
-UniqueFunction CppFile::deferCancelRebuild() {
-  std::unique_lock Lock(Mutex);
-  // Cancel an ongoing rebuild, if any, and wait for it to finish.
-  unsigned RequestRebuildCounter = ++this->RebuildCounter;
-  // Rebuild asserts that futures aren't ready if rebuild is cancelled.
-  // We want to keep this invariant.
-  if (futureIsReady(PreambleFuture)) {
-PreamblePromise = std::promise>();
-PreambleFuture = PreamblePromise.get_future();
-  }
-  if (futureIsReady(ASTFuture)) {
-ASTPromise = std::promise>();
-ASTFuture = ASTPromise.get_future();
-  }
-
-  Lock.unlock();
-  // Notify about changes to RebuildCounter.
-  RebuildCond.notify_all();
-
-  std::shared_ptr That = shared_from_this();
-  return [That, RequestRebuildCounter]() {
-std::unique_lock Lock(That->Mutex);
-CppFile *This = &*That;
-This->RebuildCond.wait(Lock, [This, RequestRebuildCounter]() {
-  return !This->RebuildInProgress ||
- This->RebuildCounter != RequestRebuildCounter;
-});
-
-// This computation got cancelled itself, do nothing.
-if (This->RebuildCounter != RequestRebuildCounter)
-  return;
-
-// Set empty results for Promises.
-That->PreambleMemUsage = 0;
-That->PreamblePromise.set_value(nullptr);
-That->ASTMemUsage = 0;
-That->ASTPr

  1   2   3   4   5   6   7   8   9   10   >