Skip to content

Introduce 'Code Generation' documentation#3078

Merged
jswrenn merged 1 commit intomainfrom
G490f3d0c05cc9f6db9c019ac73da4215f51dc627
Mar 4, 2026
Merged

Introduce 'Code Generation' documentation#3078
jswrenn merged 1 commit intomainfrom
G490f3d0c05cc9f6db9c019ac73da4215f51dc627

Conversation

@jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented Mar 4, 2026

Threads each of the codegen benchmarks introduced in #3042 into the
rustdoc of the corresponding item.


Latest Update: v8 — Compare vs v7

📚 Full Patch History

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

Version v7 v6 v5 v4 v3 v2 v1 Base
v8 vs v7 vs v6 vs v5 vs v4 vs v3 vs v2 vs v1 vs Base
v7 vs v6 vs v5 vs v4 vs v3 vs v2 vs v1 vs 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/G490f3d0c05cc9f6db9c019ac73da4215f51dc627 && git checkout -b pr-G490f3d0c05cc9f6db9c019ac73da4215f51dc627 FETCH_HEAD

Checkout

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

Cherry Pick

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

Pull

git pull origin refs/heads/G490f3d0c05cc9f6db9c019ac73da4215f51dc627

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 project's documentation by introducing a dedicated section for "Code Generation." It provides in-depth explanations and interactive examples of how zerocopy traits and macros behave at a low level, including their runtime costs and specific requirements. This is achieved through new rustdoc features, custom CSS for tabbed content, and specialized macros that embed benchmark code and machine code analysis directly into the generated documentation.

Highlights

  • Code Generation Documentation: Introduced comprehensive documentation for code generation, detailing the runtime costs and requirements of zerocopy traits and macros.
  • Custom Rustdoc Styling: Implemented custom CSS styling for rustdoc to display interactive tabbed content within the new code generation documentation.
  • New Documentation Macros: Developed new codegen_header! and codegen_tabs! macros to embed benchmark code, format definitions, and machine code analysis directly into rustdoc comments.
  • Documentation Integration: Integrated code generation documentation into the TryFromBytes, FromBytes, transmute_ref!, and try_transmute_ref! documentation comments.
  • Benchmark File Refactoring: Refactored benchmark files by removing boilerplate and standardizing zerocopy trait method calls to fully qualified paths for cleaner inclusion in documentation.

🧠 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
  • Cargo.toml
    • Updated rustdoc-args to include rustdoc/style.css for custom documentation styling.
  • benches/formats/coco.rs
    • Removed license header and module-level documentation comments.
  • benches/ref_from_bytes.rs
    • Removed license header and use statement.
    • Updated FromBytes::ref_from_bytes to zerocopy::FromBytes::ref_from_bytes.
  • benches/ref_from_bytes_with_elems.rs
    • Removed license header and use statement.
    • Updated FromBytes::ref_from_bytes_with_elems to zerocopy::FromBytes::ref_from_bytes_with_elems.
  • benches/ref_from_prefix.rs
    • Removed license header and use statement.
    • Updated FromBytes::ref_from_prefix to zerocopy::FromBytes::ref_from_prefix.
  • benches/ref_from_prefix_with_elems.rs
    • Removed license header and use statement.
    • Updated FromBytes::ref_from_prefix_with_elems to zerocopy::FromBytes::ref_from_prefix_with_elems.
  • benches/ref_from_suffix.rs
    • Removed license header and use statement.
    • Updated FromBytes::ref_from_suffix to zerocopy::FromBytes::ref_from_suffix.
  • benches/ref_from_suffix_with_elems.rs
    • Removed license header and use statement.
    • Updated FromBytes::ref_from_suffix_with_elems to zerocopy::FromBytes::ref_from_suffix_with_elems.
  • benches/transmute_ref.rs
    • Removed license header and use statement.
    • Updated transmute_ref! to zerocopy::transmute_ref!.
  • benches/try_ref_from_bytes.rs
    • Removed license header and use statement.
    • Updated TryFromBytes::try_ref_from_bytes to zerocopy::TryFromBytes::try_ref_from_bytes.
  • benches/try_ref_from_bytes_with_elems.rs
    • Removed license header and use statement.
    • Updated TryFromBytes::try_ref_from_bytes_with_elems to zerocopy::TryFromBytes::try_ref_from_bytes_with_elems.
  • benches/try_ref_from_prefix.rs
    • Removed license header and use statement.
    • Updated TryFromBytes::try_ref_from_prefix to zerocopy::TryFromBytes::try_ref_from_prefix.
  • benches/try_ref_from_prefix_with_elems.rs
    • Removed license header and use statement.
    • Updated TryFromBytes::try_ref_from_prefix_with_elems to zerocopy::TryFromBytes::try_ref_from_prefix_with_elems.
  • benches/try_ref_from_suffix.rs
    • Removed license header and use statement.
    • Updated TryFromBytes::try_ref_from_suffix to zerocopy::TryFromBytes::try_ref_from_suffix.
  • benches/try_ref_from_suffix_with_elems.rs
    • Removed license header and use statement.
    • Updated TryFromBytes::try_ref_from_suffix_with_elems to zerocopy::TryFromBytes::try_ref_from_suffix_with_elems.
  • benches/try_transmute_ref.rs
    • Removed license header and use statement.
    • Updated try_transmute_ref! to zerocopy::try_transmute_ref!.
  • rustdoc/style.css
    • Added new CSS rules for styling codegen-tabs in rustdoc.
  • src/codegen.md
    • Added new markdown content for the "Codegen" documentation page, including embedded CSS for tabbed sections.
  • src/lib.rs
    • Added codegen_header! and codegen_tabs! macros to documentation comments for various TryFromBytes and FromBytes methods.
  • src/macros.rs
    • Added codegen_tabs! macro calls to the documentation comments for transmute_ref! and try_transmute_ref!.
  • src/util/macros.rs
    • Added definitions for codegen_header! and codegen_tabs! documentation macros.
  • tools/rustdoc.sh
    • Added a new shell script to generate rustdoc with unstable options, hidden/private items, macro expansion, and custom CSS.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/docs.yml
