forked from OSchip/llvm-project
[clangd] Fix more MSVC compilation failures.
It turns out MSVC does not allow non-copyable classes in std::future and std::promise template arguments. llvm-svn: 309720
This commit is contained in:
parent
35dd1ac29c
commit
6e1f3b1c90
|
@ -275,7 +275,7 @@ std::string ClangdServer::dumpAST(PathRef File) {
|
||||||
assert(Resources && "dumpAST is called for non-added document");
|
assert(Resources && "dumpAST is called for non-added document");
|
||||||
|
|
||||||
std::string Result;
|
std::string Result;
|
||||||
Resources->getAST().get().runUnderLock([&Result](ParsedAST *AST) {
|
Resources->getAST().get()->runUnderLock([&Result](ParsedAST *AST) {
|
||||||
llvm::raw_string_ostream ResultOS(Result);
|
llvm::raw_string_ostream ResultOS(Result);
|
||||||
if (AST) {
|
if (AST) {
|
||||||
clangd::dumpAST(*AST, ResultOS);
|
clangd::dumpAST(*AST, ResultOS);
|
||||||
|
@ -299,7 +299,7 @@ Tagged<std::vector<Location>> ClangdServer::findDefinitions(PathRef File,
|
||||||
assert(Resources && "Calling findDefinitions on non-added file");
|
assert(Resources && "Calling findDefinitions on non-added file");
|
||||||
|
|
||||||
std::vector<Location> Result;
|
std::vector<Location> Result;
|
||||||
Resources->getAST().get().runUnderLock([Pos, &Result](ParsedAST *AST) {
|
Resources->getAST().get()->runUnderLock([Pos, &Result](ParsedAST *AST) {
|
||||||
if (!AST)
|
if (!AST)
|
||||||
return;
|
return;
|
||||||
Result = clangd::findDefinitions(*AST, Pos);
|
Result = clangd::findDefinitions(*AST, Pos);
|
||||||
|
|
|
@ -707,7 +707,7 @@ CppFile::CppFile(PathRef FileName, tooling::CompileCommand Command,
|
||||||
PreamblePromise.set_value(nullptr);
|
PreamblePromise.set_value(nullptr);
|
||||||
PreambleFuture = PreamblePromise.get_future();
|
PreambleFuture = PreamblePromise.get_future();
|
||||||
|
|
||||||
ASTPromise.set_value(ParsedASTWrapper(llvm::None));
|
ASTPromise.set_value(std::make_shared<ParsedASTWrapper>(llvm::None));
|
||||||
ASTFuture = ASTPromise.get_future();
|
ASTFuture = ASTPromise.get_future();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,7 +722,7 @@ void CppFile::cancelRebuilds() {
|
||||||
PreambleFuture = PreamblePromise.get_future();
|
PreambleFuture = PreamblePromise.get_future();
|
||||||
}
|
}
|
||||||
if (futureIsReady(ASTFuture)) {
|
if (futureIsReady(ASTFuture)) {
|
||||||
ASTPromise = std::promise<ParsedASTWrapper>();
|
ASTPromise = std::promise<std::shared_ptr<ParsedASTWrapper>>();
|
||||||
ASTFuture = ASTPromise.get_future();
|
ASTFuture = ASTPromise.get_future();
|
||||||
}
|
}
|
||||||
// Now wait for rebuild to finish.
|
// Now wait for rebuild to finish.
|
||||||
|
@ -730,7 +730,7 @@ void CppFile::cancelRebuilds() {
|
||||||
|
|
||||||
// Return empty results for futures.
|
// Return empty results for futures.
|
||||||
PreamblePromise.set_value(nullptr);
|
PreamblePromise.set_value(nullptr);
|
||||||
ASTPromise.set_value(ParsedASTWrapper(llvm::None));
|
ASTPromise.set_value(std::make_shared<ParsedASTWrapper>(llvm::None));
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Optional<std::vector<DiagWithFixIts>>
|
llvm::Optional<std::vector<DiagWithFixIts>>
|
||||||
|
@ -763,7 +763,7 @@ CppFile::deferRebuild(StringRef NewContents,
|
||||||
this->PreambleFuture = this->PreamblePromise.get_future();
|
this->PreambleFuture = this->PreamblePromise.get_future();
|
||||||
}
|
}
|
||||||
if (futureIsReady(this->ASTFuture)) {
|
if (futureIsReady(this->ASTFuture)) {
|
||||||
this->ASTPromise = std::promise<ParsedASTWrapper>();
|
this->ASTPromise = std::promise<std::shared_ptr<ParsedASTWrapper>>();
|
||||||
this->ASTFuture = this->ASTPromise.get_future();
|
this->ASTFuture = this->ASTPromise.get_future();
|
||||||
}
|
}
|
||||||
} // unlock Mutex.
|
} // unlock Mutex.
|
||||||
|
@ -878,7 +878,7 @@ CppFile::deferRebuild(StringRef NewContents,
|
||||||
return Diagnostics; // Our rebuild request was cancelled, don't set
|
return Diagnostics; // Our rebuild request was cancelled, don't set
|
||||||
// ASTPromise.
|
// ASTPromise.
|
||||||
|
|
||||||
That->ASTPromise.set_value(ParsedASTWrapper(std::move(NewAST)));
|
That->ASTPromise.set_value(std::make_shared<ParsedASTWrapper>(std::move(NewAST)));
|
||||||
} // unlock Mutex
|
} // unlock Mutex
|
||||||
|
|
||||||
return Diagnostics;
|
return Diagnostics;
|
||||||
|
@ -898,7 +898,7 @@ std::shared_ptr<const PreambleData> CppFile::getPossiblyStalePreamble() const {
|
||||||
return LatestAvailablePreamble;
|
return LatestAvailablePreamble;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_future<ParsedASTWrapper> CppFile::getAST() const {
|
std::shared_future<std::shared_ptr<ParsedASTWrapper>> CppFile::getAST() const {
|
||||||
std::lock_guard<std::mutex> Lock(Mutex);
|
std::lock_guard<std::mutex> Lock(Mutex);
|
||||||
return ASTFuture;
|
return ASTFuture;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,10 +104,6 @@ private:
|
||||||
// Provides thread-safe access to ParsedAST.
|
// Provides thread-safe access to ParsedAST.
|
||||||
class ParsedASTWrapper {
|
class ParsedASTWrapper {
|
||||||
public:
|
public:
|
||||||
// MSVC does not allow to use types without default constructor in
|
|
||||||
// std::promise<> template arguments.
|
|
||||||
ParsedASTWrapper() = default;
|
|
||||||
|
|
||||||
ParsedASTWrapper(ParsedASTWrapper &&Wrapper);
|
ParsedASTWrapper(ParsedASTWrapper &&Wrapper);
|
||||||
ParsedASTWrapper(llvm::Optional<ParsedAST> AST);
|
ParsedASTWrapper(llvm::Optional<ParsedAST> AST);
|
||||||
|
|
||||||
|
@ -192,7 +188,10 @@ public:
|
||||||
|
|
||||||
/// Returns a future to get the most fresh AST for a file. Returned AST is
|
/// Returns a future to get the most fresh AST for a file. Returned AST is
|
||||||
/// wrapped to prevent concurrent accesses.
|
/// wrapped to prevent concurrent accesses.
|
||||||
std::shared_future<ParsedASTWrapper> getAST() const;
|
/// We use std::shared_ptr here because MVSC fails to compile non-copyable
|
||||||
|
/// classes as template arguments of promise/future. It is guaranteed to
|
||||||
|
/// always be non-null.
|
||||||
|
std::shared_future<std::shared_ptr<ParsedASTWrapper>> getAST() const;
|
||||||
|
|
||||||
/// Get CompileCommand used to build this CppFile.
|
/// Get CompileCommand used to build this CppFile.
|
||||||
tooling::CompileCommand const &getCompileCommand() const;
|
tooling::CompileCommand const &getCompileCommand() const;
|
||||||
|
@ -226,8 +225,10 @@ private:
|
||||||
std::condition_variable RebuildCond;
|
std::condition_variable RebuildCond;
|
||||||
|
|
||||||
/// Promise and future for the latests AST. Fulfilled during rebuild.
|
/// Promise and future for the latests AST. Fulfilled during rebuild.
|
||||||
std::promise<ParsedASTWrapper> ASTPromise;
|
/// We use std::shared_ptr here because MVSC fails to compile non-copyable
|
||||||
std::shared_future<ParsedASTWrapper> ASTFuture;
|
/// classes as template arguments of promise/future.
|
||||||
|
std::promise<std::shared_ptr<ParsedASTWrapper>> ASTPromise;
|
||||||
|
std::shared_future<std::shared_ptr<ParsedASTWrapper>> ASTFuture;
|
||||||
|
|
||||||
/// Promise and future for the latests Preamble. Fulfilled during rebuild.
|
/// Promise and future for the latests Preamble. Fulfilled during rebuild.
|
||||||
std::promise<std::shared_ptr<const PreambleData>> PreamblePromise;
|
std::promise<std::shared_ptr<const PreambleData>> PreamblePromise;
|
||||||
|
|
Loading…
Reference in New Issue