You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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#1945Closes#1359Closes#2226Closes#1226Closes#1866
Makes progress on #1359
Co-authored-by: Jack Wrenn <[email protected]>
gherrit-pr-id: Iad14813bc6d933312bc8d7a1ddcf1aafc7126938
0 commit comments