[pointer] Store validity in the referent type#2334
Merged
Conversation
Closed
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
joshlf
commented
Feb 14, 2025
| // 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>() }; |
Member
Author
There was a problem hiding this comment.
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
joshlf
commented
Feb 14, 2025
jswrenn
approved these changes
Feb 17, 2025
Collaborator
jswrenn
left a comment
There was a problem hiding this comment.
Reviewed in-person; comments addressed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, validity was stored as part of the
I: Invariantstypeparameter on a
Ptr<T, I>. In this commit, we migrate the validity tobeing stored as the
VinPtr<V, I>;Inow 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
Iparameter, 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.