Skip to content

Commit be0ba4b

Browse files
authored
Remove use of sptr crate (#10860)
This was a polyfill before strict provenance APIs were on stable Rust, but they're now stable so use the native methods in `std::ptr` instead.
1 parent fa89f32 commit be0ba4b

File tree

8 files changed

+8
-27
lines changed

8 files changed

+8
-27
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ memfd = "0.6.2"
340340
psm = "0.1.11"
341341
proptest = "1.0.0"
342342
rand = { version = "0.8.3", features = ["small_rng"] }
343-
sptr = "0.3.2"
344343
# serde and serde_derive must have the same version
345344
serde = { version = "1.0.215", default-features = false, features = ['alloc'] }
346345
serde_derive = "1.0.188"

crates/wasmtime/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ wat = { workspace = true, optional = true }
4444
serde = { workspace = true }
4545
serde_derive = { workspace = true }
4646
serde_json = { workspace = true, optional = true }
47-
sptr = { workspace = true }
4847
postcard = { workspace = true }
4948
indexmap = { workspace = true }
5049
once_cell = { version = "1.12.0", optional = true }

crates/wasmtime/src/runtime/vm/component.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use core::mem;
2121
use core::mem::offset_of;
2222
use core::ops::Deref;
2323
use core::ptr::{self, NonNull};
24-
use sptr::Strict;
2524
use wasmtime_environ::component::*;
2625
use wasmtime_environ::{HostPtr, PrimaryMap, VMSharedTypeIndex};
2726

@@ -241,7 +240,7 @@ impl ComponentInstance {
241240

242241
fn vmctx(&self) -> NonNull<VMComponentContext> {
243242
let addr = &raw const self.vmctx;
244-
let ret = Strict::with_addr(self.vmctx_self_reference.as_ptr(), Strict::addr(addr));
243+
let ret = self.vmctx_self_reference.as_ptr().with_addr(addr.addr());
245244
NonNull::new(ret).unwrap()
246245
}
247246

crates/wasmtime/src/runtime/vm/instance.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use core::ptr::NonNull;
2626
#[cfg(target_has_atomic = "64")]
2727
use core::sync::atomic::AtomicU64;
2828
use core::{mem, ptr};
29-
use sptr::Strict;
3029
#[cfg(feature = "gc")]
3130
use wasmtime_environ::ModuleInternedTypeIndex;
3231
use wasmtime_environ::{
@@ -656,13 +655,8 @@ impl Instance {
656655
// (there's an actual load of the field) it does look like that by the
657656
// time the backend runs. (that's magic to me, the backend removing
658657
// loads...)
659-
//
660-
// As a final minor note, strict provenance APIs are not stable on Rust
661-
// today so the `sptr` crate is used. This crate provides the extension
662-
// trait `Strict` but the method names conflict with the nightly methods
663-
// so a different syntax is used to invoke methods here.
664658
let addr = &raw const self.vmctx;
665-
let ret = Strict::with_addr(self.vmctx_self_reference.as_ptr(), Strict::addr(addr));
659+
let ret = self.vmctx_self_reference.as_ptr().with_addr(addr.addr());
666660
NonNull::new(ret).unwrap()
667661
}
668662

crates/wasmtime/src/runtime/vm/table.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use core::ops::Range;
1313
use core::ptr::{self, NonNull};
1414
use core::slice;
1515
use core::{cmp, usize};
16-
use sptr::Strict;
1716
use wasmtime_environ::{
1817
FUNCREF_INIT_BIT, FUNCREF_MASK, IndexType, Trap, Tunables, WasmHeapTopType, WasmRefType,
1918
};
@@ -117,7 +116,7 @@ impl TaggedFuncRef {
117116
fn from(ptr: Option<NonNull<VMFuncRef>>, lazy_init: bool) -> Self {
118117
let ptr = ptr.map(|p| p.as_ptr()).unwrap_or(ptr::null_mut());
119118
if lazy_init {
120-
let masked = Strict::map_addr(ptr, |a| a | FUNCREF_INIT_BIT);
119+
let masked = ptr.map_addr(|a| a | FUNCREF_INIT_BIT);
121120
TaggedFuncRef(masked)
122121
} else {
123122
TaggedFuncRef(ptr)
@@ -133,7 +132,7 @@ impl TaggedFuncRef {
133132
} else {
134133
// Masking off the tag bit is harmless whether the table uses lazy
135134
// init or not.
136-
let unmasked = Strict::map_addr(ptr, |a| a & FUNCREF_MASK);
135+
let unmasked = ptr.map_addr(|a| a & FUNCREF_MASK);
137136
TableElement::FuncRef(NonNull::new(unmasked))
138137
}
139138
}

crates/wasmtime/src/runtime/vm/traphandlers.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,6 @@ pub(crate) mod tls {
867867
// these functions are free to be inlined.
868868
pub(super) mod raw {
869869
use super::CallThreadState;
870-
use sptr::Strict;
871870

872871
pub type Ptr = *const CallThreadState;
873872

@@ -877,15 +876,15 @@ pub(crate) mod tls {
877876

878877
fn tls_get() -> (Ptr, bool) {
879878
let mut initialized = false;
880-
let p = Strict::map_addr(crate::runtime::vm::sys::tls_get(), |a| {
879+
let p = crate::runtime::vm::sys::tls_get().map_addr(|a| {
881880
initialized = (a & 1) != 0;
882881
a & !1
883882
});
884883
(p.cast(), initialized)
885884
}
886885

887886
fn tls_set(ptr: Ptr, initialized: bool) {
888-
let encoded = Strict::map_addr(ptr, |a| a | usize::from(initialized));
887+
let encoded = ptr.map_addr(|a| a | usize::from(initialized));
889888
crate::runtime::vm::sys::tls_set(encoded.cast_mut().cast::<u8>());
890889
}
891890

crates/wasmtime/src/runtime/vm/vmcontext.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use core::marker;
1414
use core::mem::{self, MaybeUninit};
1515
use core::ptr::{self, NonNull};
1616
use core::sync::atomic::{AtomicUsize, Ordering};
17-
use sptr::Strict;
1817
use wasmtime_environ::{
1918
BuiltinFunctionIndex, DefinedMemoryIndex, Unsigned, VMCONTEXT_MAGIC, VMSharedTypeIndex,
2019
WasmHeapTopType, WasmValType,
@@ -1409,7 +1408,7 @@ impl ValRaw {
14091408
#[inline]
14101409
pub fn funcref(i: *mut c_void) -> ValRaw {
14111410
ValRaw {
1412-
funcref: Strict::map_addr(i, |i| i.to_le()),
1411+
funcref: i.map_addr(|i| i.to_le()),
14131412
}
14141413
}
14151414

@@ -1474,7 +1473,7 @@ impl ValRaw {
14741473
/// Gets the WebAssembly `funcref` value
14751474
#[inline]
14761475
pub fn get_funcref(&self) -> *mut c_void {
1477-
unsafe { Strict::map_addr(self.funcref, |i| usize::from_le(i)) }
1476+
unsafe { self.funcref.map_addr(|i| usize::from_le(i)) }
14781477
}
14791478

14801479
/// Gets the WebAssembly `externref` value

0 commit comments

Comments
 (0)