-
Notifications
You must be signed in to change notification settings - Fork 112
[pointer] Store validity in the referent type #2334
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2334 +/- ##
==========================================
+ Coverage 89.32% 89.34% +0.02%
==========================================
Files 16 16
Lines 6023 6037 +14
==========================================
+ Hits 5380 5394 +14
Misses 643 643 ☔ View full report in Codecov by Sentry. |
5d99011
to
1b77003
Compare
@@ -1050,7 +1064,7 @@ mod _casts { | |||
// `UnsafeCell<T>` has the same in-memory representation as its | |||
// inner type `T`. A consequence of this guarantee is that it is | |||
// possible to convert between `T` and `UnsafeCell<T>`. | |||
let ptr = unsafe { ptr.assume_validity::<I::Validity>() }; | |||
let ptr = unsafe { ptr.assume_validity::<V>() }; |
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.
Maybe introduce a Validity::WithValidity<V>
GAT that permits going from V<Inner = UnsafeCell<T>>
to W<Inner = UnsafeCell<T>>
?
07239f8
to
0f07add
Compare
Previously, validity was stored as part of the `I: Invariants` type parameter on a `Ptr<T, I>`. In this commit, we migrate the validity to being stored as the `V` in `Ptr<V, I>`; `I` now only stores aliasing and alignment. Bit validity is subtle, in that the pair of referent type and validity invariant define a set of bit patterns which may appear in the `Ptr`'s referent. By encoding the validity in the referent type instead of in the `I` parameter, we ensure that the validity of the referent is captured entirely by a single type parameter rather than by a pair of two separate type parameters. This makes future changes (e.g. #1359) easier to model. This idea was originally proposed in #1866 (comment) Makes progress on #1866 gherrit-pr-id: Ia73ca4e5dfb3b20f71ed72ffda24dd7450c427ba
0f07add
to
7655869
Compare
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.
Made some of the requested changes: https://github.com/google/zerocopy/compare/07239f8524aef427655ada542b0be8a5f5f54ec3..7655869
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.
Reviewed in-person; comments addressed.
Previously, validity was stored as part of the
I: Invariants
typeparameter on a
Ptr<T, I>
. In this commit, we migrate the validity tobeing stored as the
V
inPtr<V, I>
;I
now only stores aliasing andalignment.
Bit validity is subtle, in that the pair of referent type and validity
invariant define a set of bit patterns which may appear in the
Ptr
'sreferent. By encoding the validity in the referent type instead of in
the
I
parameter, we ensure that the validity of the referent iscaptured entirely by a single type parameter rather than by a pair of
two separate type parameters. This makes future changes (e.g. #1359)
easier to model.
This idea was originally proposed in #1866 (comment)
Makes progress on #1866
This PR is on branch transmute-from.