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

Fix CodeGen V2 for zero-length array #453

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

ttreyer
Copy link
Contributor

@ttreyer ttreyer commented Jan 10, 2024

Summary

Fix issue #295

  1. Replace the recursive validate_size template with a non-recursive one, making CodeGen compile
  2. Process zero-length array as containers, so no object size is left unread in the data buffer
  3. Enable the zero-length array test

Is it ok to process zero-length array as container?
I had to modify the test's results to all 0 sizes. Is this the behavior expected? Or should it report an exclusive size of 1 for the Foo struct?

Test plan

The example provided in #295 now passes successfully and has been enabled in the integration tests.

$ build/test/integration/integration_test_runner --gtest_filter='OidIntegration.arrays_member_int0' --verbose --preserve --enable-feature type-graph

@ttreyer ttreyer added bug Something isn't working types Handling of a specific type codegen Code Generation Framework labels Jan 10, 2024
@ttreyer ttreyer requested a review from JakeHillion January 10, 2024 16:57
The recursive template implemented for `validate_size` does not support
incomplete types, like zero-length array.

By splitting the `validate_size` struct in two parts:
1. `validate_size_eq` that does the actual size check, and
2. `validate_size` that preserves the previous interface and inherit
   from `validate_size_eq`,
we get the same interface and feature than previously, but without the
recursive template that doesn't support incomplete types.
@ttreyer ttreyer force-pushed the ttreyer/fix-zero-array branch from 62a3778 to cff773b Compare January 10, 2024 17:07
Copy link
Contributor

@JakeHillion JakeHillion left a comment

Choose a reason for hiding this comment

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

Not sure how much we care about breaking codegen-v1 at this point, but this does seem to. Pretty easy to make it work with both :) if we have consensus that codegen-v1 is dead that I missed then you don't need to worry.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cbeafba) 62.38% compared to head (cff773b) 62.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #453      +/-   ##
==========================================
+ Coverage   62.38%   62.41%   +0.02%     
==========================================
  Files         123      123              
  Lines       12007    12006       -1     
  Branches     1956     1955       -1     
==========================================
+ Hits         7491     7493       +2     
+ Misses       3571     3570       -1     
+ Partials      945      943       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ttreyer ttreyer force-pushed the ttreyer/fix-zero-array branch from cff773b to ec40543 Compare January 10, 2024 17:35
TreeBuilder did not consider a zero-length array like a container and
never read the array's sizeof stored in the data buffer, leading to a
mismatch between bytes written vs read out of the buffer.

Now, `TreeBuilder::isContainer` does consider zero-length array like
a container and properly consume all the object sizes in the buffer.
@ttreyer ttreyer force-pushed the ttreyer/fix-zero-array branch from ec40543 to 6a26f9a Compare January 10, 2024 17:42
@ttreyer ttreyer merged commit cf8fe64 into facebookexperimental:main Jan 10, 2024
4 checks passed
@ttreyer ttreyer deleted the ttreyer/fix-zero-array branch January 10, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cla signed codegen Code Generation Framework types Handling of a specific type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants