Skip to content

[codegen] Make codegen tests even more stressful.#3083

Merged
jswrenn merged 1 commit intomainfrom
G04affc58395810ba04b941f14dfdc20563fa850b
Mar 7, 2026
Merged

[codegen] Make codegen tests even more stressful.#3083
jswrenn merged 1 commit intomainfrom
G04affc58395810ba04b941f14dfdc20563fa850b

Conversation

@jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented Mar 5, 2026

For TryFromBytes and FromBytes tests:

  • Alignment is now 4.
  • Minimum size is now 12.
  • Trailing padding may be dynamically present.

For transmute_ref! and try_transmute_ref!:

  • Metadata fixup required.

Latest Update: v6 — Compare vs v5

📚 Full Patch History

Links show the diff between the row version and the column version.

Version v5 v4 v3 v2 v1 Base
v6 vs v5 vs v4 vs v3 vs v2 vs v1 vs Base
v5 vs v4 vs v3 vs v2 vs v1 vs Base
v4 vs v3 vs v2 vs v1 vs Base
v3 vs v2 vs v1 vs Base
v2 vs v1 vs Base
v1 vs Base
⬇️ Download this PR

Branch

git fetch origin refs/heads/G04affc58395810ba04b941f14dfdc20563fa850b && git checkout -b pr-G04affc58395810ba04b941f14dfdc20563fa850b FETCH_HEAD

Checkout

git fetch origin refs/heads/G04affc58395810ba04b941f14dfdc20563fa850b && git checkout FETCH_HEAD

Cherry Pick

git fetch origin refs/heads/G04affc58395810ba04b941f14dfdc20563fa850b && git cherry-pick FETCH_HEAD

Pull

git pull origin refs/heads/G04affc58395810ba04b941f14dfdc20563fa850b

Stacked PRs enabled by GHerrit.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness of zerocopy's code generation tests by introducing more challenging scenarios for TryFromBytes, FromBytes, and transmute_ref! macros. The changes aim to simulate "worst-case" conditions, ensuring that the library's traits and macros correctly handle complex memory layouts, alignment requirements, and dynamic sizing, including necessary runtime pointer metadata adjustments. This leads to more comprehensive validation of the generated code's correctness and efficiency.

