[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
This revision was automatically updated to reflect the committed changes. Closed by commit rCTE342137: [clangd] Use JSON format in benchmark requests reader (authored by omtcyfz, committed by ). Changed prior to commit: https://reviews.llvm.org/D51971?vs=165280=165281#toc Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51971 Files: clangd/benchmarks/IndexBenchmark.cpp test/clangd/Inputs/requests.json test/clangd/Inputs/requests.log test/clangd/index-tools.test Index: clangd/benchmarks/IndexBenchmark.cpp === --- clangd/benchmarks/IndexBenchmark.cpp +++ clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,51 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; - - llvm::SmallVector CommaSeparatedValues; - - std::vector RealRequests; - for (auto Line : Strings) { -if (RequestMatcher.match(Line, )) { - R.Query = Matches[1]; - CommaSeparatedValues.clear(); - Line.split(CommaSeparatedValues, ','); - R.Scopes.clear(); - for (auto C : CommaSeparatedValues) { -R.Scopes.push_back(C); - } - RealRequests.push_back(R); + + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); + + // Panic if the provided file couldn't be parsed. + if (!JSONArray) { +llvm::errs() << "Error when parsing JSON requests file: " + << llvm::toString(JSONArray.takeError()); +exit(1); + } + if (!JSONArray->getAsArray()) { +llvm::errs() << "Error: top-level value is not a JSON array: " << Log + << '\n'; +exit(1); + } + + for (const auto : *JSONArray->getAsArray()) { +FuzzyFindRequest Request; +// Panic if the provided file couldn't be parsed. +if (!fromJSON(Item, Request)) { + llvm::errs() << "Error when deserializing request: " << Item << '\n'; + exit(1); } +Requests.push_back(Request); } - return RealRequests; + return Requests; } static void MemQueries(benchmark::State ) { @@ -100,12 +95,12 @@ int main(int argc, char *argv[]) { if (argc < 3) { llvm::errs() << "Usage: " << argv[0] - << " global-symbol-index.yaml fuzzy-find-requests.log " + << " global-symbol-index.yaml requests.json " "BENCHMARK_OPTIONS...\n"; return -1; } IndexFilename = argv[1]; - LogFilename = argv[2]; + RequestsFilename = argv[2]; // Trim first two arguments of the benchmark invocation. argv += 3; argc -= 3; Index: test/clangd/index-tools.test === --- test/clangd/index-tools.test +++ test/clangd/index-tools.test @@ -1,3 +1,5 @@ # RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi +# Pass invalid JSON file and check that IndexBenchmark fails to parse it. +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then not %clangd-benchmark-dir/IndexBenchmark %t.index %t --benchmark_min_time=0.01 ; fi Index: test/clangd/Inputs/requests.json === --- test/clangd/Inputs/requests.json +++
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165280. kbobyrev marked 2 inline comments as done. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,5 @@ # RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi +# Pass invalid JSON file and check that IndexBenchmark fails to parse it. +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then not %clangd-benchmark-dir/IndexBenchmark %t.index %t --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":[""]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,51 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); - llvm::SmallVector CommaSeparatedValues; + // Panic if the provided file couldn't be parsed. + if (!JSONArray) { +llvm::errs() << "Error when parsing JSON
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
ilya-biryukov accepted this revision. ilya-biryukov added a comment. This revision is now accepted and ready to land. LGTM Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:52 + if (!JSONArray->getAsArray()) { +llvm::errs() << "Error when parsing JSON array: " << Log << '\n'; +exit(1); NIT: technically, the parsing succeeded at this point, maybe change to something like "top-level value is not a json array"? Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:60 +if (!fromJSON(Item, Request)) { + llvm::errs() << "Error when parsing request: " << Item << '\n'; + exit(1); NIT: s/parsing/deserializing? https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165277. kbobyrev added a comment. Fix a typo in test comments. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,5 @@ # RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi +# Pass invalid JSON file and check that IndexBenchmark fails to parse it. +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then not %clangd-benchmark-dir/IndexBenchmark %t.index %t --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":[""]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,50 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); - llvm::SmallVector CommaSeparatedValues; + // Panic if the provided file couldn't be parsed. + if (!JSONArray) { +llvm::errs() << "Error when
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165276. kbobyrev marked 2 inline comments as done. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,5 @@ # RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi +# Pass invalid JSON file and check that benchmarks fails to parse it. +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then not %clangd-benchmark-dir/IndexBenchmark %t.index %t --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":[""]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,50 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); - llvm::SmallVector CommaSeparatedValues; + // Panic if the provided file couldn't be parsed. + if (!JSONArray) { +llvm::errs() << "Error when parsing JSON
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
ilya-biryukov added inline comments. Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:48 +llvm::errs() << "Error when parsing json requests file: " + << llvm::toString(JSONArray.takeError()); +exit(1); We should only call `takeError()` when `JSONArray` is an error. Not an array value should be handled separately. BTW, can we add tests with invalid inputs for both of these cases? Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:56 +if (!fromJSON(Item, Request)) { + llvm::errs() << "Error when parsing request.\n"; + exit(1); Maybe also output the request that failed to parse? To help untangle the problem in case it happens. https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165248. kbobyrev marked 3 inline comments as done. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/clangd/index/dex/Iterator.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,3 @@ # RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":[""]}] Index: clang-tools-extra/clangd/index/dex/Iterator.cpp === --- clang-tools-extra/clangd/index/dex/Iterator.cpp +++ clang-tools-extra/clangd/index/dex/Iterator.cpp @@ -198,7 +198,7 @@ public: explicit OrIterator(std::vector> AllChildren) : Children(std::move(AllChildren)) { -assert(Children.size() > 0 && "OR iterator must have at least one child."); +assert(!Children.empty() && "OR iterator should have at least one child."); } /// Returns true if all children are exhausted. @@ -405,12 +405,16 @@ std::unique_ptr createAnd(std::vector> Children) { - return llvm::make_unique(move(Children)); + // If there is exactly one child, pull it one level up: AND(Child) -> Child. + return Children.size() == 1 ? std::move(Children.front()) + : llvm::make_unique(move(Children)); } std::unique_ptr createOr(std::vector> Children) { - return llvm::make_unique(move(Children)); + // If there is exactly one child, pull it one level up: OR(Child) -> Child. + return Children.size() == 1 ? std::move(Children.front()) + : llvm::make_unique(move(Children)); } std::unique_ptr createTrue(DocID Size) { Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,46 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
ilya-biryukov added inline comments. Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:47 + if (!JSONArray || !JSONArray->getAsArray()) { +llvm::errs() << "FATAL ERROR: Couldn't parse request.\n"; +exit(1); If there was a json parsing error, we should consume it and print to the user, i.e. ``` llvm::errs() << "Error when parsing json requests file: " << llvm::toString(std::move(JSONArray)); ``` The user-facing error when an object is not an array should probably be a separate one. Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:53 +FuzzyFindRequest Request; +fromJSON(Item, Request); +Requests.push_back(Request); Check for return value of `fromJSON` and also report an error if it failed? https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165240. kbobyrev added a comment. Fix empty scope in `requests.json`: `%s/"::"/""/g`. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,3 @@ # RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", ""]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":[""]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,41 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); - llvm::SmallVector CommaSeparatedValues; + // Panic if the provided file couldn't be parsed. + if (!JSONArray || !JSONArray->getAsArray()) { +llvm::errs() << "FATAL ERROR: Couldn't parse request.\n"; +exit(1); + } - std::vector RealRequests; - for (auto Line : Strings) { -if (RequestMatcher.match(Line, )) { - R.Query =
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165235. kbobyrev added a comment. Fix the diff after rebase. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,3 @@ # RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":["::"]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,41 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); - llvm::SmallVector CommaSeparatedValues; + // Panic if the provided file couldn't be parsed. + if (!JSONArray || !JSONArray->getAsArray()) { +llvm::errs() << "FATAL ERROR: Couldn't parse request.\n"; +exit(1); + } - std::vector RealRequests; - for (auto Line : Strings) { -if (RequestMatcher.match(Line, )) { - R.Query = Matches[1]; -
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165234. kbobyrev added a comment. Rebase on top of https://reviews.llvm.org/rL342123. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,3 @@ -# RUN: global-symbol-builder %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index +# RUN: clangd-indexer %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":["::"]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,41 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); - llvm::SmallVector CommaSeparatedValues; + // Panic if the provided file couldn't be parsed. + if (!JSONArray || !JSONArray->getAsArray()) { +llvm::errs() << "FATAL ERROR: Couldn't parse request.\n"; +exit(1); + } - std::vector
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev added inline comments. Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:45 + if (!JSONArray) { +llvm::errs() << "Couldn't parse request.\n"; + } ilya-biryukov wrote: > kbobyrev wrote: > > ilya-biryukov wrote: > > > Return from function after error? > > I thought that this should panic instead of returning empty `Requests`: > > otherwise it wouldn't be possible to detect problems in the benchmark > > driver in test, for example (it will just run benchmark over empty list of > > requests instead of doing something useful). > Let's "panic" explicitly, e.g. with `exit(1)`. > We're currently triggering undefined behaviour, not something we want to do. Good point; fixed! https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165232. kbobyrev marked 3 inline comments as done. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,3 @@ # RUN: global-symbol-builder %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":["::"]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,41 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); - llvm::SmallVector CommaSeparatedValues; + // Panic if the provided file couldn't be parsed. + if (!JSONArray || !JSONArray->getAsArray()) { +llvm::errs() << "FATAL ERROR: Couldn't parse request.\n"; +exit(1); + } - std::vector RealRequests; - for (auto Line : Strings) { -if (RequestMatcher.match(Line, )) { - R.Query = Matches[1]; -
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
ilya-biryukov added inline comments. Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:45 + if (!JSONArray) { +llvm::errs() << "Couldn't parse request.\n"; + } kbobyrev wrote: > ilya-biryukov wrote: > > Return from function after error? > I thought that this should panic instead of returning empty `Requests`: > otherwise it wouldn't be possible to detect problems in the benchmark driver > in test, for example (it will just run benchmark over empty list of requests > instead of doing something useful). Let's "panic" explicitly, e.g. with `exit(1)`. We're currently triggering undefined behaviour, not something we want to do. https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev added inline comments. Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:45 + if (!JSONArray) { +llvm::errs() << "Couldn't parse request.\n"; + } ilya-biryukov wrote: > Return from function after error? I thought that this should panic instead of returning empty `Requests`: otherwise it wouldn't be possible to detect problems in the benchmark driver in test, for example (it will just run benchmark over empty list of requests instead of doing something useful). https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165209. kbobyrev marked 2 inline comments as done. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,3 @@ # RUN: global-symbol-builder %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":["::"]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,39 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; + std::vector Requests; + auto JSONArray = llvm::json::parse(Log); - llvm::SmallVector CommaSeparatedValues; + // Shutdown with an error if provided file couldn't be parsed. + if (!JSONArray || !JSONArray->getAsArray()) +llvm::errs() << "Couldn't parse request.\n"; - std::vector RealRequests; - for (auto Line : Strings) { -if (RequestMatcher.match(Line, )) { - R.Query = Matches[1]; -
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
ilya-biryukov added inline comments. Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:45 + if (!JSONArray) { +llvm::errs() << "Couldn't parse request.\n"; + } Return from function after error? Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:47 + } + FuzzyFindRequest Request; + for (const auto : *JSONArray->getAsArray()) { Maybe declare this var inside the loop where it's used? Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:48 + FuzzyFindRequest Request; + for (const auto : *JSONArray->getAsArray()) { +fromJSON(Item, Request); Check that the parsed value is an array and report an error if not? https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev updated this revision to Diff 165110. kbobyrev marked an inline comment as done. kbobyrev added a comment. @ilya-biryukov thanks! I was assuming that the `StringRef` constructor parses user-provided string :( `llvm::json::Array` is used now. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,3 @@ # RUN: global-symbol-builder %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +[{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}, +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":["::"]}] Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -19,56 +19,37 @@ #include const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads JSON array of serialized FuzzyFindRequest's from user-provided file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); - llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; - llvm::SmallVector CommaSeparatedValues; - - std::vector RealRequests; - for (auto Line : Strings) { -if (RequestMatcher.match(Line, )) { - R.Query = Matches[1]; - CommaSeparatedValues.clear(); - Line.split(CommaSeparatedValues, ','); -
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
ilya-biryukov added a comment. In https://reviews.llvm.org/D51971#1232064, @kbobyrev wrote: > Apparently, the parsing seems to be wrong; I should fix that first. Oh, yeah, just use `llvm::json::parse` https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev planned changes to this revision. kbobyrev marked an inline comment as done. kbobyrev added a comment. Apparently, the parsing seems to be wrong; I should fix that first. https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
ilya-biryukov added inline comments. Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:21 +using clang::clangd::loadIndex; +using clang::clangd::SymbolIndex; We don't need the usings, just shorten the name on usage sites (usages are inside namespace clangd) Comment at: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:39 -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads '\n'-separated FuzzyFindRequest JSON representations from user-provided +// file. Maybe read a JSON array from the file instead? I.e. one would have to write `[{/*request1*/}, {/*request2*/}, ..]` instead of putting a request per line Pros: we get valid json, can have prettified forms too. Cons: might be a bit harder to construct the json array. But don't think it's a big deal. https://reviews.llvm.org/D51971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51971: [clangd] Use JSON format in benchmark requests reader
kbobyrev created this revision. kbobyrev added reviewers: ioeric, ilya-biryukov. kbobyrev added a project: clang-tools-extra. Herald added subscribers: kadircet, arphaman, jkorous, MaskRay. After `FuzzyFindRequest` JSON (de)serialization was introduced, it should replace ad-hoc fuzzy-find request parsing implemented in the IndexBenchmark driver. https://reviews.llvm.org/D51971 Files: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp clang-tools-extra/test/clangd/Inputs/requests.json clang-tools-extra/test/clangd/Inputs/requests.log clang-tools-extra/test/clangd/index-tools.test Index: clang-tools-extra/test/clangd/index-tools.test === --- clang-tools-extra/test/clangd/index-tools.test +++ clang-tools-extra/test/clangd/index-tools.test @@ -1,3 +1,3 @@ # RUN: global-symbol-builder %p/Inputs/BenchmarkSource.cpp -- -I%p/Inputs > %t.index # FIXME: By default, benchmarks are excluded from the list of default targets hence not built. Find a way to depend on benchmarks to run the next command. -# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.log --benchmark_min_time=0.01 ; fi +# RUN: if [ -f %clangd-benchmark-dir/IndexBenchmark ]; then %clangd-benchmark-dir/IndexBenchmark %t.index %p/Inputs/requests.json --benchmark_min_time=0.01 ; fi Index: clang-tools-extra/test/clangd/Inputs/requests.log === --- clang-tools-extra/test/clangd/Inputs/requests.log +++ /dev/null @@ -1,5 +0,0 @@ -V[09:08:34.301] Code complete: fuzzyFind("s", scopes=[llvm::]) -V[09:08:34.368] Code complete: fuzzyFind("sy", scopes=[llvm::]) -V[09:08:34.442] Code complete: fuzzyFind("sys", scopes=[llvm::]) -V[09:09:12.075] Code complete: fuzzyFind("Dex", scopes=[clang::clangd::, clang::, clang::clangd::dex::]) -V[09:09:12.075] Code complete: fuzzyFind("Variable", scopes=[]) Index: clang-tools-extra/test/clangd/Inputs/requests.json === --- /dev/null +++ clang-tools-extra/test/clangd/Inputs/requests.json @@ -0,0 +1,7 @@ +{"MaxCandidateCount":100,"ProximityPaths":["/usr/home/user/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp"],"Query":"OMP","RestrictForCodeCompletion":true,"Scopes":["clang::"]}) +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"s","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}) +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sy","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}) +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}) +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"sys","RestrictForCodeCompletion":true,"Scopes":["llvm::", "::"]}) +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Dex","RestrictForCodeCompletion":true,"Scopes":["clang::clangd::", "clang::", "clang::clangd::dex::"]}) +{"MaxCandidateCount":100,"ProximityPaths":[],"Query":"Variable","RestrictForCodeCompletion":true,"Scopes":["::"]}) Index: clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp === --- clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp +++ clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp @@ -18,57 +18,42 @@ #include #include +using clang::clangd::loadIndex; +using clang::clangd::SymbolIndex; + const char *IndexFilename; -const char *LogFilename; +const char *RequestsFilename; namespace clang { namespace clangd { namespace { -std::unique_ptr buildMem() { - return clang::clangd::loadIndex(IndexFilename, {}, false); +std::unique_ptr buildMem() { + return loadIndex(IndexFilename, {}, false); } -std::unique_ptr buildDex() { - return clang::clangd::loadIndex(IndexFilename, {}, true); +std::unique_ptr buildDex() { + return loadIndex(IndexFilename, {}, true); } -// This function processes user-provided Log file with fuzzy find requests in -// the following format: -// -// fuzzyFind("UnqualifiedName", scopes=["clang::", "clang::clangd::"]) -// -// It constructs vector of FuzzyFindRequests which is later used for the -// benchmarks. -std::vector extractQueriesFromLogs() { - llvm::Regex RequestMatcher("fuzzyFind\\(\"([a-zA-Z]*)\", scopes=\\[(.*)\\]"); - llvm::SmallVector Matches; - std::ifstream InputStream(LogFilename); +// Reads '\n'-separated FuzzyFindRequest JSON representations from user-provided +// file. +std::vector extractQueriesFromLogs() { + std::ifstream InputStream(RequestsFilename); std::string Log((std::istreambuf_iterator(InputStream)), std::istreambuf_iterator()); llvm::StringRef Temporary(Log); - llvm::SmallVector Strings; - Temporary.split(Strings, '\n'); - - clang::clangd::FuzzyFindRequest R; - R.MaxCandidateCount = 100; - - llvm::SmallVector CommaSeparatedValues; + llvm::SmallVector Lines; +