Skip to content

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Dec 30, 2025


Latest Update: v7 — Compare vs v6

📚 Full Patch History

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

Version v6 v5 v4 v3 v2 v1 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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @joshlf, 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 introduces a significant refactoring of the is_bit_valid function within the zerocopy crate. The primary goal is to simplify the function's API by removing an unnecessary generic parameter, enhance the clarity and safety of aliasing semantics through the consistent use of ReadOnly wrappers, and enforce a KnownLayout requirement for all types implementing TryFromBytes. These changes collectively aim to make the bit validity checking mechanism more robust, consistent, and easier to reason about, especially for complex data structures and automatically derived implementations.

Highlights

  • Simplified is_bit_valid Signature: The is_bit_valid function across the crate, including the TryFromBytes trait, its implementations, and associated macros, has been simplified by removing the invariant::Reference generic parameter from its Maybe candidate argument. This streamlines the API and reduces complexity.
  • Refined UnsafeCell Bit Validity Handling: The implementation of is_bit_valid for UnsafeCell<T> now utilizes transmute_unchecked with ReadOnly<T> instead of relying on an exclusive aliasing requirement. This change simplifies the logic for UnsafeCell and potentially broadens its applicability for bit validity checks.
  • TryFromBytes Requires KnownLayout: The TryFromBytes trait now includes a supertrait bound KnownLayout, ensuring that any type implementing TryFromBytes has a well-defined memory layout. This adds a crucial constraint for types that can be checked for bit validity.
  • Consistent ReadOnly Wrapper Usage: Derived and manual implementations of is_bit_valid now consistently employ transmute_unchecked with ReadOnly wrappers to handle the Maybe candidate. This standardizes how bit validity checks are performed across various types and contexts.

🧠 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.

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.

@joshlf joshlf force-pushed the Gb15e30e716a041285c1bf7434ce3163f594526a7 branch from ed42ba1 to f2813bb Compare December 30, 2025 20:06
@joshlf joshlf force-pushed the G60971ace7acef9cd1c74f74f397cb7c48e5e3f73 branch from 8338ac3 to 6fe302c Compare December 30, 2025 20:06
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 refactors the TryFromBytes::is_bit_valid method by removing its generic parameter for aliasing invariants. This simplifies the trait's API. The new implementation approach uses ReadOnly<T> to handle types with interior mutability like UnsafeCell, which seems like a sound refactoring.

My review has identified a few minor issues, mostly related to duplicated #[inline] attributes and some formatting inconsistencies in generated code within macros. These are likely leftovers from the refactoring and should be straightforward to fix.

// is. Thus, this is a sound implementation of
// `UnsafeCell::is_bit_valid`.
T::is_bit_valid(c.get_mut())
#[inline]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The #[inline] attribute is duplicated. Please remove one of them.

// SAFETY: This macro ensures that `$repr` and `Self` have the same
// size and bit validity. Thus, a bit-valid instance of `$repr` is
// also a bit-valid instance of `Self`.
#[inline]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The #[inline] attribute is duplicated. Please remove one of them.

Comment on lines +896 to +909
field_candidate.transmute_unchecked::<
#zerocopy_crate::wrappers::ReadOnly<#field_tys>,
_,
#zerocopy_crate::pointer::cast::CastUnsized
>()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There's an extra space at the beginning of this line, causing inconsistent indentation within the unsafe block. Please remove it for better code formatting.

Suggested change
field_candidate.transmute_unchecked::<
#zerocopy_crate::wrappers::ReadOnly<#field_tys>,
_,
#zerocopy_crate::pointer::cast::CastUnsized
>()
field_candidate.transmute_unchecked::<
#zerocopy_crate::wrappers::ReadOnly<#field_tys>,
_,
#zerocopy_crate::pointer::cast::CastUnsized
>()

@joshlf joshlf force-pushed the G60971ace7acef9cd1c74f74f397cb7c48e5e3f73 branch from 6fe302c to fdabe13 Compare December 30, 2025 20:41
@joshlf joshlf force-pushed the Gb15e30e716a041285c1bf7434ce3163f594526a7 branch 2 times, most recently from 7a5cf19 to f7db04e Compare December 30, 2025 20:44
@joshlf joshlf force-pushed the G60971ace7acef9cd1c74f74f397cb7c48e5e3f73 branch 2 times, most recently from bd5543a to 881fc7d Compare December 30, 2025 23:58
@joshlf joshlf force-pushed the Gb15e30e716a041285c1bf7434ce3163f594526a7 branch from f7db04e to 622633b Compare December 30, 2025 23:58
@joshlf joshlf force-pushed the G60971ace7acef9cd1c74f74f397cb7c48e5e3f73 branch from 881fc7d to ed830e3 Compare December 31, 2025 00:30
@joshlf joshlf force-pushed the Gb15e30e716a041285c1bf7434ce3163f594526a7 branch from 622633b to 6ab7850 Compare December 31, 2025 00:30
gherrit-pr-id: G60971ace7acef9cd1c74f74f397cb7c48e5e3f73
@joshlf joshlf force-pushed the G60971ace7acef9cd1c74f74f397cb7c48e5e3f73 branch from ed830e3 to e5db6e6 Compare January 2, 2026 18:12
@joshlf joshlf force-pushed the Gb15e30e716a041285c1bf7434ce3163f594526a7 branch from 6ab7850 to f08dbdd Compare January 2, 2026 18:12
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.

1 participant