Highlights

  • Enhanced Codegen Tests for TryFromBytes and FromBytes: The codegen tests for TryFromBytes and FromBytes traits have been made more stringent. The Packet struct used in these benchmarks now requires an alignment of 4, a minimum size of 12 bytes, and supports dynamically present trailing padding. This aims to simulate more 'stressful' worst-case scenarios for the zerocopy library.
  • Metadata Fixup for transmute_ref! and try_transmute_ref!: The benchmarks for transmute_ref! and try_transmute_ref! macros now specifically test scenarios where pointer metadata fixup is required at runtime. This is achieved by using a source type with a larger fixed header size than the destination type, ensuring the macros correctly adjust metadata.
  • Updated Documentation: Documentation for TryFromBytes, FromBytes, transmute_ref!, and try_transmute_ref! has been updated to clearly describe these new, more complex test conditions and the implications for generated code, including runtime checks and metadata adjustments.
  • New Benchmark Format File: A new file, benches/formats/coco_no_padding.rs, was introduced. This file defines a Packet struct with the original, less stringent layout, specifically for use in the transmute_ref benchmarks to facilitate the metadata fixup testing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • benches/formats/coco.rs
    • Updated Packet struct alignment from 2 to 4
    • Added a milk: u8 field to Packet
    • Changed temperature field type from u8 to [u8; 5]
    • Increased marshmallows array size from [u8; 2] to [u8; 3]
  • benches/formats/coco_no_padding.rs
    • Added a new file defining C0C0 enum and Packet struct with original alignment and field types for transmute_ref benchmarks
  • benches/ref_from_bytes.x86-64
    • Modified assembly code to implement new alignment and size checks for ref_from_bytes benchmark
  • benches/ref_from_bytes.x86-64.mca
    • Updated performance metrics to reflect changes in the ref_from_bytes benchmark
  • benches/ref_from_bytes_with_elems.x86-64
    • Modified assembly code to implement new alignment and size checks for ref_from_bytes_with_elems benchmark
  • benches/ref_from_bytes_with_elems.x86-64.mca
    • Updated performance metrics to reflect changes in the ref_from_bytes_with_elems benchmark
  • benches/ref_from_prefix.x86-64
    • Modified assembly code to implement new alignment and size checks for ref_from_prefix benchmark
  • benches/ref_from_prefix.x86-64.mca
    • Updated performance metrics to reflect changes in the ref_from_prefix benchmark
  • benches/ref_from_prefix_with_elems.x86-64
    • Modified assembly code to implement new alignment and size checks for ref_from_prefix_with_elems benchmark
  • benches/ref_from_prefix_with_elems.x86-64.mca
    • Updated performance metrics to reflect changes in the ref_from_prefix_with_elems benchmark
  • benches/ref_from_suffix.x86-64
    • Modified assembly code to implement new alignment and size checks for ref_from_suffix benchmark
  • benches/ref_from_suffix.x86-64.mca
    • Updated performance metrics to reflect changes in the ref_from_suffix benchmark
  • benches/ref_from_suffix_with_elems.x86-64
    • Modified assembly code to implement new alignment and size checks for ref_from_suffix_with_elems benchmark
  • benches/ref_from_suffix_with_elems.x86-64.mca
    • Updated performance metrics to reflect changes in the ref_from_suffix_with_elems benchmark
  • benches/transmute_ref.rs
    • Updated format module path to coco_no_padding.rs
    • Increased MinimalViableSource header size from [u8; 4] to [u8; 6]
  • benches/transmute_ref.x86-64
    • Modified assembly code to adjust pointer metadata for transmute_ref benchmark
  • benches/transmute_ref.x86-64.mca
    • Updated performance metrics to reflect changes in the transmute_ref benchmark
  • benches/try_ref_from_bytes.x86-64
    • Modified assembly code to implement new alignment and size checks for try_ref_from_bytes benchmark
  • benches/try_ref_from_bytes.x86-64.mca
    • Updated performance metrics to reflect changes in the try_ref_from_bytes benchmark
  • benches/try_ref_from_bytes_with_elems.x86-64
    • Modified assembly code to implement new alignment and size checks for try_ref_from_bytes_with_elems benchmark
  • benches/try_ref_from_bytes_with_elems.x86-64.mca
    • Updated performance metrics to reflect changes in the try_ref_from_bytes_with_elems benchmark
  • benches/try_ref_from_prefix.x86-64
    • Modified assembly code to implement new alignment and size checks for try_ref_from_prefix benchmark
  • benches/try_ref_from_prefix.x86-64.mca
    • Updated performance metrics to reflect changes in the try_ref_from_prefix benchmark
  • benches/try_ref_from_prefix_with_elems.x86-64
    • Modified assembly code to implement new alignment and size checks for try_ref_from_prefix_with_elems benchmark
  • benches/try_ref_from_prefix_with_elems.x86-64.mca
    • Updated performance metrics to reflect changes in the try_ref_from_prefix_with_elems benchmark
  • benches/try_ref_from_suffix.x86-64
    • Modified assembly code to implement new alignment and size checks for try_ref_from_suffix benchmark
  • benches/try_ref_from_suffix.x86-64.mca
    • Updated performance metrics to reflect changes in the try_ref_from_suffix benchmark
  • benches/try_ref_from_suffix_with_elems.x86-64
    • Modified assembly code to implement new alignment and size checks for try_ref_from_suffix_with_elems benchmark
  • benches/try_ref_from_suffix_with_elems.x86-64.mca
    • Updated performance metrics to reflect changes in the try_ref_from_suffix_with_elems benchmark
  • src/lib.rs
    • Updated documentation for TryFromBytes and FromBytes traits to reflect more stringent test conditions, including alignment, minimum length, and total length divisibility for worst-case benchmarks
  • src/macros.rs
    • Updated documentation for transmute_ref! and try_transmute_ref! to clarify runtime pointer metadata adjustment due to differing fixed header sizes
Activity
  • No human activity has been recorded on this pull request since its creation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request strengthens the codegen tests by introducing more complex data structures with stricter alignment and size requirements. The changes are well-aligned with the goal of making the tests more stressful. The updates to generated assembly, performance benchmarks, and documentation are all consistent with these changes. I have a couple of minor suggestions to improve the grammar in the updated documentation for better clarity.

@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.87%. Comparing base (daa1971) to head (5eafa06).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3083   +/-   ##
=======================================
  Coverage   91.87%   91.87%           
=======================================
  Files          20       20           
  Lines        6057     6057           
=======================================
  Hits         5565     5565           
  Misses        492      492           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jswrenn jswrenn force-pushed the Gff7f5c476000b38dbce1a040586076c9ff44a8d4 branch from bf3201c to 5843a6a Compare March 6, 2026 23:53
@jswrenn jswrenn force-pushed the G04affc58395810ba04b941f14dfdc20563fa850b branch from 11a76fa to 57741d2 Compare March 6, 2026 23:53
Base automatically changed from Gff7f5c476000b38dbce1a040586076c9ff44a8d4 to main March 7, 2026 00:28
For `TryFromBytes` and `FromBytes` tests:
- Alignment is now 4.
- Minimum size is now 12.
- Trailing padding may be dynamically present.

For `transmute_ref!` and `try_transmute_ref!`:
- Metadata fixup required.

gherrit-pr-id: G04affc58395810ba04b941f14dfdc20563fa850b
@jswrenn jswrenn force-pushed the G04affc58395810ba04b941f14dfdc20563fa850b branch from 57741d2 to 5eafa06 Compare March 7, 2026 00:35
@jswrenn jswrenn enabled auto-merge March 7, 2026 00:36
@jswrenn jswrenn added this pull request to the merge queue Mar 7, 2026
Merged via the queue into main with commit 098b966 Mar 7, 2026
105 checks passed
@jswrenn jswrenn deleted the G04affc58395810ba04b941f14dfdc20563fa850b branch March 7, 2026 01:10
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.

3 participants