[clang-tools-extra] r291446 - [include-fixer] Load symbol index asynchronously.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 9 07:18:28 PST 2017
Author: d0k
Date: Mon Jan 9 09:18:28 2017
New Revision: 291446
URL: http://llvm.org/viewvc/llvm-project?rev=291446&view=rev
Log:
[include-fixer] Load symbol index asynchronously.
We don't actually need the index until parse time, so fetch it in the
background and start parsing. By the time it is actually needed it's
likely that the loading phase has completed in the background.
Modified:
clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h
clang-tools-extra/trunk/include-fixer/plugin/IncludeFixerPlugin.cpp
clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
Modified: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp?rev=291446&r1=291445&r2=291446&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp Mon Jan 9 09:18:28 2017
@@ -64,7 +64,7 @@ SymbolIndexManager::search(llvm::StringR
do {
std::vector<clang::find_all_symbols::SymbolInfo> Symbols;
for (const auto &DB : SymbolIndices) {
- auto Res = DB->search(Names.back().str());
+ auto Res = DB.get()->search(Names.back());
Symbols.insert(Symbols.end(), Res.begin(), Res.end());
}
Modified: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h?rev=291446&r1=291445&r2=291446&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h (original)
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.h Mon Jan 9 09:18:28 2017
@@ -13,6 +13,7 @@
#include "SymbolIndex.h"
#include "find-all-symbols/SymbolInfo.h"
#include "llvm/ADT/StringRef.h"
+#include <future>
namespace clang {
namespace include_fixer {
@@ -21,8 +22,8 @@ namespace include_fixer {
/// to an indentifier in the source code from multiple symbol databases.
class SymbolIndexManager {
public:
- void addSymbolIndex(std::unique_ptr<SymbolIndex> DB) {
- SymbolIndices.push_back(std::move(DB));
+ void addSymbolIndex(std::function<std::unique_ptr<SymbolIndex>()> F) {
+ SymbolIndices.push_back(std::async(std::launch::async, F));
}
/// Search for header files to be included for an identifier.
@@ -39,7 +40,7 @@ public:
search(llvm::StringRef Identifier, bool IsNestedSearch = true) const;
private:
- std::vector<std::unique_ptr<SymbolIndex>> SymbolIndices;
+ std::vector<std::shared_future<std::unique_ptr<SymbolIndex>>> SymbolIndices;
};
} // namespace include_fixer
Modified: clang-tools-extra/trunk/include-fixer/plugin/IncludeFixerPlugin.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/plugin/IncludeFixerPlugin.cpp?rev=291446&r1=291445&r2=291446&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/plugin/IncludeFixerPlugin.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/plugin/IncludeFixerPlugin.cpp Mon Jan 9 09:18:28 2017
@@ -61,23 +61,26 @@ public:
Input = Arg.substr(strlen("-input="));
}
- llvm::ErrorOr<std::unique_ptr<include_fixer::YamlSymbolIndex>> SymbolIdx(
- nullptr);
- if (DB == "yaml") {
- if (!Input.empty()) {
- SymbolIdx = include_fixer::YamlSymbolIndex::createFromFile(Input);
- } else {
- // If we don't have any input file, look in the directory of the first
- // file and its parents.
- const FrontendOptions &FO = CI.getFrontendOpts();
- SmallString<128> AbsolutePath(
- tooling::getAbsolutePath(FO.Inputs[0].getFile()));
- StringRef Directory = llvm::sys::path::parent_path(AbsolutePath);
- SymbolIdx = include_fixer::YamlSymbolIndex::createFromDirectory(
- Directory, "find_all_symbols_db.yaml");
+ std::string InputFile = CI.getFrontendOpts().Inputs[0].getFile();
+ auto CreateYamlIdx = [=]() -> std::unique_ptr<include_fixer::SymbolIndex> {
+ llvm::ErrorOr<std::unique_ptr<include_fixer::YamlSymbolIndex>> SymbolIdx(
+ nullptr);
+ if (DB == "yaml") {
+ if (!Input.empty()) {
+ SymbolIdx = include_fixer::YamlSymbolIndex::createFromFile(Input);
+ } else {
+ // If we don't have any input file, look in the directory of the first
+ // file and its parents.
+ SmallString<128> AbsolutePath(tooling::getAbsolutePath(InputFile));
+ StringRef Directory = llvm::sys::path::parent_path(AbsolutePath);
+ SymbolIdx = include_fixer::YamlSymbolIndex::createFromDirectory(
+ Directory, "find_all_symbols_db.yaml");
+ }
}
- }
- SymbolIndexMgr->addSymbolIndex(std::move(*SymbolIdx));
+ return std::move(*SymbolIdx);
+ };
+
+ SymbolIndexMgr->addSymbolIndex(std::move(CreateYamlIdx));
return true;
}
Modified: clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp?rev=291446&r1=291445&r2=291446&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp Mon Jan 9 09:18:28 2017
@@ -179,30 +179,36 @@ createSymbolIndexManager(StringRef FileP
find_all_symbols::SymbolInfo::SymbolKind::Unknown,
CommaSplits[I].trim(), 1, {}, /*NumOccurrences=*/E - I));
}
- SymbolIndexMgr->addSymbolIndex(
- llvm::make_unique<include_fixer::InMemorySymbolIndex>(Symbols));
+ SymbolIndexMgr->addSymbolIndex([=]() {
+ return llvm::make_unique<include_fixer::InMemorySymbolIndex>(Symbols);
+ });
break;
}
case yaml: {
- llvm::ErrorOr<std::unique_ptr<include_fixer::YamlSymbolIndex>> DB(nullptr);
- if (!Input.empty()) {
- DB = include_fixer::YamlSymbolIndex::createFromFile(Input);
- } else {
- // If we don't have any input file, look in the directory of the first
- // file and its parents.
- SmallString<128> AbsolutePath(tooling::getAbsolutePath(FilePath));
- StringRef Directory = llvm::sys::path::parent_path(AbsolutePath);
- DB = include_fixer::YamlSymbolIndex::createFromDirectory(
- Directory, "find_all_symbols_db.yaml");
- }
+ auto CreateYamlIdx = [=]() -> std::unique_ptr<include_fixer::SymbolIndex> {
+ llvm::ErrorOr<std::unique_ptr<include_fixer::YamlSymbolIndex>> DB(
+ nullptr);
+ if (!Input.empty()) {
+ DB = include_fixer::YamlSymbolIndex::createFromFile(Input);
+ } else {
+ // If we don't have any input file, look in the directory of the
+ // first
+ // file and its parents.
+ SmallString<128> AbsolutePath(tooling::getAbsolutePath(FilePath));
+ StringRef Directory = llvm::sys::path::parent_path(AbsolutePath);
+ DB = include_fixer::YamlSymbolIndex::createFromDirectory(
+ Directory, "find_all_symbols_db.yaml");
+ }
- if (!DB) {
- llvm::errs() << "Couldn't find YAML db: " << DB.getError().message()
- << '\n';
- return nullptr;
- }
+ if (!DB) {
+ llvm::errs() << "Couldn't find YAML db: " << DB.getError().message()
+ << '\n';
+ return nullptr;
+ }
+ return std::move(*DB);
+ };
- SymbolIndexMgr->addSymbolIndex(std::move(*DB));
+ SymbolIndexMgr->addSymbolIndex(std::move(CreateYamlIdx));
break;
}
}
Modified: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp?rev=291446&r1=291445&r2=291446&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp Mon Jan 9 09:18:28 2017
@@ -85,8 +85,9 @@ static std::string runIncludeFixer(
1, {}),
};
auto SymbolIndexMgr = llvm::make_unique<include_fixer::SymbolIndexManager>();
- SymbolIndexMgr->addSymbolIndex(
- llvm::make_unique<include_fixer::InMemorySymbolIndex>(Symbols));
+ SymbolIndexMgr->addSymbolIndex([=]() {
+ return llvm::make_unique<include_fixer::InMemorySymbolIndex>(Symbols);
+ });
std::vector<IncludeFixerContext> FixerContexts;
IncludeFixerActionFactory Factory(*SymbolIndexMgr, FixerContexts, "llvm");
More information about the cfe-commits
mailing list