This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Ensure that we reply to each call exactly once. NFC (I think!)
ClosedPublic

Authored by sammccall on Oct 18 2018, 7:40 AM.

Details

Summary

In debug builds, getting this wrong will trigger asserts.
In production builds, it will send an error reply if none was sent,
and drop redundant replies. (And log).

No tests because this is always a programming error.
(We did have some cases of this, but I fixed them with the new dispatcher).

Diff Detail

Event Timeline

sammccall created this revision.Oct 18 2018, 7:40 AM
ioeric added inline comments.Oct 19 2018, 3:14 AM
clangd/ClangdLSPServer.cpp
174

As discussed offline, we could potentially make this non-copyable to make harder to be duplicated and called more than once. And we could also get rid of the shared State in the functor.

sammccall updated this revision to Diff 170593.Oct 23 2018, 2:46 AM

Make ReplyOnce move-only.

sammccall marked an inline comment as done.Oct 23 2018, 2:46 AM
ioeric added inline comments.Oct 24 2018, 6:13 AM
clangd/ClangdLSPServer.cpp
112

Do we have guarantee that Tracer.Args outlives Reply?

sammccall updated this revision to Diff 170866.Oct 24 2018, 6:20 AM

Clarify Span::Args lifetime.

sammccall added inline comments.Oct 24 2018, 6:22 AM
clangd/ClangdLSPServer.cpp
112

Yes, assuming the Handler propagates contexts properly.
The args are owned by the context created by the trace::Span.
Added a comment to Span to guarantee this.

ioeric accepted this revision.Oct 24 2018, 6:26 AM
This revision is now accepted and ready to land.Oct 24 2018, 6:26 AM
This revision was automatically updated to reflect the committed changes.