This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Allow observation of changes to global CDBs.
ClosedPublic

Authored by sammccall on Nov 13 2018, 7:37 AM.

Details

Summary

Currently, changes *within* CDBs are not tracked (CDB has no facility to do so).
However, discovery of new CDBs are tracked (all files are marked as modified).
Also, files whose compilation commands are explicitly set are marked modified.

The intent is to use this for auto-index. Newly discovered files will be indexed
with low priority.

Diff Detail

Repository
rL LLVM

Event Timeline

sammccall created this revision.Nov 13 2018, 7:37 AM
ilya-biryukov added inline comments.Nov 14 2018, 2:48 AM
clangd/Function.h
90 ↗(On Diff #173853)

I assume the Event is supposed to be used only with non-reference and non-const qualified types.
Maybe add a static assert for that? Something like:
static_assert(std::is_same_v<std::decay_t<T>, T>)

135 ↗(On Diff #173853)

As discussed offline, running the callbacks under the lock might cause deadlocks.
We probably won't hit this case in near future, but it would be nice to find a way to diagnose this situation. Not sure what we can do non-intrusively, though.

clangd/GlobalCompilationDatabase.h
72 ↗(On Diff #173853)

Maybe add a /*Cached*/ comment here too?

unittests/clangd/GlobalCompilationDatabaseTests.cpp
98 ↗(On Diff #173853)

Maybe add an actual test?

sammccall updated this revision to Diff 174014.Nov 14 2018, 4:19 AM
sammccall marked 3 inline comments as done.

Address comments.
Add missing OverlayCDB->Base watching (oops!)

ilya-biryukov accepted this revision.Nov 15 2018, 3:15 AM

LGTM

clangd/Function.h
147 ↗(On Diff #174014)

NIT: Maybe move this static_assert to the top of the class?
I'd argue this is part of the public interface as it puts constraints on the template parameters.

clangd/GlobalCompilationDatabase.cpp
73 ↗(On Diff #174014)

NIT: maybe initialize Cached to a specific value as a precaution against introducing UB with some future changes? The current behavior itself seems correct, it's never accessed when uninitialized, albeit it takes some time to figure it out.

This revision is now accepted and ready to land.Nov 15 2018, 3:15 AM
ilya-biryukov requested changes to this revision.Nov 16 2018, 10:16 AM
ilya-biryukov added inline comments.
clangd/Function.h
108 ↗(On Diff #174014)

We need to unsubscribe this in the assignment operator before overwriting Parent.
Currently we won't delete this from the parent's listeners.

Maybe add a test for that too?

This revision now requires changes to proceed.Nov 16 2018, 10:16 AM
sammccall updated this revision to Diff 174633.Nov 19 2018, 9:52 AM
sammccall marked 2 inline comments as done.

Address comments, add test for Event machinery.

sammccall added inline comments.Nov 19 2018, 9:59 AM
clangd/Function.h
147 ↗(On Diff #174014)

On balance I don't think I agree here.

I'm not sure about having the static assert at all, unless we have reason to believe it will compile but do the wrong thing. Happy to compromise by including it, but I don't think it belongs up front.
It's not very human-readable, and computers are just as happy with it in the private section. It's consistent with some other ways of disallowing compilation, like declaring members private.

ilya-biryukov accepted this revision.Nov 20 2018, 1:38 AM

LGTM

clangd/Function.h
147 ↗(On Diff #174014)

Reference collapsing rules can bite us here, e.g. I don't think making Event<int&> and Event<int&&> valid makes sense, even though both would compile.

It's consistent with some other ways of disallowing compilation, like declaring members private.

Would also argue those private members should be declared at the top of the class for the same reasons.

But we just have different opinions here, it's not terribly important.

This revision is now accepted and ready to land.Nov 20 2018, 1:38 AM
This revision was automatically updated to reflect the committed changes.