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

Update to match Editions behavior of latest protoc (v25.0) #191

Merged
merged 8 commits into from
Oct 27, 2023

Conversation

jhump
Copy link
Member

@jhump jhump commented Oct 27, 2023

Between v24 and v25, the implementation or editions inside of protoc changed quite rather drastically. Most of the complexity having to do with computation of feature defaults and feature set resolution has been completely removed 🎉.

There are some changes to exported symbols made in this branch, like removal of the exported options.FeaturesResolverCache. But this is technically not a breaking change because those symbols were never included in a released version. So this branch is fully backwards-compatible with the previous release (though not the previous commit).

It's a large-ish change, so it might be easier to digest if reviewed commit-by-commit.

This still does not perform some of the checks for field features that protoc performs, so that still needs to come in a subsequent branch. But this does bring this repo up to the same level of protoc-compatibility it had before, but this time with protoc v25 (instead of v24). It also does add one add'l check: that the packed field option is not used with editions.

@@ -6,7 +6,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/stretchr/testify v1.8.4
golang.org/x/sync v0.3.0
google.golang.org/protobuf v1.31.1-0.20230727123859-6d0a5dbd9500
google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1
Copy link
Member Author

Choose a reason for hiding this comment

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

This latest version of protobuf-go pulls in the latest descriptor.proto changes.

@@ -2041,44 +2038,6 @@ func TestLinkerValidation(t *testing.T) {
},
expectedErr: `test.proto:1:11: edition value "2022" not recognized; should be one of ["2023"]`,
},
"failure_use_of_features_without_editions": {
Copy link
Member Author

Choose a reason for hiding this comment

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

This moved into the parser's descriptor validation, so is done in parser tests instead of in linker tests.

},
expectedErr: `test.proto:3:25: field Foo.foo: option 'features' may only be used with editions but file uses "proto3" syntax`,
},
"failure_direct_use_of_raw_features": {
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no longer a raw_features field in google.protobuf.FeatureSet.

md.Options.UninterpretedOption = internal.RemoveOption(md.Options.UninterpretedOption, index)
valid := false
if opt.IdentifierValue != nil {
if opt.GetIdentifierValue() == "true" {
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, this would allow an explicit map_entry option as long as the value was false. But the latest version of protoc doesn't allow this at all, so we mirror its behavior.

@@ -272,9 +272,8 @@ func TestBasicValidation(t *testing.T) {
contents: `message Foo { reserved 1, 2 to 10, 11 to 20; extensions 21 to 22; }`,
},
"failure_message_reserved_start_after_end": {
contents: `message Foo { reserved 10 to 1; }`,
expectedErr: `test.proto:1:24: range, 10 to 1, is invalid: start must be <= end`,
expectedDiffWithProtoc: true, // bug in protoc: https://github.com/protocolbuffers/protobuf/issues/13442
Copy link
Member Author

Choose a reason for hiding this comment

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

Numerous bugs have been fixed in protoc v25. Yay! 💥

return err
}
if featuresDefaults != nil && nmd.GetOptions().GetMapEntry() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was moved to a post-process below. It was a little simpler that way.

@jhump jhump changed the title Update to match behavior of latest protoc (v25.0) Update to match Editions behavior of latest protoc (v25.0) Oct 27, 2023
@jhump jhump requested a review from Alfus October 27, 2023 18:22
@jhump jhump enabled auto-merge (squash) October 27, 2023 19:01
@jhump jhump merged commit 24bce88 into main Oct 27, 2023
7 checks passed
@jhump jhump deleted the jh/update-to-latest-descriptor-proto branch October 27, 2023 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants