Skip to content

Commit 80615d9

Browse files
authored
Merge pull request #18909 from Veykril/push-rrpprwwzttkt
Use `strict_provenance`
2 parents a91b571 + 105ea3b commit 80615d9

File tree

4 files changed

+8
-39
lines changed

4 files changed

+8
-39
lines changed

src/tools/rust-analyzer/Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,6 @@ dependencies = [
846846
"dashmap",
847847
"hashbrown",
848848
"rustc-hash 2.0.0",
849-
"sptr",
850849
"triomphe",
851850
]
852851

@@ -1927,12 +1926,6 @@ dependencies = [
19271926
"vfs",
19281927
]
19291928

1930-
[[package]]
1931-
name = "sptr"
1932-
version = "0.3.2"
1933-
source = "registry+https://github.com/rust-lang/crates.io-index"
1934-
checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a"
1935-
19361929
[[package]]
19371930
name = "stdx"
19381931
version = "0.0.0"

src/tools/rust-analyzer/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"]

src/tools/rust-analyzer/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

src/tools/rust-analyzer/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)