-
Notifications
You must be signed in to change notification settings - Fork 526
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
prost-build: CodeGenerator::boxed
method
#1019
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At line 626, there is another instance of a boxed
variable. Can that be replaced by the same function?
prost-build/src/code_generator.rs
Outdated
if field.label == Some(Label::Repeated as i32) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this changes the logic from the original: now any boxed
match from the config will be ignored if the field is repeated, while previously it gave true. But I think that was wrong, because it never makes sense to box a Vec
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To think of it, this should be reverted if we want this to be merged for 0.12.x releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quick fix is to split this function into a boxed_field
and boxed_oneof
variants. Make sure to document why two variants are needed.
Maybe you could add a deprecation warning like this:
println!("cargo:warning=Field X is repeated and manually marked as boxed. This is deprecated and support will be removed in a later release");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quick fix is to split this function into a
boxed_field
andboxed_oneof
variants. Make sure to document why two variants are needed.
I don't like this idea. The logic would need to be replicated, even though it's mostly the same for regular fields and oneof members. More so with the deprecation warning, which I have now added as per your suggestion.
Done, with some complication and a questionable behavioral change that I have commented on above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think there are enough tests for boxed fields and oneof fields?
prost-build/src/code_generator.rs
Outdated
if field.label == Some(Label::Repeated as i32) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quick fix is to split this function into a boxed_field
and boxed_oneof
variants. Make sure to document why two variants are needed.
Maybe you could add a deprecation warning like this:
println!("cargo:warning=Field X is repeated and manually marked as boxed. This is deprecated and support will be removed in a later release");
A helper method to capture the logic of deciding whether a field needs to be boxed. This follows the pattern with other methods like `optional`, and will allow reusing the logic in the upcoming builder codegen.
The bit in CodeGenerator::append_oneof was pretty much the same, except the configuration is looked up for the oneof name. Rearrange the logic so that intermediate values are bound when needed. If a repeated fields is configured to be boxed, a deprecation warning will be emitted by the build script.
c64f1f2
to
3fa4069
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the current version. I found one logic error, then this is ready.
Co-authored-by: Casper Meijn <casper@meijn.net>
Thank you for your contribution. I appreciate your patience during the review. |
_PROST!_ is a [Protocol Buffers](https://developers.google.com/protocol-buffers/) implementation for the [Rust Language](https://www.rust-lang.org/). `prost` generates simple, idiomatic Rust code from `proto2` and `proto3` files. This patch update brings new fixes: - fix: include_file should handle proto without package (tokio-rs#1002) - Place Config::format behind the format feature flag - Handle keyword `Self` after stripping enum type prefix (tokio-rs#998) ## Documentation - fix(readme): fix the link and badge for CI (tokio-rs#1049) ## Internal - style(codegen): `Syntax` to a separate file (tokio-rs#1029) - chore(codegen): extract c string escaping to a separate file (tokio-rs#1028) - style(prost-build): `CodeGenerator::boxed` method (tokio-rs#1019) - style(prost-build): Consolidate field data into struct (tokio-rs#1017) - style(prost-build): `BytesType and MapType` into a `collections` module. (tokio-rs#1030) - style(prost-build): Split `Config` and `Module` into a separate module and files (tokio-rs#1020) - style(prost-build): prost_path helper (tokio-rs#1018) - style: Fix toml indent (tokio-rs#1048) - style: Fix clippy warnings and enable clippy in CI (tokio-rs#1008) - build: Use git submodule to download protobuf sources (tokio-rs#1014) - ci: Add TOML validation with `taplo` (tokio-rs#1034) - tests: Create a separate tempdir for each test (tokio-rs#1044) - tests: Remove GoogleMessage3 and GoogleMessage4 benchmarks (tokio-rs#1037) - chore: Update internal crates to Rust edition 2021 (tokio-rs#1039) - chore: Update crate descriptions (tokio-rs#1038) - chore: Fix clippy checks in CI (tokio-rs#1032) - chore: Add Casper Meijn as author (tokio-rs#1025)
_PROST!_ is a [Protocol Buffers](https://developers.google.com/protocol-buffers/) implementation for the [Rust Language](https://www.rust-lang.org/). `prost` generates simple, idiomatic Rust code from `proto2` and `proto3` files. This patch update brings new fixes: - fix: include_file should handle proto without package (#1002) - Place Config::format behind the format feature flag - Handle keyword `Self` after stripping enum type prefix (#998) ## Documentation - fix(readme): fix the link and badge for CI (#1049) ## Internal - style(codegen): `Syntax` to a separate file (#1029) - chore(codegen): extract c string escaping to a separate file (#1028) - style(prost-build): `CodeGenerator::boxed` method (#1019) - style(prost-build): Consolidate field data into struct (#1017) - style(prost-build): `BytesType and MapType` into a `collections` module. (#1030) - style(prost-build): Split `Config` and `Module` into a separate module and files (#1020) - style(prost-build): prost_path helper (#1018) - style: Fix toml indent (#1048) - style: Fix clippy warnings and enable clippy in CI (#1008) - build: Use git submodule to download protobuf sources (#1014) - ci: Add TOML validation with `taplo` (#1034) - tests: Create a separate tempdir for each test (#1044) - tests: Remove GoogleMessage3 and GoogleMessage4 benchmarks (#1037) - chore: Update internal crates to Rust edition 2021 (#1039) - chore: Update crate descriptions (#1038) - chore: Fix clippy checks in CI (#1032) - chore: Add Casper Meijn as author (#1025)
A helper method to capture the logic of deciding whether a field needs to be boxed. This follows the pattern with other methods like
optional
, and will allow reusing the logic in the upcoming builder codegen in #901.