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
Extend Ptr to support storing unboxed Ts by-value. Retain existing invariant transformations which make sense in the context of values (e.g., transformations on bit validity).
Motivation
Many of the behaviors of Ptr aren't actually specific to pointers. For example, a hypothetical MaybeValue<T> could keep track of whether it owns a bit-valid T just as Ptr does, and could provide various invariant state transitions.
Instead of introducing a new MaybeValue type, we could just teach Ptr to also store values. This would permit us to re-use existing Ptr conversions which are not specific to pointers and apply those conversions to values.
This would also permit us to replace or unify some existing abstractions:
Building on #1797, we can make this support T: ?Sized + KnownLayout like so:
structPtr<'a,T,I>whereT: ?Sized,I:Invariants,I::Aliasing:Aliasing<'a,T>{inner: <I::AliasingasAliasing<'a,T>>::Inner,}traitInvariants{typeAliasing;}traitAliasing<'a,T: ?Sized>{typeInner;}enumValue{}impl<'a,T: ?Sized + KnownLayout>Aliasing<'a,T>forValue{typeInner = T::MaybeUninit;// New associated type on `KnownLayout`; see #1797, #1822}enumShared{}impl<'a,T: ?Sized + KnownLayout>Aliasing<'a,T>forShared{typeInner = NonNull<T>;}enumExclusive{}impl<'a,T: ?Sized + KnownLayout>Aliasing<'a,T>forExclusive{typeInner = NonNull<T>;}
This design is prototyped here, although it looks slightly different since we have to redefine various zerocopy internals to get it to work on the Rust playground.
This dovetails with #1839, which may require us to store something other than a NonNull<T> for Exclusive-aliased Ptrs.
Open questions
How do we support Drop? If we're supporting boxed (Box<T>) or unboxed (T) values, we need to support Drop, but only when certain invariants (e.g., bit validity) are satisfied.
The text was updated successfully, but these errors were encountered:
joshlf
changed the title
Teach Ptr to store unboxed values
Extend Ptr to store unboxed values
Oct 11, 2024
Overview
Extend
Ptr
to support storing unboxedT
s by-value. Retain existing invariant transformations which make sense in the context of values (e.g., transformations on bit validity).Motivation
Many of the behaviors of
Ptr
aren't actually specific to pointers. For example, a hypotheticalMaybeValue<T>
could keep track of whether it owns a bit-validT
just asPtr
does, and could provide various invariant state transitions.Instead of introducing a new
MaybeValue
type, we could just teachPtr
to also store values. This would permit us to re-use existingPtr
conversions which are not specific to pointers and apply those conversions to values.This would also permit us to replace or unify some existing abstractions:
Unalign
andUnalignUnsized
MaybeUninit<T: ?Sized + KnownLayout>
ReadOnly
It would also dovetail nicely with extending
Ptr
to support other pointer types.Design
Building on #1797, we can make this support
T: ?Sized + KnownLayout
like so:This design is prototyped here, although it looks slightly different since we have to redefine various zerocopy internals to get it to work on the Rust playground.
This dovetails with #1839, which may require us to store something other than a
NonNull<T>
forExclusive
-aliasedPtr
s.Open questions
Drop
? If we're supporting boxed (Box<T>
) or unboxed (T
) values, we need to supportDrop
, but only when certain invariants (e.g., bit validity) are satisfied.The text was updated successfully, but these errors were encountered: