This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Migrate to proto2 syntax
ClosedPublic

Authored by kbobyrev on Oct 21 2020, 7:15 AM.

Details

Summary

This allows us to check whether enum field is actually sent over the wire or missing.

Diff Detail

Event Timeline

kbobyrev created this revision.Oct 21 2020, 7:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2020, 7:15 AM
kbobyrev requested review of this revision.Oct 21 2020, 7:15 AM
sammccall added inline comments.Oct 22 2020, 4:50 PM
clang-tools-extra/clangd/index/remote/Index.proto
15

can we just switch to proto2 instead?

apart from reserving the zero value, proto3 also requires you to explicitly handle zero in your code (vs being able to set a default in the proto definition)

Offsetting enums by one isn't a big deal, but it can be in other cases (consider a number like num_refs where 0 is a meaningful value and offsetting by 1 is really confusing)

clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
118–123

this -1 and +1 everywhere makes me a bit leery.
Seems a bit easy to reverse or forget it.

What about

template <typename T> std::underlying_type_t<T> toProtobuf(T Value) {
  return static_cast<std::underlying_type_t<T>>(Value) + 1;
}

and the inverse?

291

?!

this is a bitfield

kbobyrev updated this revision to Diff 300229.Oct 23 2020, 4:45 AM

Migrate to proto2 syntax.

kbobyrev updated this revision to Diff 300230.Oct 23 2020, 4:46 AM
kbobyrev marked 3 inline comments as done.

Remove outdated comment.

kbobyrev retitled this revision from [clangd] Offset enum values by when marshalling to [clangd] Migrate to proto2 syntax.Oct 23 2020, 4:47 AM
kbobyrev edited the summary of this revision. (Show Details)
kbobyrev updated this revision to Diff 300231.Oct 23 2020, 4:47 AM

Remove a newline.

sammccall accepted this revision.Oct 23 2020, 5:10 AM
sammccall added inline comments.
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
118–123

I don't think this comment is necessary. The code reads clearly and is more obvious/natural than the alternative you're arguing against here.

137

nit: RelationsRequest

This revision is now accepted and ready to land.Oct 23 2020, 5:10 AM
kbobyrev updated this revision to Diff 300246.Oct 23 2020, 5:26 AM

Remove unnecessary comment and fix a typo.

This revision was landed with ongoing or failed builds.Oct 23 2020, 5:27 AM
This revision was automatically updated to reflect the committed changes.
Harbormaster completed remote builds in B76161: Diff 300231.