Activity
  • The pull request was automatically generated by GHerrit.
  • The pull request is part of a stacked PR series, as indicated by the GHerrit metadata.
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 introduces a 'Code Generation' documentation section for various functions, which is a fantastic addition for understanding performance implications. The use of a tabbed interface to show format definitions, benchmark code, and machine code analysis is well-executed. However, I've found several copy-paste errors in the new documentation blocks within src/lib.rs that should be corrected. Additionally, there's a new file, src/codegen.md, that appears to be an unused development artifact and could likely be removed.

@jswrenn jswrenn force-pushed the G490f3d0c05cc9f6db9c019ac73da4215f51dc627 branch 2 times, most recently from 99ef78c to 0a155a5 Compare March 4, 2026 19:42
@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3078   +/-   ##
=======================================
  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
Copy link
Collaborator Author

jswrenn commented Mar 4, 2026

The generated documentation looks like this:

Screenshot 2026-03-04 at 2 58 56 PM

@jswrenn jswrenn force-pushed the G490f3d0c05cc9f6db9c019ac73da4215f51dc627 branch 2 times, most recently from 0398261 to 8b4c98b Compare March 4, 2026 20:28
@joshlf
Copy link
Member

joshlf commented Mar 4, 2026

/gemini review

In particular, please review the prose in doc comments to ensure it accurately matches the benchmark being described, e.g.:

    /// - the source must begin an even memory address
    /// - the source has a minimum length of 4 bytes
    /// - the source has a total length divisible by 2
    /// - the source begins with the bytes `0xC0C0`

You'll need to cross-reference each of these against the file which is loaded, e.g.:

    #[doc = codegen_tabs!(format = "coco", bench = "try_ref_from_bytes")]

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 introduces a "Code Generation" documentation section for various methods and macros, embedding benchmark code and analysis directly into the rustdoc output. This is a great improvement for developers looking to understand the performance characteristics of zerocopy. The changes are mostly related to documentation generation, including new macros, CSS for styling, and updates to benchmark files. I've found one issue related to cross-browser compatibility in the new CSS file.

@jswrenn jswrenn force-pushed the G490f3d0c05cc9f6db9c019ac73da4215f51dc627 branch from 8b4c98b to bd8bd76 Compare March 4, 2026 23:04
@jswrenn jswrenn enabled auto-merge March 4, 2026 23:06
@jswrenn jswrenn requested a review from joshlf March 4, 2026 23:06
Threads each of the codegen benchmarks introduced in #3042 into the
rustdoc of the corresponding item.

gherrit-pr-id: G490f3d0c05cc9f6db9c019ac73da4215f51dc627
@jswrenn jswrenn force-pushed the G490f3d0c05cc9f6db9c019ac73da4215f51dc627 branch from bd8bd76 to af96890 Compare March 4, 2026 23:08
@jswrenn jswrenn added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit 128f030 Mar 4, 2026
105 checks passed
@jswrenn jswrenn deleted the G490f3d0c05cc9f6db9c019ac73da4215f51dc627 branch March 4, 2026 23:48
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