Skip to content

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Jan 9, 2026

MutationCompatible introduces unnecessary indirection and makes many
type signatures needlessly complex. In this commit, we flatten the trait
hierarchy so that TryTransmuteFromPtr has more impls, and
MutationCompatible is removed entirely.

We also remove the Read trait for a similar reason.


Latest Update: v17 — Compare vs v16

📚 Full Patch History

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

Version v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v8 v7 v6 v5 v4 v3 v2 v1 Base
v7 v6 v5 v4 v3 v2 v1 Base
v6 v5 v4 v3 v2 v1 Base
v5 v4 v3 v2 v1 Base
v4 v3 v2 v1 Base
v3 v2 v1 Base
v2 v1 Base
v1 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 undertakes a significant internal refactoring of the zerocopy crate's trait system. The core objective is to simplify the codebase by eliminating the MutationCompatible and Read traits, which were identified as sources of excessive indirection and complexity. By flattening the TryTransmuteFromPtr trait hierarchy and streamlining type parameters in various pointer manipulation functions and macros, the changes aim to enhance the clarity, maintainability, and overall design of the crate's low-level memory safety mechanisms.

Highlights

  • Trait Removal: The MutationCompatible and Read traits have been entirely removed from the codebase, as they introduced unnecessary indirection and complexity in type signatures.
  • Trait Hierarchy Flattening: The TryTransmuteFromPtr trait hierarchy has been flattened, leading to more direct implementations and simplified type bounds in various functions and methods.
  • Code Simplification: Numerous Ptr methods (e.g., recall_validity, transmute, cast) and associated macros have been simplified by removing redundant type parameters and complex trait bounds, improving readability and maintainability.
  • Updated zerocopy-derive Macros: The zerocopy-derive macros have been updated to align with the removed traits, specifically in cast calls and InvariantsEq implementations, ensuring consistency across the crate.
  • Safety Documentation Updates: New TODO comments have been added to update safety documentation for TryTransmuteFromPtr and to consider unifying Ptr::cast and Ptr::transmute.

🧠 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 G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 847fe34 to 70fb472 Compare January 9, 2026 00:01
@joshlf joshlf changed the title [WIP] Remove MutationCompatible [WIP] Remove MutationCompatible, Read Jan 9, 2026
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 is a significant and welcome refactoring that removes the MutationCompatible and Read traits, simplifying the trait hierarchy and making type signatures less complex. The changes are extensive, touching many parts of the codebase, but they appear to be consistent and correct. The introduction of new TryTransmuteFromPtr impls to replace the old traits is a good approach. I've noticed you've added several TODO comments to track necessary updates to safety documentation, which is great for a work-in-progress PR. I've raised a few review comments to formalize the need to address these TODOs, particularly for the new unsafe implementations, to ensure they are fully justified before this PR is merged.

unsafe { Ptr::from_inner(inner) })
})?;

// TODO: Update this safety comment for `TryTransmuteFromPtr`.
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This TODO is important. The following safety comment is outdated as it refers to the Read trait which has been removed. Please update the safety justification to reflect the new TryTransmuteFromPtr bounds.

// TODO: Maybe use the same reason for both? There shouldn't be any situation in
// which the reasons are different (one is BecauseExclusive and the other is
// BecauseImmutable).
// SAFETY: TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Please fill in the safety comment for this unsafe impl. The justification should explain why this implementation of TryTransmuteFromPtr is sound for Exclusive aliasing, considering the preconditions and postconditions of the trait.

// SAFETY: `Src: Read<A, _>` and `Dst: Read<A, _>`.
unsafe impl<Src: ?Sized, Dst: ?Sized, A: Aliasing, SV: Validity, DV: Validity, R>
MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
// SAFETY: TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Please fill in the safety comment for this unsafe impl. The justification should explain why this implementation of TryTransmuteFromPtr is sound for BecauseInvariantsEq, considering the InvariantsEq and TransmuteFrom bounds.

@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (G27dd847426e3572e87b20bd64642c9fcb0e51ec8@b685399). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/util/macros.rs 0.00% 1 Missing ⚠️
src/wrappers.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@                             Coverage Diff                              @@
##             G27dd847426e3572e87b20bd64642c9fcb0e51ec8    #2878   +/-   ##
============================================================================
  Coverage                                             ?   91.44%           
============================================================================
  Files                                                ?       20           
  Lines                                                ?     5912           
  Branches                                             ?        0           
============================================================================
  Hits                                                 ?     5406           
  Misses                                               ?      506           
  Partials                                             ?        0           

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

@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch from 050ea06 to 2972d07 Compare January 9, 2026 16:57
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 70fb472 to 3c218ea Compare January 9, 2026 16:57
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch 2 times, most recently from f5919bc to 9562030 Compare January 9, 2026 17:22
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 3c218ea to 741e5f8 Compare January 15, 2026 23:32
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch from 9562030 to 625fa9b Compare January 15, 2026 23:32
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 741e5f8 to 91658ad Compare January 16, 2026 00:02
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch 2 times, most recently from 74741ec to a8fdf22 Compare January 16, 2026 00:29
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch 2 times, most recently from 256fa34 to 7a4c315 Compare January 16, 2026 00:35
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch from a8fdf22 to 4314268 Compare January 16, 2026 00:35
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 7a4c315 to 88add0a Compare January 16, 2026 00:41
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch from 4314268 to 10d1c38 Compare January 16, 2026 00:41
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 88add0a to 4a75a90 Compare January 16, 2026 00:54
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch 2 times, most recently from 6cde490 to 152c38f Compare January 16, 2026 01:01
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 4a75a90 to 1f5ac66 Compare January 16, 2026 01:01
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 1f5ac66 to d3c8fb4 Compare January 16, 2026 01:14
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch from 152c38f to 4959305 Compare January 16, 2026 01:14
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from d3c8fb4 to b201ea1 Compare January 16, 2026 19:00
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch from 4959305 to 6f92cae Compare January 16, 2026 19:00
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from b201ea1 to 62478e2 Compare January 16, 2026 20:37
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch from 6f92cae to 3fb9013 Compare January 16, 2026 20:37
`MutationCompatible` introduces unnecessary indirection and makes many
type signatures needlessly complex. In this commit, we flatten the trait
hierarchy so that `TryTransmuteFromPtr` has more impls, and
`MutationCompatible` is removed entirely.

We also remove the `Read` trait for a similar reason.

gherrit-pr-id: G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34
@joshlf joshlf force-pushed the G8a3e5c48698ed092b1175cfb42f6f85fb3fb6a34 branch from 62478e2 to e6bfe16 Compare January 16, 2026 20:57
@joshlf joshlf force-pushed the G27dd847426e3572e87b20bd64642c9fcb0e51ec8 branch from 3fb9013 to b685399 Compare January 16, 2026 20:57
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.

2 participants