Skip to content

Commit 7916de6

Browse files
debug: Tweak logging for unseen headers (#196)
1 parent d2d282d commit 7916de6

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

indexer/Driver.cc

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,10 @@ class Driver {
703703
fullIndex.SerializeToOstream(&outputStream);
704704
}
705705

706-
bool isMultiplyIndexedApproximate(const std::string &relativePath,
707-
AbsolutePathRef shardPath) const {
706+
bool
707+
isMultiplyIndexedApproximate(const std::string &relativePath,
708+
AbsolutePathRef shardPath,
709+
absl::flat_hash_set<uint32_t> &badJobIds) const {
708710
auto multiplyIndexed = this->planner.isMultiplyIndexed(
709711
RootRelativePathRef{relativePath, RootKind::Project});
710712
bool isMultiplyIndexed;
@@ -719,15 +721,7 @@ class Driver {
719721
if (auto optFileName = shardPath.fileName()) {
720722
if (auto optJobId = ShardPaths::tryParseJobId(*optFileName)) {
721723
auto jobId = optJobId.value();
722-
spdlog::info("the unknown header was encountered when processing "
723-
"the compilation command at index {} in the "
724-
"compilation database",
725-
jobId);
726-
spdlog::info(
727-
"it may be possible to reproduce this issue by subsetting the "
728-
"compilation database using `jq '.[{}:{}]` {} > bad.json` and "
729-
"re-running `scip-clang --compdb-path=bad.json <flags...>`",
730-
jobId, jobId + 1, this->options.compdbPath.asStringRef());
724+
badJobIds.insert(jobId);
731725
}
732726
}
733727
// Be conservative here
@@ -787,6 +781,8 @@ class Driver {
787781
return true;
788782
};
789783

784+
absl::flat_hash_set<uint32_t> badJobIds{};
785+
790786
scip::IndexBuilder builder{fullIndex};
791787
// TODO: Measure how much time this is taking and parallelize if too slow.
792788
for (auto &paths : this->shardPaths) {
@@ -796,7 +792,7 @@ class Driver {
796792
}
797793
for (auto &doc : *indexShard.mutable_documents()) {
798794
bool isMultiplyIndexed = this->isMultiplyIndexedApproximate(
799-
doc.relative_path(), paths.docsAndExternals.asRef());
795+
doc.relative_path(), paths.docsAndExternals.asRef(), badJobIds);
800796
builder.addDocument(std::move(doc), isMultiplyIndexed);
801797
}
802798
// See NOTE(ref: precondition-deterministic-ext-symbol-docs); in
@@ -808,6 +804,21 @@ class Driver {
808804
}
809805
}
810806

807+
if (!badJobIds.empty()) {
808+
std::vector<uint32_t> badJobIdsSorted{badJobIds.begin(), badJobIds.end()};
809+
absl::c_sort(badJobIdsSorted);
810+
spdlog::info("previously unseen headers were encountered when processing"
811+
" the compilation commands at indexes [{}] in the "
812+
"compilation database",
813+
fmt::join(badJobIdsSorted, ","));
814+
spdlog::info(
815+
"it may be possible to reproduce this issue by subsetting the "
816+
"compilation database using `jq '[.[{}]]` {} > bad.json` and "
817+
"re-running `scip-clang --compdb-path=bad.json <flags...>`",
818+
fmt::join(badJobIdsSorted, ","),
819+
this->options.compdbPath.asStringRef());
820+
}
821+
811822
auto symbolToInfoMap = builder.populateSymbolToInfoMap();
812823

813824
for (auto &paths : this->shardPaths) {

0 commit comments

Comments
 (0)