Skip to content

Commit

Permalink
Enables WASM Threads Proposal Permanently
Browse files Browse the repository at this point in the history
  • Loading branch information
Dheatly23 committed Nov 4, 2024
1 parent 2f06809 commit 743916a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ features = [
"wat",
"parallel-compilation",
"gc",
"threads",
"demangle",
"addr2line",
"debug-builtins",
Expand Down Expand Up @@ -81,7 +82,6 @@ object-registry-extern = []
object-registry = ["object-registry-compat", "object-registry-extern"]
more-precise-timer = []
deterministic-wasm = []
wasm-threads = ["wasmtime/threads"]
component-model = [
"wasmtime/component-model",
"dep:wasmparser",
Expand Down
9 changes: 0 additions & 9 deletions doc/misc/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ Enables WASI 0.2

Enables component-based Godot value manipulation.

### WASM Threads Proposal

* Feature: `wasm-threads`
* Default: false

Enables WASM threads proposal, allowing use of shared memory,
atomic instruction, and notification.
Note that multi-threading is a separate thing and currently cannot be done inside WASM code.

### Deterministic WASM

* Feature: `deterministic-wasm`
Expand Down
3 changes: 1 addition & 2 deletions src/wasm_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ pub fn init_engine() {
.wasm_multi_value(true)
.wasm_multi_memory(true)
.wasm_memory64(true)
.wasm_threads(true)
.wasm_custom_page_sizes(true);
#[cfg(feature = "wasm-threads")]
config.wasm_threads(true);
#[cfg(feature = "component-model")]
config.wasm_component_model(true);

Expand Down
13 changes: 3 additions & 10 deletions src/wasm_instance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#[cfg(feature = "wasi")]
use std::any::Any;
#[cfg(feature = "wasm-threads")]
use std::cell::UnsafeCell;
use std::collections::hash_map::{Entry, HashMap};
use std::hash::{Hash, Hasher};
#[cfg(feature = "wasi")]
Expand All @@ -23,10 +21,9 @@ use wasmtime::component::ResourceTable;
use wasmtime::Linker;
#[cfg(feature = "memory-limiter")]
use wasmtime::ResourceLimiter;
#[cfg(feature = "wasm-threads")]
use wasmtime::SharedMemory;
use wasmtime::{
AsContextMut, Extern, Func, FuncType, Instance as InstanceWasm, Memory, Store, StoreContextMut,
AsContextMut, Extern, Func, FuncType, Instance as InstanceWasm, Memory, SharedMemory, Store,
StoreContextMut,
};
#[cfg(feature = "wasi")]
use wasmtime_wasi::preview1::{add_to_linker_sync, WasiP1Ctx};
Expand Down Expand Up @@ -64,7 +61,6 @@ use crate::{bail_with_site, site_context, variant_dispatch};

enum MemoryType {
Memory(Memory),
#[cfg(feature = "wasm-threads")]
SharedMemory(SharedMemory),
}

Expand Down Expand Up @@ -681,7 +677,6 @@ impl WasmInstance {
InstanceType::Core(inst) => {
match inst.get_export(ret.store.get_mut(), MEMORY_EXPORT) {
Some(Extern::Memory(mem)) => Some(MemoryType::Memory(mem)),
#[cfg(feature = "wasm-threads")]
Some(Extern::SharedMemory(mem)) => Some(MemoryType::SharedMemory(mem)),
_ => None,
}
Expand Down Expand Up @@ -710,11 +705,10 @@ impl WasmInstance {
m.acquire_store(|_, store| {
f(match &self.memory {
Some(MemoryType::Memory(mem)) => mem.data_mut(store),
#[cfg(feature = "wasm-threads")]
// SAFETY: Externalize concurrent access to user
#[allow(mutable_transmutes)]
Some(MemoryType::SharedMemory(mem)) => unsafe {
mem::transmute::<&[UnsafeCell<u8>], &mut [u8]>(mem.data())
mem::transmute::<&[_], &mut [u8]>(mem.data())
},
None => bail_with_site!("No memory exported"),
})
Expand Down Expand Up @@ -1106,7 +1100,6 @@ impl WasmInstance {
InstanceType::Core(inst) => match inst.get_export(store, &name.to_string())
{
Some(Extern::Memory(mem)) => Some(MemoryType::Memory(mem)),
#[cfg(feature = "wasm-threads")]
Some(Extern::SharedMemory(mem)) => Some(MemoryType::SharedMemory(mem)),
_ => None,
},
Expand Down

0 comments on commit 743916a

Please sign in to comment.