Skip to content

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Jan 22, 2026

With this change, some TryTransmuteFromPtr impls become conditionally
sound – specifically, they are sound for size-preserving casts, but not
for size-shrinking casts. In order to ensure they remain sound, we make
the cast a type parameter on TryTransmuteFromPtr, which allows us to
add the appropriate bounds on these impls. This also prepares us for
more complex transmutes such as "overwriting/tearing" transmutes, as we
can require overwriting/tearing transmutability only for shrikning
casts, but not for size-preserving casts.

Makes progress on #2701, #1940, #1852


Latest Update: v33 — Compare vs v32

📚 Full Patch History

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

Version v32 v31 v30 v29 v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v33 v32 v31 v30 v29 v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v32 v31 v30 v29 v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v31 v30 v29 v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v30 v29 v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v29 v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v28 v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v27 v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v26 v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v25 v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v24 v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v23 v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v22 v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v21 v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v20 v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v19 v18 v17 v16 v15 v14 v13 v12 v11 v10 v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v18 v17 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 refines the transmute machinery by introducing a mechanism to safely permit 'shrinking transmutes' under specific conditions. It modifies the rules for reverse transmutation, primarily by enforcing a CastExact constraint on the destination type's cast mechanism. This ensures that despite a potential 'shrinking' in type, the underlying memory footprint remains identical, thereby maintaining memory safety and expanding the flexibility of transmute operations.

Highlights

  • Permitting Shrinking Transmutes: The core change allows for 'shrinking transmutes' in the transmute machinery, which were previously explicitly banned. This is achieved by introducing a CastExact constraint, ensuring that the source and destination types occupy the same memory size during reverse transmutation.
  • Refined Reverse Transmutation Conditions: The documentation for 'Reverse transmutation' has been updated to reflect the new conditions. It now states that if Dst::CastFrom implements CastExact, and the set of DV-valid referents of dst is a subset of SV-valid referents of src, then the transmutation is permitted.
  • Trait Constraint Addition: A new where clause constraint, Dst::CastFrom: cast::CastExact<Src, Dst>, has been added to the TryTransmuteFromPtr trait, enforcing the size equality requirement for safe shrinking transmutes.
  • SizeEq Trait Adjustment: The SizeEq trait's associated type CastFrom has been relaxed from cast::CastExact to cast::Cast, with the CastExact requirement now being applied directly as a trait bound on TryTransmuteFromPtr.

🧠 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 Gda7c06c9a8e54f5afd6aa5a093406a7b71259fd3 branch from a4ef307 to 591b556 Compare January 22, 2026 20:38
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 8529fd1 to 5b89e27 Compare January 22, 2026 20:38
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 transmutation machinery to enable future support for shrinking transmutes. The core change is relaxing the bound on SizeEq::CastFrom from CastExact to Cast, which allows it to be used for non-size-preserving casts. To maintain safety, existing code that relied on the implicit size-equality guarantee of SizeEq has been updated to explicitly require CastExact. The changes are well-structured, consistent, and the documentation has been updated accordingly. This is a good step towards more flexible transmutation capabilities. I have no further comments.

@joshlf joshlf force-pushed the Gda7c06c9a8e54f5afd6aa5a093406a7b71259fd3 branch from 591b556 to 62ea699 Compare January 22, 2026 20:44
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 5b89e27 to 5635968 Compare January 22, 2026 20:44
@joshlf joshlf force-pushed the Gda7c06c9a8e54f5afd6aa5a093406a7b71259fd3 branch from 62ea699 to 522141c Compare January 22, 2026 20:47
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 5635968 to 46f2fd0 Compare January 22, 2026 20:47
@joshlf joshlf force-pushed the Gda7c06c9a8e54f5afd6aa5a093406a7b71259fd3 branch from 522141c to f0a5b8c Compare January 22, 2026 20:57
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch 2 times, most recently from abc0fe4 to 4f2892d Compare January 22, 2026 21:08
@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.31%. Comparing base (5fcf372) to head (ad5d704).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2912   +/-   ##
=======================================
  Coverage   91.31%   91.31%           
