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

use ALIGN for Push::alignment in struct types #8398

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bkietz
Copy link

@bkietz bkietz commented Sep 20, 2024

This PR adds an override of the default Push::alignment(), which is incorrectly 1 for structs because they are byte arrays and this doesn't accurately reflect the type's alignment requirements.

fixes #8150

Copy link

google-cla bot commented Sep 20, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@bkietz
Copy link
Author

bkietz commented Sep 20, 2024

@evgenyx00 @tustvold

Copy link

@alamb alamb left a comment

Choose a reason for hiding this comment

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

I wonder if we should add a test to this PR to make sure there are no regressions

@bkietz
Copy link
Author

bkietz commented Sep 25, 2024

I was not sure where to add such a test, but I'd be happy to. I opened apache/arrow-rs#6426 since that seemed like a good way to check for regressions (I didn't see any). @aardappel @CasperN any recommendations?

@aardappel
Copy link
Collaborator

@bkietz yes we generally should have tests :) Not too familiar with the Rust tests though, have a look.

@bkietz bkietz force-pushed the push-alignment-for-structs branch 2 times, most recently from 0b25b84 to 7d7ba5e Compare October 4, 2024 14:39
@bkietz bkietz requested a review from alamb October 4, 2024 14:39
@bkietz
Copy link
Author

bkietz commented Oct 4, 2024

I've regenerated and added a test.

  • struct_vec3_is_written_with_correct_alignment_in_table did not catch this bug before; adding a struct to a Table also goes through the Push trait. I could extend it (for example using a loop over multiple preceding strings to ensure at least one iteration will require padding for alignment)
  • The pull request template suggests that building should also regenerate. However, AFAICT cmake will only regenerate for C++. Perhaps cmake should instead invoke generate_code.py?
  • Could a reviewer please approve the CI workflows so we can see if I've missed anything?

Copy link

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @bkietz

I am not familiar with this codebase, but I did verify that the test you added fails without the code in this PR

To test I did:

cd flatbuffers/tests/rust_usage_test
cargo test --test integration_test

The test fails like this without the PR

---- flatbuffers_tests::push_impls::push_u8_generated_struct_alignment stdout ----
thread 'flatbuffers_tests::push_impls::push_u8_generated_struct_alignment' panicked at tests/integration_test.rs:2360:9:
assertion `left == right` failed
  left: [10, 0, 20, 0, 0, 1]
 right: [10, 0, 20, 0, 1]

Seem like an improvement to me (the 1u8 is now aligned at a byte boundary rather than a u16 boundary)

@bkietz
Copy link
Author

bkietz commented Oct 10, 2024

@dbaileychess could you review and/or approve the CI workflows?

@bkietz
Copy link
Author

bkietz commented Oct 11, 2024

@aardappel whom can we ask to review this?

@aardappel
Copy link
Collaborator

I'd say either @CasperN or @dbaileychess

@bkietz
Copy link
Author

bkietz commented Oct 13, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ codegen Involving generating code from schema rust
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rust Push::alignment Incorrect for Structs
5 participants