-
Couldn't load subscription status.
- Fork 127
[pointer] Support generic TransmuteFrom framework
#2408
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
bd18425 to
4bd4fd9
Compare
feb5ccf to
03547a1
Compare
|
I think we may have to handle |
4bd4fd9 to
f1b2bec
Compare
03547a1 to
0c59508
Compare
f1b2bec to
653cdb9
Compare
653cdb9 to
3e52166
Compare
0c59508 to
daf3a21
Compare
c640f3e to
6151c97
Compare
6151c97 to
bbf07a8
Compare
b37fcfa to
3a43dfd
Compare
0c63965 to
9c88adc
Compare
daf3a21 to
c559aad
Compare
a247151 to
8695084
Compare
c559aad to
9a5a4dd
Compare
079852a to
48e7eb3
Compare
TransmuteFrom framework
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2408 +/- ##
==========================================
+ Coverage 87.33% 88.03% +0.70%
==========================================
Files 17 17
Lines 6451 6412 -39
==========================================
+ Hits 5634 5645 +11
+ Misses 817 767 -50 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
48e7eb3 to
91aea96
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.
Developed and reviewed in tandem!
This commit removes the `TransparentWrapper` trait and the `Ptr::transparent_wrapper_into_inner` method. It replaces them with a new family of transmutation traits which encode more generic transmutation (from any `T` to any `U`) and a set of `Ptr` methods which use those traits to bound transmutation operations. In particular: - `Dst: TransmuteFrom<Src>` denotes that a by-value transmutation is sound - `Dst: TryTransmuteFromPtr<Src>` denotes that a transmutation is sound so long as it can be guaranteed that the source is bit-valid for the destination; this is used by e.g. `Ptr::try_into_valid`, which performs runtime validation of bit validity - `Dst: TransmuteFromPtr<Src>` is equivalent to `TransmuteFrom<Src> + TryTransmuteFromPtr<Src>` Some type arguments are omitted in this summary. In particular, all three traits also take validity invariant parameters for both the source and destination types. Also, the `[Try]TransmuteFromPtr` traits take an aliasing parameter. In order to support these traits, we introduce a generalization of `Read` known as `MutationCompatible`. `T: MutationCompatible<U, A>` denotes that *either* `T: Read<A>` and `U: Read<A>` *or* `T` and `U` have the same interior mutation semantics (formally, it is sound for `&T` and `&U` to reference the same referent - safe code operating on these references cannot cause undefined behavior). This is a refinement of the "`UnsafeCell` agreement" concept that we have used before, but it supports types which store but don't actually use `UnsafeCell`s. For example, given a hypothetical `ReadOnly<T>`, the following bound holds: usize: MutationCompatible<ReadOnly<AtomicUsize>, Exclusive> This commit also takes a different approach from the one originally envisioned in #1945. In particular, it turns out that we don't need a full type-level mapping concept. Instead, we need a *predicate* over transitions to determine which ones are valid (e.g., it is valid to go from a `Valid` `MaybeUninit<T>` to an `Uninit` `MaybeUninit<T>`). By contrast, the invariant mapping concept suggests that each source validity has *exactly one* destination validity. This commit makes progress on #1940 by supporting unsized transmutations, but we don't yet support size shrinking or expanding transmutations. This commit obsoletes #1359, as that issue was predicated upon the existence of `TransparentWrapper`, which this commit removes. This commit closes #1226, which suggests supporting `UnsafeCell` agreement. Closes #1945 Closes #1359 Closes #2226 Closes #1226 Closes #1866 Makes progress on #1359 Co-authored-by: Jack Wrenn <[email protected]> gherrit-pr-id: Iad14813bc6d933312bc8d7a1ddcf1aafc7126938
91aea96 to
64a08b3
Compare
In #2408, we simplified the safety precondition of `unsafe_impl!`, but did not remove safety proofs at call sites made redundant by that simplification. This commit removes those now-obsolete proofs. gherrit-pr-id: I70d5aa5ace6bd2e39e679eac7f00a66d4b843d57
In #2408, we simplified the safety precondition of `unsafe_impl!`, but did not remove safety proofs at call sites made redundant by that simplification. This commit removes those now-obsolete proofs. gherrit-pr-id: I70d5aa5ace6bd2e39e679eac7f00a66d4b843d57
* Implement traits for Cell Closes #1253 gherrit-pr-id: I569b74086a5f98cda71b4a4131f9ce4f89dcc623 * Remove obsolete safety proofs In #2408, we simplified the safety precondition of `unsafe_impl!`, but did not remove safety proofs at call sites made redundant by that simplification. This commit removes those now-obsolete proofs. gherrit-pr-id: I70d5aa5ace6bd2e39e679eac7f00a66d4b843d57
This commit removes the
TransparentWrappertrait and thePtr::transparent_wrapper_into_innermethod. It replaces them with anew family of transmutation traits which encode more generic
transmutation (from any
Tto anyU) and a set ofPtrmethods whichuse those traits to bound transmutation operations.
In particular:
Dst: TransmuteFrom<Src>denotes that a by-value transmutation issound
Dst: TryTransmuteFromPtr<Src>denotes that a transmutation is soundso long as it can be guaranteed that the source is bit-valid for the
destination; this is used by e.g.
Ptr::try_into_valid, whichperforms runtime validation of bit validity
Dst: TransmuteFromPtr<Src>is equivalent toTransmuteFrom<Src> + TryTransmuteFromPtr<Src>Some type arguments are omitted in this summary. In particular, all
three traits also take validity invariant parameters for both the source
and destination types. Also, the
[Try]TransmuteFromPtrtraits take analiasing parameter.
In order to support these traits, we introduce a generalization of
Readknown asMutationCompatible.T: MutationCompatible<U, A>denotes that either
T: Read<A>andU: Read<A>orTandUhave the same interior mutation semantics (formally, it is sound for
&Tand&Uto reference the same referent - safe code operating onthese references cannot cause undefined behavior). This is a refinement
of the "
UnsafeCellagreement" concept that we have used before, but itsupports types which store but don't actually use
UnsafeCells. Forexample, given a hypothetical
ReadOnly<T>, the following bound holds:This commit also takes a different approach from the one originally
envisioned in #1945. In particular, it turns out that we don't need a
full type-level mapping concept. Instead, we need a predicate over
transitions to determine which ones are valid (e.g., it is valid to go
from a
ValidMaybeUninit<T>to anUninitMaybeUninit<T>). Bycontrast, the invariant mapping concept suggests that each source
validity has exactly one destination validity.
This commit makes progress on #1940 by supporting unsized
transmutations, but we don't yet support size shrinking or expanding
transmutations.
This commit obsoletes #1359, as that issue was predicated upon the
existence of
TransparentWrapper, which this commit removes.This commit closes #1226, which suggests supporting
UnsafeCellagreement.
Closes #1945
Closes #1359
Closes #2226
Closes #1226
Closes #1866
Makes progress on #1359
Co-authored-by: Jack Wrenn [email protected]
This PR is on branch ptr-validity.
TransmuteFromframework #2408