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

style(prost-build): Consolidate field data into struct #1017

Merged
merged 3 commits into from
Apr 29, 2024

Conversation

mzabaluev
Copy link
Contributor

When massaging field data in CodeGenerator::append_message, move it into lists of Field and OneofField structs so that later generation passes can operate on the data with less code duplication.

Subsidiary append_* methods are changed to take references to these structs rather than moved data, as generation of lexical tokens does not actually consume any owned data, and we will need more passes over the same field lists for the upcoming builder codegen in #901.

Copy link
Collaborator

@caspermeijn caspermeijn left a comment

Choose a reason for hiding this comment

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

This is a good idea to make these explicit structs. But I think we could make more use of it.

I don't expect you to change the whole file, but I would like to see a bit more integration in the code you already touched.

prost-build/src/code_generator.rs Outdated Show resolved Hide resolved
prost-build/src/code_generator.rs Show resolved Hide resolved
prost-build/src/code_generator.rs Outdated Show resolved Hide resolved
prost-build/src/code_generator.rs Outdated Show resolved Hide resolved
prost-build/src/code_generator.rs Outdated Show resolved Hide resolved
prost-build/src/code_generator.rs Outdated Show resolved Hide resolved
}
});
// Optional fields create a synthetic oneof that we want to skip
let oneof_fields: Vec<OneofField> = message
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a good for readability. The logic is not spread anymore. I do like a comment that explains the difference between oneof_map and oneof_fields.

prost-build/src/code_generator.rs Outdated Show resolved Hide resolved
prost-build/src/code_generator.rs Outdated Show resolved Hide resolved
When massaging field data in CodeGenerator::append_message,
move it into lists of Field and OneofField structs so that later
generation passes can operate on the data with less code duplication.

Subsidiary append_* methods are changed to take references to these
structs rather than moved data, as generation of lexical tokens
does not actually consume any owned data, and we will need more
passes over the same field lists for the upcoming builder code.
Make rust_field into a method computing the name on the fly.
In OneofField, make the vector of fields to have Field members.
Don't play reference renaming tricks with field.descriptor.
@caspermeijn caspermeijn changed the title prost-build: consolidate message field data to improve reuse in code generator style(prost-build): Consolidate field data into struct Apr 29, 2024
@caspermeijn caspermeijn added this pull request to the merge queue Apr 29, 2024
@caspermeijn
Copy link
Collaborator

Thank you for your contribution. I am grateful for your patience during code review.

Merged via the queue into tokio-rs:master with commit 680a2e1 Apr 29, 2024
14 checks passed
caspermeijn added a commit to caspermeijn/prost that referenced this pull request May 5, 2024
_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)
github-merge-queue bot pushed a commit that referenced this pull request May 8, 2024
_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)
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