Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add analyzer to enforce usage of VT versions of marshalling and unmarshalling #2043

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

tstirrat15
Copy link
Contributor

@tstirrat15 tstirrat15 commented Aug 27, 2024

Description

Calling proto.Marshal requires calling reflection code, where the VT methods are called directly and are more efficient. This adds a linter that enforces that.

Note

The exclusions ended up being fairly broad because of the size of the excluded packages. One thing that was discussed was implementing // nolint comments for this analyzer, but that would require either writing that manually into the analyzer or making use of a package that provides that functionality, and I wasn't sure whether we wanted to take that on right now.

Changes

  • Add new analyzer and tests
  • Add analyzer to toolchain
  • Add some exceptions for the analyzer
  • Fix the problems identified by the analyzer
  • Bump vtproto version to pick up changes that deal with nested one_ofs + messages like we have in the SetOperation definition
  • Regenerate the protoc-generated files according to the above

Testing

Review the code. See that lints go green.

@tstirrat15 tstirrat15 requested review from vroldanbet and a team as code owners August 27, 2024 00:25
@github-actions github-actions bot added area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) area/dependencies Affects dependencies labels Aug 27, 2024
@tstirrat15
Copy link
Contributor Author

Had a conversation with @josephschorr where it'd be nice to have a sort of snapshot test that serializes a schema out to protobuf bytes using both VT and non-VT, and then the test deserializes using the opposite and then asserts that they agree, with the idea being that it's a snapshot test that will alert us if our serialization or deserialization changes meaningfully.

"golang.org/x/tools/go/ast/inspector"
)

func sliceMap(s []string, f func(value string) string) []string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a function for this in the lo library we import some places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it named the same? I copied this code from an existing analyzer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vroldanbet
vroldanbet previously approved these changes Aug 29, 2024
Copy link
Contributor

@vroldanbet vroldanbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just 2 nits

magefiles/lint.go Show resolved Hide resolved
"golang.org/x/tools/go/ast/inspector"
)

func sliceMap(s []string, f func(value string) string) []string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vroldanbet
vroldanbet previously approved these changes Aug 30, 2024
Copy link
Contributor

@vroldanbet vroldanbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter seems to be failing in CI, but changes look good to me!

vroldanbet
vroldanbet previously approved these changes Aug 30, 2024
josephschorr
josephschorr previously approved these changes Aug 30, 2024
Copy link
Member

@josephschorr josephschorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tstirrat15 tstirrat15 added this pull request to the merge queue Aug 30, 2024
Merged via the queue into main with commit 506248a Aug 30, 2024
22 checks passed
@tstirrat15 tstirrat15 deleted the 2036-enforce-usage-of-VT branch August 30, 2024 17:41
@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/datastore Affects the storage system area/dependencies Affects dependencies area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants