This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix race in FileIndex that sometimes temporarily lost updates.
ClosedPublic

Authored by sammccall on Jun 30 2020, 10:30 AM.

Details

Summary

FileIndex was built out of threadsafe components, so update() didn't have data
races, but wasn't actually correct.

Diff Detail

Event Timeline

sammccall created this revision.Jun 30 2020, 10:30 AM
kadircet accepted this revision.Jul 1 2020, 2:14 AM

LGTM, thanks!

clang-tools-extra/clangd/index/FileIndex.cpp
270

Bumping the version in update and just exposing it in buildIndex feels more natural, WDYT?

Might even enable us to get rid of some redundant resets (not that it is expensive ..), imagine a sequencing like:

  • update1
  • update2
  • buildIndex1
  • buildIndex2

even though both build the same index, they got different version numbers hence both will reset the current index.

clang-tools-extra/clangd/index/Symbol.h
190

i suppose this is for testing::SizeIs right?

This revision is now accepted and ready to land.Jul 1 2020, 2:14 AM
kadircet added inline comments.Jul 1 2020, 2:24 AM
clang-tools-extra/clangd/index/FileIndex.h
97

oh and also maybe use size_t ?

as there's only one (well three actually, if you count both preamble and main-file index separately, and one in background-index) instance of FileSymbols for a single clangd instance, hence we could in theory bump this number with every keystroke :/

I suppose 4 bytes is also far from any practical limits, but pushing it as far as possible wouldn't hurt?

sammccall marked 5 inline comments as done.Jul 1 2020, 7:47 AM
sammccall added inline comments.
clang-tools-extra/clangd/index/FileIndex.cpp
270

Yeah, that makes sense.

clang-tools-extra/clangd/index/Symbol.h
190

Right, gtest is weird. Could live without it, seems harmless though.

This revision was automatically updated to reflect the committed changes.
sammccall marked 2 inline comments as done.