=======================================
  Files          20       20           
  Lines        5897     5897           
=======================================
  Hits         5385     5385           
  Misses        512      512           

☔ 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 Gd9d1c0de851091ffe6161889d21ca2167845a591 branch 3 times, most recently from 77aedb3 to a86e3dd Compare January 22, 2026 21:36
@joshlf joshlf force-pushed the Gda7c06c9a8e54f5afd6aa5a093406a7b71259fd3 branch from f0a5b8c to 4cb7174 Compare January 22, 2026 21:45
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from a86e3dd to 7a46add Compare January 22, 2026 21:45
Base automatically changed from Gda7c06c9a8e54f5afd6aa5a093406a7b71259fd3 to main January 22, 2026 22:32
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 7a46add to 975631d Compare January 23, 2026 20:14
@joshlf joshlf changed the base branch from main to G0973aa3261bb811a53f7d99b8d38df5d6c328d52 January 23, 2026 20:14
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch 2 times, most recently from b1116a3 to 15386c4 Compare January 23, 2026 20:59
@joshlf joshlf changed the base branch from G0973aa3261bb811a53f7d99b8d38df5d6c328d52 to G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 January 23, 2026 20:59
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 15386c4 to 8fa19c4 Compare January 24, 2026 05:07
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 97a08f6 to 857d03c Compare January 24, 2026 05:59
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch 2 times, most recently from 43a76ea to c7676f9 Compare January 24, 2026 17:15
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 857d03c to 3e346c5 Compare January 24, 2026 17:15
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 3e346c5 to b995fc0 Compare January 24, 2026 17:19
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch 2 times, most recently from 5f0ebe0 to fc1ff83 Compare January 24, 2026 17:40
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch 2 times, most recently from c5bf143 to 0744864 Compare January 24, 2026 17:51
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch from fc1ff83 to 918103f Compare January 24, 2026 17:51
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch from 918103f to 565194b Compare January 26, 2026 04:18
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 0744864 to 1371b00 Compare January 26, 2026 04:18
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch from 565194b to fec3c4e Compare January 26, 2026 04:30
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch 2 times, most recently from bdeb4fe to 8e47081 Compare January 26, 2026 04:35
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch from fec3c4e to 0bba9e9 Compare January 26, 2026 04:35
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 8e47081 to e514dc5 Compare January 26, 2026 04:46
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch from 0bba9e9 to 3852df9 Compare January 26, 2026 15:27
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch 2 times, most recently from 05ef45a to 41d3040 Compare January 26, 2026 15:38
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch 2 times, most recently from b3dc714 to bdba77b Compare January 26, 2026 16:26
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch 2 times, most recently from 0516778 to 28a38ee Compare January 26, 2026 17:03
@joshlf joshlf force-pushed the G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 branch from bdba77b to 2bb0c47 Compare January 26, 2026 17:03
Base automatically changed from G1cb98a9a25bc3bcf02d17e63b5389c2d66e9b4d8 to main January 26, 2026 17:58
With this change, some `TryTransmuteFromPtr` impls become conditionally
sound – specifically, they are sound for size-preserving casts, but not
for size-shrinking casts. In order to ensure they remain sound, we make
the cast a type parameter on `TryTransmuteFromPtr`, which allows us to
add the appropriate bounds on these impls. This also prepares us for
more complex transmutes such as "overwriting/tearing" transmutes, as we
can require overwriting/tearing transmutability *only* for shrikning
casts, but not for size-preserving casts.

Makes progress on #2701, #1940, #1852

gherrit-pr-id: Gd9d1c0de851091ffe6161889d21ca2167845a591
@joshlf joshlf force-pushed the Gd9d1c0de851091ffe6161889d21ca2167845a591 branch from 28a38ee to ad5d704 Compare January 26, 2026 18:04
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