@@ -13,7 +13,6 @@ use std::{
1313use dashmap:: { DashMap , SharedValue } ;
1414use hashbrown:: { hash_map:: RawEntryMut , HashMap } ;
1515use rustc_hash:: FxHasher ;
16- use sptr:: Strict ;
1716use triomphe:: Arc ;
1817
1918pub mod symbols;
@@ -84,7 +83,7 @@ impl TaggedArcPtr {
8483 #[ inline]
8584 pub ( crate ) unsafe fn try_as_arc_owned ( self ) -> Option < ManuallyDrop < Arc < Box < str > > > > {
8685 // Unpack the tag from the alignment niche
87- let tag = Strict :: addr ( self . packed . as_ptr ( ) ) & Self :: BOOL_BITS ;
86+ let tag = self . packed . as_ptr ( ) . addr ( ) & Self :: BOOL_BITS ;
8887 if tag != 0 {
8988 // Safety: We checked that the tag is non-zero -> true, so we are pointing to the data offset of an `Arc`
9089 Some ( ManuallyDrop :: new ( unsafe {
@@ -99,40 +98,18 @@ impl TaggedArcPtr {
9998 fn pack_arc ( ptr : NonNull < * const str > ) -> NonNull < * const str > {
10099 let packed_tag = true as usize ;
101100
102- // can't use this strict provenance stuff here due to trait methods not being const
103- // unsafe {
104- // // Safety: The pointer is derived from a non-null
105- // NonNull::new_unchecked(Strict::map_addr(ptr.as_ptr(), |addr| {
106- // // Safety:
107- // // - The pointer is `NonNull` => it's address is `NonZero<usize>`
108- // // - `P::BITS` least significant bits are always zero (`Pointer` contract)
109- // // - `T::BITS <= P::BITS` (from `Self::ASSERTION`)
110- // //
111- // // Thus `addr >> T::BITS` is guaranteed to be non-zero.
112- // //
113- // // `{non_zero} | packed_tag` can't make the value zero.
114-
115- // (addr >> Self::BOOL_BITS) | packed_tag
116- // }))
117- // }
118- // so what follows is roughly what the above looks like but inlined
119-
120- let self_addr = ptr. as_ptr ( ) as * const * const str as usize ;
121- let addr = self_addr | packed_tag;
122- let dest_addr = addr as isize ;
123- let offset = dest_addr. wrapping_sub ( self_addr as isize ) ;
124-
125- // SAFETY: The resulting pointer is guaranteed to be NonNull as we only modify the niche bytes
126- unsafe { NonNull :: new_unchecked ( ptr. as_ptr ( ) . cast :: < u8 > ( ) . wrapping_offset ( offset) . cast ( ) ) }
101+ unsafe {
102+ // Safety: The pointer is derived from a non-null and bit-oring it with true (1) will
103+ // not make it null.
104+ NonNull :: new_unchecked ( ptr. as_ptr ( ) . map_addr ( |addr| addr | packed_tag) )
105+ }
127106 }
128107
129108 #[ inline]
130109 pub ( crate ) fn pointer ( self ) -> NonNull < * const str > {
131110 // SAFETY: The resulting pointer is guaranteed to be NonNull as we only modify the niche bytes
132111 unsafe {
133- NonNull :: new_unchecked ( Strict :: map_addr ( self . packed . as_ptr ( ) , |addr| {
134- addr & !Self :: BOOL_BITS
135- } ) )
112+ NonNull :: new_unchecked ( self . packed . as_ptr ( ) . map_addr ( |addr| addr & !Self :: BOOL_BITS ) )
136113 }
137114 }
138115
0 commit comments