Skip to content

Commit 1633b60

Browse files
authored
Enable threads, multi-memory, and relaxed-simd by default (#7285)
* Enable threads, multi-memory, and relaxed-simd by default This commit enables by default three proposals that were advanced to stage 4 in the proposal process at last week's in-person CG meeting. These proposals are: * `threads` - atomic instructions and shared memory * `multi-memory` - the ability to have more than one linear memory * `relaxed-simd` - new simd instructions that may differ across platforms These proposals are now all enabled by default in Wasmtime. Note that they can still be selectively disabled via `Config` options. * Fix an x64-specific test
1 parent 5c7ed43 commit 1633b60

File tree

3 files changed

+28
-42
lines changed

3 files changed

+28
-42
lines changed

crates/wasmtime/src/config.rs

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,6 @@ impl Config {
230230
ret.wasm_simd(true);
231231
ret.wasm_backtrace_details(WasmBacktraceDetails::Environment);
232232

233-
ret.wasm_relaxed_simd(false);
234-
ret.wasm_threads(false);
235-
ret.wasm_multi_memory(false);
236-
237233
// This is on-by-default in `wasmparser` since it's a stage 4+ proposal
238234
// but it's not implemented in Wasmtime yet so disable it.
239235
ret.features.tail_call = false;
@@ -660,31 +656,23 @@ impl Config {
660656
self
661657
}
662658

663-
/// Configures whether the WebAssembly threads proposal will be enabled for
664-
/// compilation.
665-
///
666-
/// The [WebAssembly threads proposal][threads] is not currently fully
667-
/// standardized and is undergoing development. Additionally the support in
668-
/// wasmtime itself is still being worked on. Support for this feature can
669-
/// be enabled through this method for appropriate wasm modules.
659+
/// Configures whether the WebAssembly [threads] proposal will be enabled
660+
/// for compilation.
670661
///
671662
/// This feature gates items such as shared memories and atomic
672-
/// instructions. Note that the threads feature depends on the
673-
/// bulk memory feature, which is enabled by default.
663+
/// instructions. Note that the threads feature depends on the bulk memory
664+
/// feature, which is enabled by default. Additionally note that while the
665+
/// wasm feature is called "threads" it does not actually include the
666+
/// ability to spawn threads. Spawning threads is part of the [wasi-threads]
667+
/// proposal which is a separately gated feature in Wasmtime.
674668
///
675-
/// This is `false` by default.
676-
///
677-
/// > **Note**: Wasmtime does not implement everything for the wasm threads
678-
/// > spec at this time, so bugs, panics, and possibly segfaults should be
679-
/// > expected. This should not be enabled in a production setting right
680-
/// > now.
681-
///
682-
/// # Errors
669+
/// Embeddings of Wasmtime are able to build their own custom threading
670+
/// scheme on top of the core wasm threads proposal, however.
683671
///
684-
/// The validation of this feature are deferred until the engine is being built,
685-
/// and thus may cause `Engine::new` fail if the `bulk_memory` feature is disabled.
672+
/// This is `true` by default.
686673
///
687674
/// [threads]: https://github.com/webassembly/threads
675+
/// [wasi-threads]: https://github.com/webassembly/wasi-threads
688676
pub fn wasm_threads(&mut self, enable: bool) -> &mut Self {
689677
self.features.threads = enable;
690678
self
@@ -750,15 +738,13 @@ impl Config {
750738
/// Configures whether the WebAssembly Relaxed SIMD proposal will be
751739
/// enabled for compilation.
752740
///
753-
/// The [WebAssembly Relaxed SIMD proposal][proposal] is not, at the time of
754-
/// this writing, at stage 4. The relaxed SIMD proposal adds new
755-
/// instructions to WebAssembly which, for some specific inputs, are allowed
756-
/// to produce different results on different hosts. More-or-less this
757-
/// proposal enables exposing platform-specific semantics of SIMD
758-
/// instructions in a controlled fashion to a WebAssembly program. From an
759-
/// embedder's perspective this means that WebAssembly programs may execute
760-
/// differently depending on whether the host is x86_64 or AArch64, for
761-
/// example.
741+
/// The relaxed SIMD proposal adds new instructions to WebAssembly which,
742+
/// for some specific inputs, are allowed to produce different results on
743+
/// different hosts. More-or-less this proposal enables exposing
744+
/// platform-specific semantics of SIMD instructions in a controlled
745+
/// fashion to a WebAssembly program. From an embedder's perspective this
746+
/// means that WebAssembly programs may execute differently depending on
747+
/// whether the host is x86_64 or AArch64, for example.
762748
///
763749
/// By default Wasmtime lowers relaxed SIMD instructions to the fastest
764750
/// lowering for the platform it's running on. This means that, by default,
@@ -768,7 +754,7 @@ impl Config {
768754
/// deterministic behavior across all platforms, as classified by the
769755
/// specification, at the cost of performance.
770756
///
771-
/// This is `false` by default.
757+
/// This is `true` by default.
772758
///
773759
/// [proposal]: https://github.com/webassembly/relaxed-simd
774760
pub fn wasm_relaxed_simd(&mut self, enable: bool) -> &mut Self {
@@ -840,7 +826,7 @@ impl Config {
840826
/// This feature gates modules having more than one linear memory
841827
/// declaration or import.
842828
///
843-
/// This is `false` by default.
829+
/// This is `true` by default.
844830
///
845831
/// [proposal]: https://github.com/webassembly/multi-memory
846832
pub fn wasm_multi_memory(&mut self, enable: bool) -> &mut Self {

crates/wasmtime/src/engine/serialization.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,27 +629,27 @@ Caused by:
629629
#[test]
630630
fn test_feature_mismatch() -> Result<()> {
631631
let mut config = Config::new();
632-
config.wasm_simd(true);
632+
config.wasm_threads(true);
633633

634634
let engine = Engine::new(&config)?;
635635
let mut metadata = Metadata::new(&engine);
636-
metadata.features.simd = false;
636+
metadata.features.threads = false;
637637

638638
match metadata.check_compatible(&engine) {
639639
Ok(_) => unreachable!(),
640-
Err(e) => assert_eq!(e.to_string(), "Module was compiled without WebAssembly SIMD support but it is enabled for the host"),
640+
Err(e) => assert_eq!(e.to_string(), "Module was compiled without WebAssembly threads support but it is enabled for the host"),
641641
}
642642

643643
let mut config = Config::new();
644-
config.wasm_simd(false);
644+
config.wasm_threads(false);
645645

646646
let engine = Engine::new(&config)?;
647647
let mut metadata = Metadata::new(&engine);
648-
metadata.features.simd = true;
648+
metadata.features.threads = true;
649649

650650
match metadata.check_compatible(&engine) {
651651
Ok(_) => unreachable!(),
652-
Err(e) => assert_eq!(e.to_string(), "Module was compiled with WebAssembly SIMD support but it is not enabled for the host"),
652+
Err(e) => assert_eq!(e.to_string(), "Module was compiled with WebAssembly threads support but it is not enabled for the host"),
653653
}
654654

655655
Ok(())

tests/all/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn caches_across_engines() {
4343
// differ in wasm features enabled (which can affect
4444
// runtime/compilation settings)
4545
let res = Module::deserialize(
46-
&Engine::new(Config::new().wasm_simd(false)).unwrap(),
46+
&Engine::new(Config::new().wasm_threads(false)).unwrap(),
4747
&bytes,
4848
);
4949
assert!(res.is_err());
@@ -182,7 +182,7 @@ fn serialize_not_overly_massive() -> Result<()> {
182182
#[cfg_attr(any(not(target_arch = "x86_64"), miri), ignore)]
183183
fn missing_sse_and_floats_still_works() -> Result<()> {
184184
let mut config = Config::new();
185-
config.wasm_simd(false);
185+
config.wasm_simd(false).wasm_relaxed_simd(false);
186186
unsafe {
187187
config.cranelift_flag_set("has_sse41", "false");
188188
}

0 commit comments

Comments
 (0)