Skip to content

threads: add feature flags #10206

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

Merged
merged 4 commits into from
Apr 11, 2025
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
2 changes: 2 additions & 0 deletions crates/fuzzing/src/generators/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl Config {
custom_page_sizes,
multi_memory,
threads,
shared_everything_threads,
gc,
function_references,
relaxed_simd,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions crates/test-util/src/wasmtime_wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions crates/test-util/src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ macro_rules! foreach_config_option {
custom_page_sizes
multi_memory
threads
shared_everything_threads
gc
function_references
relaxed_simd
Expand Down
15 changes: 15 additions & 0 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
11 changes: 9 additions & 2 deletions crates/wasmtime/src/engine/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -219,6 +220,7 @@ impl Metadata<'_> {
component_model,
simd,
threads,
shared_everything_threads,
tail_call,
multi_memory,
exceptions,
Expand All @@ -229,7 +231,6 @@ impl Metadata<'_> {
function_references,
gc,
custom_page_sizes,
shared_everything_threads,
cm_async,
cm_async_builtins,
cm_async_stackful,
Expand All @@ -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(),
Expand All @@ -267,6 +267,7 @@ impl Metadata<'_> {
component_model,
simd,
threads,
shared_everything_threads,
tail_call,
multi_memory,
exceptions,
Expand Down Expand Up @@ -481,6 +482,7 @@ impl Metadata<'_> {
simd,
tail_call,
threads,
shared_everything_threads,
multi_memory,
exceptions,
legacy_exceptions,
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions tests/misc_testsuite/shared-everything-threads/flags.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
;;! shared_everything_threads = true

(module)