mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Use strict_provenance
This commit is contained in:
parent
b7a3d606ea
commit
090a145d44
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -846,7 +846,6 @@ dependencies = [
|
|||||||
"dashmap",
|
"dashmap",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
"rustc-hash 2.0.0",
|
"rustc-hash 2.0.0",
|
||||||
"sptr",
|
|
||||||
"triomphe",
|
"triomphe",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1927,12 +1926,6 @@ dependencies = [
|
|||||||
"vfs",
|
"vfs",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sptr"
|
|
||||||
version = "0.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stdx"
|
name = "stdx"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
@ -4,7 +4,7 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
rust-version = "1.83"
|
rust-version = "1.84"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
authors = ["rust-analyzer team"]
|
authors = ["rust-analyzer team"]
|
||||||
|
@ -19,7 +19,6 @@ dashmap.workspace = true
|
|||||||
hashbrown.workspace = true
|
hashbrown.workspace = true
|
||||||
rustc-hash.workspace = true
|
rustc-hash.workspace = true
|
||||||
triomphe.workspace = true
|
triomphe.workspace = true
|
||||||
sptr = "0.3.2"
|
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
@ -13,7 +13,6 @@ use std::{
|
|||||||
use dashmap::{DashMap, SharedValue};
|
use dashmap::{DashMap, SharedValue};
|
||||||
use hashbrown::{hash_map::RawEntryMut, HashMap};
|
use hashbrown::{hash_map::RawEntryMut, HashMap};
|
||||||
use rustc_hash::FxHasher;
|
use rustc_hash::FxHasher;
|
||||||
use sptr::Strict;
|
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
pub mod symbols;
|
pub mod symbols;
|
||||||
@ -84,7 +83,7 @@ impl TaggedArcPtr {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) unsafe fn try_as_arc_owned(self) -> Option<ManuallyDrop<Arc<Box<str>>>> {
|
pub(crate) unsafe fn try_as_arc_owned(self) -> Option<ManuallyDrop<Arc<Box<str>>>> {
|
||||||
// Unpack the tag from the alignment niche
|
// Unpack the tag from the alignment niche
|
||||||
let tag = Strict::addr(self.packed.as_ptr()) & Self::BOOL_BITS;
|
let tag = self.packed.as_ptr().addr() & Self::BOOL_BITS;
|
||||||
if tag != 0 {
|
if tag != 0 {
|
||||||
// Safety: We checked that the tag is non-zero -> true, so we are pointing to the data offset of an `Arc`
|
// Safety: We checked that the tag is non-zero -> true, so we are pointing to the data offset of an `Arc`
|
||||||
Some(ManuallyDrop::new(unsafe {
|
Some(ManuallyDrop::new(unsafe {
|
||||||
@ -99,40 +98,18 @@ impl TaggedArcPtr {
|
|||||||
fn pack_arc(ptr: NonNull<*const str>) -> NonNull<*const str> {
|
fn pack_arc(ptr: NonNull<*const str>) -> NonNull<*const str> {
|
||||||
let packed_tag = true as usize;
|
let packed_tag = true as usize;
|
||||||
|
|
||||||
// can't use this strict provenance stuff here due to trait methods not being const
|
unsafe {
|
||||||
// unsafe {
|
// Safety: The pointer is derived from a non-null and bit-oring it with true (1) will
|
||||||
// // Safety: The pointer is derived from a non-null
|
// not make it null.
|
||||||
// NonNull::new_unchecked(Strict::map_addr(ptr.as_ptr(), |addr| {
|
NonNull::new_unchecked(ptr.as_ptr().map_addr(|addr| addr | packed_tag))
|
||||||
// // Safety:
|
}
|
||||||
// // - The pointer is `NonNull` => it's address is `NonZero<usize>`
|
|
||||||
// // - `P::BITS` least significant bits are always zero (`Pointer` contract)
|
|
||||||
// // - `T::BITS <= P::BITS` (from `Self::ASSERTION`)
|
|
||||||
// //
|
|
||||||
// // Thus `addr >> T::BITS` is guaranteed to be non-zero.
|
|
||||||
// //
|
|
||||||
// // `{non_zero} | packed_tag` can't make the value zero.
|
|
||||||
|
|
||||||
// (addr >> Self::BOOL_BITS) | packed_tag
|
|
||||||
// }))
|
|
||||||
// }
|
|
||||||
// so what follows is roughly what the above looks like but inlined
|
|
||||||
|
|
||||||
let self_addr = ptr.as_ptr() as *const *const str as usize;
|
|
||||||
let addr = self_addr | packed_tag;
|
|
||||||
let dest_addr = addr as isize;
|
|
||||||
let offset = dest_addr.wrapping_sub(self_addr as isize);
|
|
||||||
|
|
||||||
// SAFETY: The resulting pointer is guaranteed to be NonNull as we only modify the niche bytes
|
|
||||||
unsafe { NonNull::new_unchecked(ptr.as_ptr().cast::<u8>().wrapping_offset(offset).cast()) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn pointer(self) -> NonNull<*const str> {
|
pub(crate) fn pointer(self) -> NonNull<*const str> {
|
||||||
// SAFETY: The resulting pointer is guaranteed to be NonNull as we only modify the niche bytes
|
// SAFETY: The resulting pointer is guaranteed to be NonNull as we only modify the niche bytes
|
||||||
unsafe {
|
unsafe {
|
||||||
NonNull::new_unchecked(Strict::map_addr(self.packed.as_ptr(), |addr| {
|
NonNull::new_unchecked(self.packed.as_ptr().map_addr(|addr| addr & !Self::BOOL_BITS))
|
||||||
addr & !Self::BOOL_BITS
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user