Skip to content

Commit 39962ff

Browse files
authored
Merge pull request #18909 from Veykril/push-rrpprwwzttkt
Use `strict_provenance`
2 parents b7a3d60 + 090a145 commit 39962ff

File tree

4 files changed

+8
-39
lines changed

4 files changed

+8
-39
lines changed

Diff for: Cargo.lock

-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
44
resolver = "2"
55

66
[workspace.package]
7-
rust-version = "1.83"
7+
rust-version = "1.84"
88
edition = "2021"
99
license = "MIT OR Apache-2.0"
1010
authors = ["rust-analyzer team"]

Diff for: crates/intern/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dashmap.workspace = true
1919
hashbrown.workspace = true
2020
rustc-hash.workspace = true
2121
triomphe.workspace = true
22-
sptr = "0.3.2"
2322

2423
[lints]
2524
workspace = true

Diff for: crates/intern/src/symbol.rs

+7-30
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::{
1313
use dashmap::{DashMap, SharedValue};
1414
use hashbrown::{hash_map::RawEntryMut, HashMap};
1515
use rustc_hash::FxHasher;
16-
use sptr::Strict;
1716
use triomphe::Arc;
1817

1918
pub 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

Comments
 (0)