Skip to content

Commit bb12131

Browse files
authored
threads: add feature flags (#10206)
* threads: add feature flags This adds both the Cargo-level and CLI-level flags for the shared-everything-threads proposal. * 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. * 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. * Add internal flags necessary for testing
1 parent 26b433a commit bb12131

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

crates/fuzzing/src/generators/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl Config {
131131
custom_page_sizes,
132132
multi_memory,
133133
threads,
134+
shared_everything_threads,
134135
gc,
135136
function_references,
136137
relaxed_simd,
@@ -173,6 +174,7 @@ impl Config {
173174
config.tail_call_enabled = tail_call.unwrap_or(false);
174175
config.custom_page_sizes_enabled = custom_page_sizes.unwrap_or(false);
175176
config.threads_enabled = threads.unwrap_or(false);
177+
config.shared_everything_threads_enabled = shared_everything_threads.unwrap_or(false);
176178
config.gc_enabled = gc.unwrap_or(false);
177179
config.reference_types_enabled = config.gc_enabled
178180
|| self.module_config.function_references_enabled

crates/test-util/src/wasmtime_wast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
2929
custom_page_sizes,
3030
multi_memory,
3131
threads,
32+
shared_everything_threads,
3233
gc,
3334
function_references,
3435
relaxed_simd,
@@ -54,6 +55,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
5455
let custom_page_sizes = custom_page_sizes.unwrap_or(false);
5556
let multi_memory = multi_memory.unwrap_or(false);
5657
let threads = threads.unwrap_or(false);
58+
let shared_everything_threads = shared_everything_threads.unwrap_or(false);
5759
let gc = gc.unwrap_or(false);
5860
let tail_call = tail_call.unwrap_or(false);
5961
let extended_const = extended_const.unwrap_or(false);
@@ -78,6 +80,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
7880
config
7981
.wasm_multi_memory(multi_memory)
8082
.wasm_threads(threads)
83+
.wasm_shared_everything_threads(shared_everything_threads)
8184
.wasm_memory64(memory64)
8285
.wasm_function_references(function_references)
8386
.wasm_gc(gc)

crates/test-util/src/wast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ macro_rules! foreach_config_option {
230230
custom_page_sizes
231231
multi_memory
232232
threads
233+
shared_everything_threads
233234
gc
234235
function_references
235236
relaxed_simd

crates/wasmtime/src/config.rs

+15
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,21 @@ impl Config {
848848
self
849849
}
850850

851+
/// Configures whether the WebAssembly [shared-everything-threads] proposal
852+
/// will be enabled for compilation.
853+
///
854+
/// This feature gates extended use of the `shared` attribute on items other
855+
/// than memories, extra atomic instructions, and new component model
856+
/// intrinsics for spawning threads. It depends on the
857+
/// [`wasm_threads`][Self::wasm_threads] being enabled.
858+
///
859+
/// [shared-everything-threads]:
860+
/// https://github.com/webassembly/shared-everything-threads
861+
pub fn wasm_shared_everything_threads(&mut self, enable: bool) -> &mut Self {
862+
self.wasm_feature(WasmFeatures::SHARED_EVERYTHING_THREADS, enable);
863+
self
864+
}
865+
851866
/// Configures whether the [WebAssembly reference types proposal][proposal]
852867
/// will be enabled for compilation.
853868
///

crates/wasmtime/src/engine/serialization.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ struct WasmFeatures {
192192
simd: bool,
193193
tail_call: bool,
194194
threads: bool,
195+
shared_everything_threads: bool,
195196
multi_memory: bool,
196197
exceptions: bool,
197198
legacy_exceptions: bool,
@@ -219,6 +220,7 @@ impl Metadata<'_> {
219220
component_model,
220221
simd,
221222
threads,
223+
shared_everything_threads,
222224
tail_call,
223225
multi_memory,
224226
exceptions,
@@ -229,7 +231,6 @@ impl Metadata<'_> {
229231
function_references,
230232
gc,
231233
custom_page_sizes,
232-
shared_everything_threads,
233234
cm_async,
234235
cm_async_builtins,
235236
cm_async_stackful,
@@ -253,7 +254,6 @@ impl Metadata<'_> {
253254
assert!(!memory_control);
254255
assert!(!cm_nested_names);
255256
assert!(!cm_values);
256-
assert!(!shared_everything_threads);
257257

258258
Metadata {
259259
target: engine.compiler().triple().to_string(),
@@ -267,6 +267,7 @@ impl Metadata<'_> {
267267
component_model,
268268
simd,
269269
threads,
270+
shared_everything_threads,
270271
tail_call,
271272
multi_memory,
272273
exceptions,
@@ -481,6 +482,7 @@ impl Metadata<'_> {
481482
simd,
482483
tail_call,
483484
threads,
485+
shared_everything_threads,
484486
multi_memory,
485487
exceptions,
486488
legacy_exceptions,
@@ -540,6 +542,11 @@ impl Metadata<'_> {
540542
other.contains(F::THREADS),
541543
"WebAssembly threads support",
542544
)?;
545+
Self::check_bool(
546+
shared_everything_threads,
547+
other.contains(F::SHARED_EVERYTHING_THREADS),
548+
"WebAssembly shared-everything-threads support",
549+
)?;
543550
Self::check_bool(
544551
multi_memory,
545552
other.contains(F::MULTI_MEMORY),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
;;! shared_everything_threads = true
2+
3+
(module)

0 commit comments

Comments
 (0)