pub struct TaggedRef<'a, Pointee: Aligned + ?Sized, T: Tag> {
packed: NonNull<Pointee>,
tag_pointer_ghost: PhantomData<(&'a Pointee, T)>,
}
Expand description
A covariant Copy
tagged borrow. This is essentially { pointer: &'a P, tag: T }
packed
in a single reference.
Fields§
§packed: NonNull<Pointee>
This is semantically a pair of pointer: &'a P
and tag: T
fields,
however we pack them in a single pointer, to save space.
We pack the tag into the most-significant bits of the pointer to ease retrieval of the value. A left shift is a multiplication and those are embeddable in instruction encoding, for example:
// (<https://godbolt.org/z/jqcYPWEr3>)
example::shift_read3:
mov eax, dword ptr [8*rdi]
ret
example::mask_read3:
and rdi, -8
mov eax, dword ptr [rdi]
ret
This is ASM outputted by rustc for reads of values behind tagged pointers for different approaches of tagging:
shift_read3
uses<< 3
(the tag is in the most-significant bits)mask_read3
uses& !0b111
(the tag is in the least-significant bits)
The shift approach thus produces less instructions and is likely faster (see https://godbolt.org/z/Y913sMdWb).
Encoding diagram:
[ packed.addr ]
[ tag ] [ pointer.addr >> T::BITS ] <-- usize::BITS - T::BITS bits
^
|
T::BITS bits
The tag can be retrieved by packed.addr() >> T::BITS
and the pointer
can be retrieved by packed.map_addr(|addr| addr << T::BITS)
.
tag_pointer_ghost: PhantomData<(&'a Pointee, T)>
Implementations§
Source§impl<'a, P, T> TaggedRef<'a, P, T>
impl<'a, P, T> TaggedRef<'a, P, T>
Trait Implementations§
Source§impl<'a, P, T, HCX> HashStable<HCX> for TaggedRef<'a, P, T>
impl<'a, P, T, HCX> HashStable<HCX> for TaggedRef<'a, P, T>
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher)
impl<P, T> Copy for TaggedRef<'_, P, T>
impl<'a, P: Sync, T: Send + Tag> DynSend for TaggedRef<'a, P, T>
impl<'a, P: Sync, T: Sync + Tag> DynSync for TaggedRef<'a, P, T>
impl<P, T: Tag> Eq for TaggedRef<'_, P, T>
impl<P, T> Send for TaggedRef<'_, P, T>
impl<P, T> Sync for TaggedRef<'_, P, T>
Auto Trait Implementations§
impl<'a, Pointee, T> Freeze for TaggedRef<'a, Pointee, T>where
Pointee: ?Sized,
impl<'a, Pointee, T> RefUnwindSafe for TaggedRef<'a, Pointee, T>
impl<'a, Pointee, T> Unpin for TaggedRef<'a, Pointee, T>
impl<'a, Pointee, T> UnwindSafe for TaggedRef<'a, Pointee, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.