-
Notifications
You must be signed in to change notification settings - Fork 138
[pointer] Add generic projection/cast framework #2860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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 foundational generic framework for pointer projection and casting within the Highlights
🧠 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 AssistThe 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
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 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
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2860 +/- ##
==========================================
- Coverage 91.94% 91.89% -0.06%
==========================================
Files 20 20
Lines 5824 5773 -51
==========================================
- Hits 5355 5305 -50
+ Misses 469 468 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 significant and well-designed refactoring of the pointer casting and projection framework by adding the Project and Cast traits. This unification simplifies the codebase and makes the casting logic more extensible and type-driven. The changes across the files are consistent with this new design.
My review focuses on the correctness and safety of these new abstractions. I've found a few places where // SAFETY: TODO comments indicate missing safety justifications for unsafe blocks. It's important to fill these in to ensure the soundness of the library. Most notably, I've identified one InvariantsEq implementation in zerocopy-derive/src/enum.rs that appears to be incorrect and could lead to unsoundness. Please address these points to finalize this excellent refactoring.
01addfc to
f291309
Compare
|
/gemini review |
There was a problem hiding this 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 generic framework for pointer projections and casts using the new Project and Cast traits. This is a significant and valuable refactoring that unifies various casting and projection mechanisms throughout the codebase, making them more composable and robust. The changes are extensive, touching many core parts of the pointer manipulation logic.
While the overall direction is excellent, I've found several critical issues related to TODOs in SAFETY comments, particularly concerning potential soundness holes with InvariantsEq implementations for enums and a missing safety justification for a new public project method. These must be addressed to ensure the soundness guarantees of zerocopy are upheld. I've also pointed out a few other places where TODOs in safety comments should be replaced with proper justifications.
f291309 to
f675ef9
Compare
f675ef9 to
8f36d46
Compare
67064e8 to
1499f20
Compare
| // [1] Per | ||
| // https://doc.rust-lang.org/1.92.0/reference/type-layout.html#reprc-unions, | ||
| // it's not *technically* guaranteed that non-maximally- | ||
| // sized fields are at offset 0, but it's clear that this is | ||
| // the intention of `repr(C)` unions. It says: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For repr(C) unions, this guarantees zero offsets:
Fields might have a non-zero offset (except when the C representation is used); in that case the bits starting at the offset of the fields are read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1499f20 to
021e25d
Compare
3d0b918 to
4e33171
Compare
|
/gemini review |
There was a problem hiding this 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 powerful and generic framework for pointer projections and casts with the Project and Cast traits. This is a significant improvement that unifies various casting mechanisms throughout the codebase, reducing boilerplate and increasing clarity. The use of transitive projections is particularly elegant. The changes are extensive and touch core parts of the library, and the refactoring appears to be very well thought out. I've found a couple of places where safety comments need to be addressed to fully justify the soundness of the new additions.
ba1a532 to
05f8ad1
Compare
Add `unsafe trait Project` and `unsafe trait Cast: Project`. `Cast` is implemented for any address-preserving cast, while `Project` generalizes to conversions which may not preserve the address of the referent (ie, field projections). Use these (mostly `Cast`, but some `Project`) to unify `PtrInner`/`Ptr` casts, field projections, and `SizeEq` casts. Replace a good amount of unsafe derive-generated code with uses of this machinery. Makes progress on #196 Closes #2856 gherrit-pr-id: Gdeb4f5a282b778a82175703218739a93074d0cc4
05f8ad1 to
6414d5d
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is a significant and well-executed refactoring that introduces a generic framework for pointer projections and casts through the new Project and Cast traits. This change successfully unifies various casting mechanisms throughout the codebase, replacing a good amount of unsafe derive-generated code with this new, more robust machinery. The new abstractions are thoughtfully designed and improve the overall structure and safety of pointer manipulations. I have one minor suggestion for code style.
Add
unsafe trait Projectandunsafe trait Cast: Project.Castisimplemented for any address-preserving cast, while
Projectgeneralizesto conversions which may not preserve the address of the referent (ie,
field projections). Use these (mostly
Cast, but someProject) tounify
PtrInner/Ptrcasts, field projections, andSizeEqcasts.Replace a good amount of unsafe derive-generated code with uses of this
machinery.
Makes progress on #196
Closes #2856
Latest Update: v16 — Compare vs v15
📚 Full Patch History
Links show the diff between the row version and the column version.