Skip to content

Commit 000bf5e

Browse files
committed
Remove Send+Sync bounds on create_raw_function.
Previously there were two different functions for creating raw functions: one for "host" functions that had the `Send+Sync` bounds and another for "normal" functions without. The implementations of both merged into one implementation and the bounds were kept. However, as `IntoFunc` isn't bounded with `Send+Sync`, a transmute was made to ignore the bounds in `create_raw_function`. The comment for the transmute is now out of date because the implementation is no longer specific to "host" functions. This commit removes the bounds from `create_raw_function` and, by extension, the transmute call. This change really doesn't alter any safety semantics as `Send+Sync` is enforced for host functions when they are defined in `Config`.
1 parent 3c43ed4 commit 000bf5e

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

crates/wasmtime/src/func.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,17 +1787,20 @@ macro_rules! impl_into_func {
17871787
);
17881788

17891789
let trampoline = host_trampoline::<$($args,)* R>;
1790-
let shared_signature_id = registry.map(|r| r.register(ty.as_wasm_func_type(), trampoline)).unwrap_or(VMSharedSignatureIndex::default());
1790+
1791+
// If not given a registry, use a default signature index that is guaranteed to trap
1792+
// if the function is called indirectly without first being associated with a store (a bug condition).
1793+
let shared_signature_id = registry
1794+
.map(|r| r.register(ty.as_wasm_func_type(), trampoline))
1795+
.unwrap_or(VMSharedSignatureIndex::default());
17911796

17921797
let instance = unsafe {
17931798
crate::trampoline::create_raw_function(
17941799
std::slice::from_raw_parts_mut(
17951800
wasm_to_host_shim::<F, $($args,)* R> as *mut _,
17961801
0,
17971802
),
1798-
// This transmutation is safe as the *only* place this should be called is from
1799-
// `Config::wrap_host_func` which adds the Send and Sync bounds on the function.
1800-
std::mem::transmute::<Box<dyn Any>, _>(Box::new(self)),
1803+
Box::new(self),
18011804
shared_signature_id
18021805
)
18031806
.expect("failed to create raw function")

crates/wasmtime/src/trampoline/func.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn create_function(
293293

294294
pub unsafe fn create_raw_function(
295295
func: *mut [VMFunctionBody],
296-
host_state: Box<dyn Any + Send + Sync>,
296+
host_state: Box<dyn Any>,
297297
shared_signature_id: VMSharedSignatureIndex,
298298
) -> Result<InstanceHandle> {
299299
let mut module = Module::new();

0 commit comments

Comments
 (0)