@@ -13,7 +13,6 @@ use std::{
13
13
use dashmap:: { DashMap , SharedValue } ;
14
14
use hashbrown:: { hash_map:: RawEntryMut , HashMap } ;
15
15
use rustc_hash:: FxHasher ;
16
- use sptr:: Strict ;
17
16
use triomphe:: Arc ;
18
17
19
18
pub mod symbols;
@@ -84,7 +83,7 @@ impl TaggedArcPtr {
84
83
#[ inline]
85
84
pub ( crate ) unsafe fn try_as_arc_owned ( self ) -> Option < ManuallyDrop < Arc < Box < str > > > > {
86
85
// 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 ;
88
87
if tag != 0 {
89
88
// Safety: We checked that the tag is non-zero -> true, so we are pointing to the data offset of an `Arc`
90
89
Some ( ManuallyDrop :: new ( unsafe {
@@ -99,40 +98,18 @@ impl TaggedArcPtr {
99
98
fn pack_arc ( ptr : NonNull < * const str > ) -> NonNull < * const str > {
100
99
let packed_tag = true as usize ;
101
100
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
+ }
127
106
}
128
107
129
108
#[ inline]
130
109
pub ( crate ) fn pointer ( self ) -> NonNull < * const str > {
131
110
// SAFETY: The resulting pointer is guaranteed to be NonNull as we only modify the niche bytes
132
111
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 ) )
136
113
}
137
114
}
138
115
0 commit comments