[clangd] Respect task cancellation in TUScheduler.
authorSam McCall <sam.mccall@gmail.com>
Thu, 22 Nov 2018 10:22:16 +0000 (10:22 +0000)
committerSam McCall <sam.mccall@gmail.com>
Thu, 22 Nov 2018 10:22:16 +0000 (10:22 +0000)
commita2b048bc4bdf9320249d0ff512fab6f16c2e6e47
treeae2dd8f32376c05e0f2c2e11354e46f6f8791b82
parentaf5b1603ea171aa96175bc29b3a4e55d8bd95cfe
[clangd] Respect task cancellation in TUScheduler.

Summary:
- Reads are never executed if canceled before ready-to run.
  In practice, we finalize cancelled reads eagerly and out-of-order.
- Cancelled reads don't prevent prior updates from being elided, as they don't
  actually depend on the result of the update.
- Updates are downgraded from WantDiagnostics::Yes to WantDiagnostics::Auto when
  cancelled, which allows them to be elided when all dependent reads are
  cancelled and there are subsequent writes. (e.g. when the queue is backed up
  with cancelled requests).

The queue operations aren't optimal (we scan the whole queue for cancelled
tasks every time the scheduler runs, and check cancellation twice in the end).
However I believe these costs are still trivial in practice (compared to any
AST operation) and the logic can be cleanly separated from the rest of the
scheduler.

Reviewers: ilya-biryukov

Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D54746

llvm-svn: 347450
clang-tools-extra/clangd/Cancellation.cpp
clang-tools-extra/clangd/Cancellation.h
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp