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

Auto capitalize enums name in Ruby #10454

Merged
merged 21 commits into from
Sep 28, 2022
Merged

Conversation

tisonkun
Copy link
Contributor

This closes #1965.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Contributor Author

@anandolee could you help with triggering the CI workflows? If there're some failure, I can investigate during wait for reviews.

@tisonkun
Copy link
Contributor Author

It seems all tasks passed. @haberman could you give this patch a review?

Copy link
Contributor

@JasonLunn JasonLunn left a comment

Choose a reason for hiding this comment

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

Thanks for submitting the patch. I've highlighted a couple of concerns, but I think they're straightforward to address.

ruby/ext/google/protobuf_c/message.c Show resolved Hide resolved
ruby/ext/google/protobuf_c/message.c Show resolved Hide resolved
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun requested review from JasonLunn and removed request for haberman September 4, 2022 08:28
@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 4, 2022

@JasonLunn thanks for your reviews. Comments addressed.

@JasonLunn
Copy link
Contributor

Thanks, @tisonkun. Is the new test passing for you locally? It is failing in CI.
The JRuby changes fail with NameError: bad constant name 860 with stack trace:

add_serialized_file at [com/google/protobuf/jruby/RubyDescriptorPool.java:125]
internal_add_file at /[workspace/ruby/lib/google/protobuf/descriptor_dsl.rb:65]
add_file at /[workspace/ruby/lib/google/protobuf/descriptor_dsl.rb:43]

This exception appears in all the tests targets, including gc_test and the conformance_test, not just the unit tests.

In the CRuby interpreters, the failure is limited to the unit tests. The new assertion (assert proto_module::TestEnum::V0 == 4 fails with NameError: uninitialized constant BasicTest::TestEnum::V0 and separately the new call to push (l.push :V0) fails with RangeError: Unknown symbol value for enum field ''..

@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 9, 2022

@JasonLunn how can I run tests locally? I don't find some instructions. Also the test output is missing :(

Let me try out rake test.

@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 9, 2022

OK. I found that I only changed for enummodule calls, but not for the compiler. I will spend some time to find the related code and made the change. But it would help a lot if you can tell when which logic writes:

    add_enum "a.b.proto2.TestEnum" do
      value :Default, 0
      value :A, 1
      value :B, 2
      value :C, 3
      value :v0, 4
    end

@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 9, 2022

For JRuby, it may need more effort. And I may consider we finish the CRuby part first and following up for the JRuby part - I work on this part-time and my use case is CRuby only.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 9, 2022

Addressed. The ruby unit test can be still failed because updates to the compiler seems not be used by the unit test in the same patch. I'm unsure if we should make the compiler changes in first?

Hmm...I hope the CI can build the protoc and use the new one just built :)

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 15, 2022

Well. The last two commits don't help on decode_json (auto capitalize) for JRuby as described above.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 15, 2022

@JasonLunn @deannagarcia I think ignore these cases for JRuby is OK.

  1. If you define an Enum starting with lower case, it's already invalid for Ruby. We auto capitalize for using the enum without changing the proto file while keep pb binary compatible.
  2. Now, if we encode to json, v0 will be V0. And it works well for Ruby self usage but fails if interop between different languages.
  3. A thoroughgoing solution can be: (1) add a mark of the "original name" for codec in text/json format. (2) Use something different from Ruby's constants to represent Enum so that lower letter is allowed.

Anyway, currently, these cases pass wrongly. Even decode_json accepts enum name in lower case, it means nothing for a real Ruby use case.

@tisonkun
Copy link
Contributor Author

@JasonLunn @deannagarcia @mkruskal-google any further comments here?

@JasonLunn
Copy link
Contributor

@tisonkun - can you help me understand two things:

  1. Why is it that only JRuby needs expectation changes to the conformance tests, but CRuby doesn't?
  2. Can you clarify what specific tests you mean when you wrote "these cases pass wrongly"?

@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 27, 2022

@JasonLunn thanks for your follow-ups:

Why is it that only JRuby needs expectation changes to the conformance tests, but CRuby doesn't?

