This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Narrow and document a loophole in blockUntilIdle
ClosedPublic

Authored by sammccall on Feb 17 2021, 3:59 AM.

Details

Summary

blockUntilIdle of a parent can't always be correctly implemented as

return ChildA.blockUntilIdle() && ChildB.blockUntilIdle()

The problem is that B can schedule work on A while we're waiting on it.

I believe this is theoretically possible today between CDB and background index.
Modules open more possibilities and it's hard to reason about all of them.

I don't have a perfect fix, and the abstraction is too good to lose. this patch:

  • calls out why we block on workscheduler first, and asserts correctness
  • documents the issue
  • reduces the practical possibility of spuriously returning true significantly

This function is ultimately only for testing, so we're driving down flake rate.

Diff Detail

Event Timeline

sammccall created this revision.Feb 17 2021, 3:59 AM
sammccall requested review of this revision.Feb 17 2021, 3:59 AM

LG for the blockUntilIdle update, but feels like two patches wind up together :(

kadircet added inline comments.Feb 18 2021, 2:19 AM
clang-tools-extra/clangd/ClangdServer.cpp
893

this is extending the Deadline in theory, e.g. if user requested idleness in 10 seconds, this can now wait for up to 20 seconds. but this was possible in the previous case too, e.g. CDB could block for 10 seconds, and then bgindex would block for another 10 seconds, and mentioned this is only for tests, so should be fine (but might be worth mentioning in the comments.)

sammccall updated this revision to Diff 324609.Feb 18 2021, 6:06 AM

Revert unintended changes, add FIXME

Doh, sorry about the garbled patch

clang-tools-extra/clangd/ClangdServer.cpp
893

Right - the idea with Deadline is it's something absolute you can pass around, and here we are creating a new one for each call.

This is wrong, but it's consistent with the code before this patch and I'd rather not fix both at once. Added a FIXME to the header.

(To fix this we'd want to change the signature of BackgroundIndex to take a Deadline too)

kadircet accepted this revision.Feb 19 2021, 4:56 AM

thanks, lgtm!

This revision is now accepted and ready to land.Feb 19 2021, 4:56 AM