Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable threads, multi-memory, and relaxed-simd by default #7285

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 20 additions & 34 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ impl Config {
ret.wasm_simd(true);
ret.wasm_backtrace_details(WasmBacktraceDetails::Environment);

ret.wasm_relaxed_simd(false);
ret.wasm_threads(false);
ret.wasm_multi_memory(false);

// This is on-by-default in `wasmparser` since it's a stage 4+ proposal
// but it's not implemented in Wasmtime yet so disable it.
ret.features.tail_call = false;
Expand Down Expand Up @@ -660,31 +656,23 @@ impl Config {
self
}

/// Configures whether the WebAssembly threads proposal will be enabled for
/// compilation.
///
/// The [WebAssembly threads proposal][threads] is not currently fully
/// standardized and is undergoing development. Additionally the support in
/// wasmtime itself is still being worked on. Support for this feature can
/// be enabled through this method for appropriate wasm modules.
/// Configures whether the WebAssembly [threads] proposal will be enabled
/// for compilation.
///
/// This feature gates items such as shared memories and atomic
/// instructions. Note that the threads feature depends on the
/// bulk memory feature, which is enabled by default.
/// instructions. Note that the threads feature depends on the bulk memory
/// feature, which is enabled by default. Additionally note that while the
/// wasm feature is called "threads" it does not actually include the
/// ability to spawn threads. Spawning threads is part of the [wasi-threads]
/// proposal which is a separately gated feature in Wasmtime.
///
/// This is `false` by default.
///
/// > **Note**: Wasmtime does not implement everything for the wasm threads
/// > spec at this time, so bugs, panics, and possibly segfaults should be
/// > expected. This should not be enabled in a production setting right
/// > now.
///
/// # Errors
/// Embeddings of Wasmtime are able to build their own custom threading
/// scheme on top of the core wasm threads proposal, however.
///
/// The validation of this feature are deferred until the engine is being built,
/// and thus may cause `Engine::new` fail if the `bulk_memory` feature is disabled.
/// This is `true` by default.
///
/// [threads]: https://github.com/webassembly/threads
/// [wasi-threads]: https://github.com/webassembly/wasi-threads
pub fn wasm_threads(&mut self, enable: bool) -> &mut Self {
self.features.threads = enable;
self
Expand Down Expand Up @@ -750,15 +738,13 @@ impl Config {
/// Configures whether the WebAssembly Relaxed SIMD proposal will be
/// enabled for compilation.
///
/// The [WebAssembly Relaxed SIMD proposal][proposal] is not, at the time of
/// this writing, at stage 4. The relaxed SIMD proposal adds new
/// instructions to WebAssembly which, for some specific inputs, are allowed
/// to produce different results on different hosts. More-or-less this
/// proposal enables exposing platform-specific semantics of SIMD
/// instructions in a controlled fashion to a WebAssembly program. From an
/// embedder's perspective this means that WebAssembly programs may execute
/// differently depending on whether the host is x86_64 or AArch64, for
/// example.
/// The relaxed SIMD proposal adds new instructions to WebAssembly which,
/// for some specific inputs, are allowed to produce different results on
/// different hosts. More-or-less this proposal enables exposing
/// platform-specific semantics of SIMD instructions in a controlled
/// fashion to a WebAssembly program. From an embedder's perspective this
/// means that WebAssembly programs may execute differently depending on
/// whether the host is x86_64 or AArch64, for example.
///
/// By default Wasmtime lowers relaxed SIMD instructions to the fastest
/// lowering for the platform it's running on. This means that, by default,
Expand All @@ -768,7 +754,7 @@ impl Config {
/// deterministic behavior across all platforms, as classified by the
/// specification, at the cost of performance.
///
/// This is `false` by default.
/// This is `true` by default.
///
/// [proposal]: https://github.com/webassembly/relaxed-simd
pub fn wasm_relaxed_simd(&mut self, enable: bool) -> &mut Self {
Expand Down Expand Up @@ -840,7 +826,7 @@ impl Config {
/// This feature gates modules having more than one linear memory
/// declaration or import.
///
/// This is `false` by default.
/// This is `true` by default.
///
/// [proposal]: https://github.com/webassembly/multi-memory
pub fn wasm_multi_memory(&mut self, enable: bool) -> &mut Self {
Expand Down
12 changes: 6 additions & 6 deletions crates/wasmtime/src/engine/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,27 +629,27 @@ Caused by:
#[test]
fn test_feature_mismatch() -> Result<()> {
let mut config = Config::new();
config.wasm_simd(true);
config.wasm_threads(true);

let engine = Engine::new(&config)?;
let mut metadata = Metadata::new(&engine);
metadata.features.simd = false;
metadata.features.threads = false;

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

let mut config = Config::new();
config.wasm_simd(false);
config.wasm_threads(false);

let engine = Engine::new(&config)?;
let mut metadata = Metadata::new(&engine);
metadata.features.simd = true;
metadata.features.threads = true;

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

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions tests/all/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn caches_across_engines() {
// differ in wasm features enabled (which can affect
// runtime/compilation settings)
let res = Module::deserialize(
&Engine::new(Config::new().wasm_simd(false)).unwrap(),
&Engine::new(Config::new().wasm_threads(false)).unwrap(),
&bytes,
);
assert!(res.is_err());
Expand Down Expand Up @@ -182,7 +182,7 @@ fn serialize_not_overly_massive() -> Result<()> {
#[cfg_attr(any(not(target_arch = "x86_64"), miri), ignore)]
fn missing_sse_and_floats_still_works() -> Result<()> {
let mut config = Config::new();
config.wasm_simd(false);
config.wasm_simd(false).wasm_relaxed_simd(false);
unsafe {
config.cranelift_flag_set("has_sse41", "false");
}
Expand Down