Please read #10454 (comment). The CRuby path is full under control and can be changed, while the JRuby path depends on Java Protobuf implementation.

Can you clarify what specific tests you mean when you wrote "these cases pass wrongly"?

Even decode_json accepts enum name in lower case, it means nothing for a real Ruby use case. I'm debugging deeper in a more expressive output. Or I'd say the tests pass but it doesn't reflect a real-world use case.

@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 27, 2022

Emmm..I may make a mistake here. That we can already use resolve to work with lower letter started enums.

Let me comment on the original issue.

#1965 (comment) Waiting for reviewers' suggestion.

@tisonkun
Copy link
Contributor Author

Wait a minute. I think the original purpose is to define the constant following Ruby's rule. Let me try to narrow the change scope.

Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Contributor Author

Updated. I think this patch is tidy now. All tests passed locally:

rbenv global 3.1.2
bazel test //ruby:conformance_test
rbenv global jruby-9.3.7.0
bazel test //ruby:conformance_test_jruby --define=ruby_platform=java --action_env=PATH --action_env=GEM_PATH --action_env=GEM_HOME --verbose_failures
cd ./ruby/
bundle install
bundle exec rake test
rbenv global 3.1.2
bundle exec rake test

cc @JasonLunn @deannagarcia please take a review :)

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Contributor Author

@JasonLunn @deannagarcia @mkruskal-google All tests passed now and the changeset is minimal. Please take a look :)

@JasonLunn JasonLunn merged commit 2d08621 into protocolbuffers:main Sep 28, 2022
@JasonLunn
Copy link
Contributor

Thanks for you contribution, @tisonkun!

@tisonkun tisonkun deleted the patch-1 branch September 29, 2022 00:14
@tisonkun
Copy link
Contributor Author

tisonkun commented Sep 29, 2022

@JasonLunn thanks for your review! I may be a bit in a hurry but I'd like to know whether/when we can have a release for this patch. I come here because my gem wants it :)

It's not a request, though. And as long as we have a determinate estimate, days or weeks should be OK.

tisonkun added a commit to tisonkun/protobuf that referenced this pull request Oct 4, 2022
deannagarcia added a commit that referenced this pull request Oct 6, 2022
mkruskal-google pushed a commit that referenced this pull request Oct 13, 2022
mkruskal-google added a commit that referenced this pull request Oct 19, 2022
* Force uninstall protobuf in python macos builds

We are seeing failures in brew uninstall protobuf due to no package. Change this to a force install to avoid the error.

* Fix spelling errors (#10717)

* Merge pull request #10200 from tonydnewell/bugfix/protobuf-7474

Fix for grpc.tools #17995 & protobuf #7474 (handle UTF-8 paths in argumentfile)

* Upgrade to kotlin 1.6

* 21.x No longer define no_threadlocal on OpenBSD

* Upgrade kokoro to Xcode 14 (#10732)

* Upgrade kokoro to Xcode 14

* Fix osx errors

* Merge pull request #10770 from protocolbuffers/googleberg-cl-480629524

Mark default instance as immutable first to avoid race during static initialization of default instances.

* Auto capitalize enums name in Ruby (#10454) (#10763)

This closes #1965.

* Edit toolchain to work with absl dep

* Bump upb to latest version after fixes applied (#10783)

* 21.x 202210180838 (#10785)

* Updating version.json and repo version numbers to: 21.8

* Update changelog

Co-authored-by: Protobuf Team Bot <protobuf-team-bot@google.com>

* Update generated protos

Co-authored-by: deannagarcia <69992229+deannagarcia@users.noreply.github.com>
Co-authored-by: Matt Fowles Kulukundis <matt.fowles@gmail.com>
Co-authored-by: Deanna Garcia <deannagarcia@google.com>
Co-authored-by: Brad Smith <brad@comstyle.com>
Co-authored-by: Jerry Berg <107155935+googleberg@users.noreply.github.com>
Co-authored-by: tison <wander4096@gmail.com>
Co-authored-by: Protobuf Team Bot <protobuf-team-bot@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to have lowercase enums in Ruby
7 participants