Skip to content

Commit 8a5a573

Browse files
committed
Clarify addr and with_addr implementations
1 parent e7cc021 commit 8a5a573

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

crates/core_simd/src/elements/const_ptr.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,21 @@ where
8383

8484
#[inline]
8585
fn addr(self) -> Self::Usize {
86-
// Safety: Since `addr` discards provenance, this is safe.
86+
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
87+
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
88+
// provenance).
8789
unsafe { core::mem::transmute_copy(&self) }
88-
89-
//TODO switch to casts when available
90-
//self.cast()
9190
}
9291

9392
#[inline]
94-
fn with_addr(self, addr: Self::Usize) -> Self {
93+
fn with_addr(self, _addr: Self::Usize) -> Self {
9594
unimplemented!()
9695
/*
96+
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
97+
//
98+
// In the mean-time, this operation is defined to be "as if" it was
99+
// a wrapping_offset, so we can emulate it as such. This should properly
100+
// restore pointer provenance even under today's compiler.
97101
self.cast::<*const u8>()
98102
.wrapping_offset(addr.cast::<isize>() - self.addr().cast::<isize>())
99103
.cast()

crates/core_simd/src/elements/mut_ptr.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,21 @@ where
7878

7979
#[inline]
8080
fn addr(self) -> Self::Usize {
81-
// Safety: Since `addr` discards provenance, this is safe.
81+
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
82+
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
83+
// provenance).
8284
unsafe { core::mem::transmute_copy(&self) }
83-
84-
//TODO switch to casts when available
85-
//self.cast()
8685
}
8786

8887
#[inline]
89-
fn with_addr(self, addr: Self::Usize) -> Self {
88+
fn with_addr(self, _addr: Self::Usize) -> Self {
9089
unimplemented!()
9190
/*
91+
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
92+
//
93+
// In the mean-time, this operation is defined to be "as if" it was
94+
// a wrapping_offset, so we can emulate it as such. This should properly
95+
// restore pointer provenance even under today's compiler.
9296
self.cast::<*mut u8>()
9397
.wrapping_offset(addr.cast::<isize>() - self.addr().cast::<isize>())
9498
.cast()

0 commit comments

Comments
 (0)