From 577c642560aa37e4547c0e96148c0116c6669b7a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 23 Sep 2024 12:43:10 -0700 Subject: [PATCH 1/4] threads: add feature flags This adds both the Cargo-level and CLI-level flags for the shared-everything-threads proposal. --- Cargo.toml | 1 + crates/cli-flags/Cargo.toml | 1 + crates/cli-flags/src/lib.rs | 3 +++ crates/cranelift/Cargo.toml | 1 + crates/environ/Cargo.toml | 1 + crates/wasmtime/Cargo.toml | 6 ++++++ crates/wasmtime/src/config.rs | 15 +++++++++++++++ 7 files changed, 28 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 286bdea527eb..5f9300dadf3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -493,6 +493,7 @@ coredump = ["wasmtime-cli-flags/coredump"] addr2line = ["wasmtime/addr2line"] debug-builtins = ["wasmtime/debug-builtins"] threads = ["wasmtime-cli-flags/threads"] +shared-everything-threads = ["wasmtime-cli-flags/shared-everything-threads"] gc = ["wasmtime-cli-flags/gc", "wasmtime/gc"] gc-drc = ["gc", "wasmtime/gc-drc", "wasmtime-cli-flags/gc-drc"] gc-null = ["gc", "wasmtime/gc-null", "wasmtime-cli-flags/gc-null"] diff --git a/crates/cli-flags/Cargo.toml b/crates/cli-flags/Cargo.toml index 23dc34036e85..aac287be912f 100644 --- a/crates/cli-flags/Cargo.toml +++ b/crates/cli-flags/Cargo.toml @@ -37,5 +37,6 @@ gc = ["wasmtime/gc"] gc-drc = ["gc", "wasmtime/gc-drc"] gc-null = ["gc", "wasmtime/gc-null"] threads = ["wasmtime/threads"] +shared-everything-threads = ["wasmtime/shared-everything-threads"] memory-protection-keys = ["wasmtime/memory-protection-keys"] pulley = ["wasmtime/pulley"] diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs index bbf2d2a77f4e..dc05f2e26943 100644 --- a/crates/cli-flags/src/lib.rs +++ b/crates/cli-flags/src/lib.rs @@ -358,6 +358,8 @@ wasmtime_option_group! { pub tail_call: Option, /// Configure support for the threads proposal. pub threads: Option, + /// Configure support for the shared-everything-threads proposal. + pub shared_everything_threads: Option, /// Configure support for the memory64 proposal. pub memory64: Option, /// Configure support for the component-model proposal. @@ -1014,6 +1016,7 @@ impl CommonOptions { ("component-model-async", component_model_async_builtins, wasm_component_model_async_builtins) ("component-model-async", component_model_async_stackful, wasm_component_model_async_stackful) ("threads", threads, wasm_threads) + ("shared-everything-threads", shared_everything_threads, wasm_shared_everything_threads) ("gc", gc, wasm_gc) ("gc", reference_types, wasm_reference_types) ("gc", function_references, wasm_function_references) diff --git a/crates/cranelift/Cargo.toml b/crates/cranelift/Cargo.toml index c4ef5cbd2d14..99d5d6e00513 100644 --- a/crates/cranelift/Cargo.toml +++ b/crates/cranelift/Cargo.toml @@ -46,3 +46,4 @@ gc = ["wasmtime-environ/gc"] gc-drc = ["gc", "wasmtime-environ/gc-drc"] gc-null = ["gc", "wasmtime-environ/gc-null"] threads = ["wasmtime-environ/threads"] +shared-everything-threads = ["wasmtime-environ/shared-everything-threads"] diff --git a/crates/environ/Cargo.toml b/crates/environ/Cargo.toml index e85aef15b347..c49916f2cd4f 100644 --- a/crates/environ/Cargo.toml +++ b/crates/environ/Cargo.toml @@ -70,6 +70,7 @@ compile = [ "dep:wasmprinter", ] threads = ['std'] +shared-everything-threads = ['std'] wmemcheck = ['std'] std = [ 'anyhow/std', diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml index e7ef39593f33..6582af2c0b7a 100644 --- a/crates/wasmtime/Cargo.toml +++ b/crates/wasmtime/Cargo.toml @@ -309,6 +309,12 @@ threads = [ "std", ] +# Enable runtime support for the WebAssembly shared-everything-threads proposal. +shared-everything-threads = [ + "wasmtime-cranelift?/shared-everything-threads", + "std", +] + # Controls whether backtraces will attempt to parse DWARF information in # WebAssembly modules and components to provide filenames and line numbers in # stack traces. diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs index 79a6f1b60143..443d3a253e59 100644 --- a/crates/wasmtime/src/config.rs +++ b/crates/wasmtime/src/config.rs @@ -848,6 +848,21 @@ impl Config { self } + /// Configures whether the WebAssembly [shared-everything-threads] proposal + /// will be enabled for compilation. + /// + /// This feature gates extended use of the `shared` attribute on items other + /// than memories, extra atomic instructions, and new component model + /// intrinsics for spawning threads. It depends on the + /// [`wasm_threads`][Self::wasm_threads] being enabled. + /// + /// [shared-everything-threads]: + /// https://github.com/webassembly/shared-everything-threads + pub fn wasm_shared_everything_threads(&mut self, enable: bool) -> &mut Self { + self.wasm_feature(WasmFeatures::SHARED_EVERYTHING_THREADS, enable); + self + } + /// Configures whether the [WebAssembly reference types proposal][proposal] /// will be enabled for compilation. /// From 9dfc58616098ac586c50ef38129c1963ee15e4c4 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 10 Apr 2025 15:14:18 -0700 Subject: [PATCH 2/4] Remove Cargo-level feature flags As recommended in a review, we can probably use the `threads` feature flag instead for the same kind of conditional compilation. --- Cargo.toml | 1 - crates/cli-flags/Cargo.toml | 1 - crates/cranelift/Cargo.toml | 1 - crates/environ/Cargo.toml | 1 - crates/wasmtime/Cargo.toml | 6 ------ 5 files changed, 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f9300dadf3f..286bdea527eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -493,7 +493,6 @@ coredump = ["wasmtime-cli-flags/coredump"] addr2line = ["wasmtime/addr2line"] debug-builtins = ["wasmtime/debug-builtins"] threads = ["wasmtime-cli-flags/threads"] -shared-everything-threads = ["wasmtime-cli-flags/shared-everything-threads"] gc = ["wasmtime-cli-flags/gc", "wasmtime/gc"] gc-drc = ["gc", "wasmtime/gc-drc", "wasmtime-cli-flags/gc-drc"] gc-null = ["gc", "wasmtime/gc-null", "wasmtime-cli-flags/gc-null"] diff --git a/crates/cli-flags/Cargo.toml b/crates/cli-flags/Cargo.toml index aac287be912f..23dc34036e85 100644 --- a/crates/cli-flags/Cargo.toml +++ b/crates/cli-flags/Cargo.toml @@ -37,6 +37,5 @@ gc = ["wasmtime/gc"] gc-drc = ["gc", "wasmtime/gc-drc"] gc-null = ["gc", "wasmtime/gc-null"] threads = ["wasmtime/threads"] -shared-everything-threads = ["wasmtime/shared-everything-threads"] memory-protection-keys = ["wasmtime/memory-protection-keys"] pulley = ["wasmtime/pulley"] diff --git a/crates/cranelift/Cargo.toml b/crates/cranelift/Cargo.toml index 99d5d6e00513..c4ef5cbd2d14 100644 --- a/crates/cranelift/Cargo.toml +++ b/crates/cranelift/Cargo.toml @@ -46,4 +46,3 @@ gc = ["wasmtime-environ/gc"] gc-drc = ["gc", "wasmtime-environ/gc-drc"] gc-null = ["gc", "wasmtime-environ/gc-null"] threads = ["wasmtime-environ/threads"] -shared-everything-threads = ["wasmtime-environ/shared-everything-threads"] diff --git a/crates/environ/Cargo.toml b/crates/environ/Cargo.toml index c49916f2cd4f..e85aef15b347 100644 --- a/crates/environ/Cargo.toml +++ b/crates/environ/Cargo.toml @@ -70,7 +70,6 @@ compile = [ "dep:wasmprinter", ] threads = ['std'] -shared-everything-threads = ['std'] wmemcheck = ['std'] std = [ 'anyhow/std', diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml index 6582af2c0b7a..e7ef39593f33 100644 --- a/crates/wasmtime/Cargo.toml +++ b/crates/wasmtime/Cargo.toml @@ -309,12 +309,6 @@ threads = [ "std", ] -# Enable runtime support for the WebAssembly shared-everything-threads proposal. -shared-everything-threads = [ - "wasmtime-cranelift?/shared-everything-threads", - "std", -] - # Controls whether backtraces will attempt to parse DWARF information in # WebAssembly modules and components to provide filenames and line numbers in # stack traces. From 3cf2e1f50aeb05581a5cbdb33c81d529a438ff98 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 10 Apr 2025 15:16:54 -0700 Subject: [PATCH 3/4] Remove CLI-level flags Since we don't expect users to be interacting with shared-everything-threads modules from the command line, hide this for now. --- crates/cli-flags/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs index dc05f2e26943..bbf2d2a77f4e 100644 --- a/crates/cli-flags/src/lib.rs +++ b/crates/cli-flags/src/lib.rs @@ -358,8 +358,6 @@ wasmtime_option_group! { pub tail_call: Option, /// Configure support for the threads proposal. pub threads: Option, - /// Configure support for the shared-everything-threads proposal. - pub shared_everything_threads: Option, /// Configure support for the memory64 proposal. pub memory64: Option, /// Configure support for the component-model proposal. @@ -1016,7 +1014,6 @@ impl CommonOptions { ("component-model-async", component_model_async_builtins, wasm_component_model_async_builtins) ("component-model-async", component_model_async_stackful, wasm_component_model_async_stackful) ("threads", threads, wasm_threads) - ("shared-everything-threads", shared_everything_threads, wasm_shared_everything_threads) ("gc", gc, wasm_gc) ("gc", reference_types, wasm_reference_types) ("gc", function_references, wasm_function_references) From 04c70f8f0a46faffa69ddb763a905caeaa1dfd6e Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 10 Apr 2025 15:24:45 -0700 Subject: [PATCH 4/4] Add internal flags necessary for testing --- crates/fuzzing/src/generators/config.rs | 2 ++ crates/test-util/src/wasmtime_wast.rs | 3 +++ crates/test-util/src/wast.rs | 1 + crates/wasmtime/src/engine/serialization.rs | 11 +++++++++-- .../shared-everything-threads/flags.wast | 3 +++ 5 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/misc_testsuite/shared-everything-threads/flags.wast diff --git a/crates/fuzzing/src/generators/config.rs b/crates/fuzzing/src/generators/config.rs index a8fe0572d249..9da39c3a7455 100644 --- a/crates/fuzzing/src/generators/config.rs +++ b/crates/fuzzing/src/generators/config.rs @@ -131,6 +131,7 @@ impl Config { custom_page_sizes, multi_memory, threads, + shared_everything_threads, gc, function_references, relaxed_simd, @@ -173,6 +174,7 @@ impl Config { config.tail_call_enabled = tail_call.unwrap_or(false); config.custom_page_sizes_enabled = custom_page_sizes.unwrap_or(false); config.threads_enabled = threads.unwrap_or(false); + config.shared_everything_threads_enabled = shared_everything_threads.unwrap_or(false); config.gc_enabled = gc.unwrap_or(false); config.reference_types_enabled = config.gc_enabled || self.module_config.function_references_enabled diff --git a/crates/test-util/src/wasmtime_wast.rs b/crates/test-util/src/wasmtime_wast.rs index d4bafab12f69..7bb14ee8cada 100644 --- a/crates/test-util/src/wasmtime_wast.rs +++ b/crates/test-util/src/wasmtime_wast.rs @@ -29,6 +29,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) { custom_page_sizes, multi_memory, threads, + shared_everything_threads, gc, function_references, relaxed_simd, @@ -54,6 +55,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) { let custom_page_sizes = custom_page_sizes.unwrap_or(false); let multi_memory = multi_memory.unwrap_or(false); let threads = threads.unwrap_or(false); + let shared_everything_threads = shared_everything_threads.unwrap_or(false); let gc = gc.unwrap_or(false); let tail_call = tail_call.unwrap_or(false); let extended_const = extended_const.unwrap_or(false); @@ -78,6 +80,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) { config .wasm_multi_memory(multi_memory) .wasm_threads(threads) + .wasm_shared_everything_threads(shared_everything_threads) .wasm_memory64(memory64) .wasm_function_references(function_references) .wasm_gc(gc) diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rs index 856385030c00..8bfdec93a800 100644 --- a/crates/test-util/src/wast.rs +++ b/crates/test-util/src/wast.rs @@ -230,6 +230,7 @@ macro_rules! foreach_config_option { custom_page_sizes multi_memory threads + shared_everything_threads gc function_references relaxed_simd diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rs index 928f0b8b6008..e0089935514e 100644 --- a/crates/wasmtime/src/engine/serialization.rs +++ b/crates/wasmtime/src/engine/serialization.rs @@ -192,6 +192,7 @@ struct WasmFeatures { simd: bool, tail_call: bool, threads: bool, + shared_everything_threads: bool, multi_memory: bool, exceptions: bool, legacy_exceptions: bool, @@ -219,6 +220,7 @@ impl Metadata<'_> { component_model, simd, threads, + shared_everything_threads, tail_call, multi_memory, exceptions, @@ -229,7 +231,6 @@ impl Metadata<'_> { function_references, gc, custom_page_sizes, - shared_everything_threads, cm_async, cm_async_builtins, cm_async_stackful, @@ -253,7 +254,6 @@ impl Metadata<'_> { assert!(!memory_control); assert!(!cm_nested_names); assert!(!cm_values); - assert!(!shared_everything_threads); Metadata { target: engine.compiler().triple().to_string(), @@ -267,6 +267,7 @@ impl Metadata<'_> { component_model, simd, threads, + shared_everything_threads, tail_call, multi_memory, exceptions, @@ -481,6 +482,7 @@ impl Metadata<'_> { simd, tail_call, threads, + shared_everything_threads, multi_memory, exceptions, legacy_exceptions, @@ -540,6 +542,11 @@ impl Metadata<'_> { other.contains(F::THREADS), "WebAssembly threads support", )?; + Self::check_bool( + shared_everything_threads, + other.contains(F::SHARED_EVERYTHING_THREADS), + "WebAssembly shared-everything-threads support", + )?; Self::check_bool( multi_memory, other.contains(F::MULTI_MEMORY), diff --git a/tests/misc_testsuite/shared-everything-threads/flags.wast b/tests/misc_testsuite/shared-everything-threads/flags.wast new file mode 100644 index 000000000000..6e580f128f07 --- /dev/null +++ b/tests/misc_testsuite/shared-everything-threads/flags.wast @@ -0,0 +1,3 @@ +;;! shared_everything_threads = true + +(module)