1 use crate::wast;
2 use wasmtime::Config;
3 
4 /// Helper method to apply `wast_config` to `config`.
apply_wast_config(config: &mut Config, wast_config: &wast::WastConfig)5 pub fn apply_wast_config(config: &mut Config, wast_config: &wast::WastConfig) {
6     use wasmtime_environ::TripleExt;
7     use wast::{Collector, Compiler};
8 
9     config.strategy(match wast_config.compiler {
10         Compiler::CraneliftNative | Compiler::CraneliftPulley => wasmtime::Strategy::Cranelift,
11         Compiler::Winch => wasmtime::Strategy::Winch,
12     });
13     if let Compiler::CraneliftPulley = wast_config.compiler {
14         config
15             .target(&target_lexicon::Triple::pulley_host().to_string())
16             .unwrap();
17     }
18     config.collector(match wast_config.collector {
19         Collector::Auto => wasmtime::Collector::Auto,
20         Collector::Null => wasmtime::Collector::Null,
21         Collector::DeferredReferenceCounting => wasmtime::Collector::DeferredReferenceCounting,
22     });
23 }
24 
25 /// Helper method to apply `test_config` to `config`.
apply_test_config(config: &mut Config, test_config: &wast::TestConfig)26 pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
27     let wast::TestConfig {
28         bulk_memory,
29         memory64,
30         custom_page_sizes,
31         multi_memory,
32         threads,
33         shared_everything_threads,
34         gc,
35         function_references,
36         relaxed_simd,
37         reference_types,
38         tail_call,
39         extended_const,
40         wide_arithmetic,
41         component_model_async,
42         component_model_async_builtins,
43         component_model_async_stackful,
44         component_model_threading,
45         component_model_error_context,
46         component_model_gc,
47         component_model_map,
48         component_model_fixed_length_lists,
49         nan_canonicalization,
50         simd,
51         exceptions,
52         legacy_exceptions,
53         stack_switching,
54         custom_descriptors,
55 
56         hogs_memory: _,
57         gc_types: _,
58         spec_test: _,
59     } = *test_config;
60     // Note that all of these proposals/features are currently default-off to
61     // ensure that we annotate all tests accurately with what features they
62     // need, even in the future when features are stabilized.
63     let bulk_memory = bulk_memory.unwrap_or(false);
64     let memory64 = memory64.unwrap_or(false);
65     let custom_page_sizes = custom_page_sizes.unwrap_or(false);
66     let multi_memory = multi_memory.unwrap_or(false);
67     let threads = threads.unwrap_or(false);
68     let shared_everything_threads = shared_everything_threads.unwrap_or(false);
69     let gc = gc.unwrap_or(false);
70     let tail_call = tail_call.unwrap_or(false);
71     let extended_const = extended_const.unwrap_or(false);
72     let wide_arithmetic = wide_arithmetic.unwrap_or(false);
73     let component_model_async = component_model_async.unwrap_or(false);
74     let component_model_async_builtins = component_model_async_builtins.unwrap_or(false);
75     let component_model_async_stackful = component_model_async_stackful.unwrap_or(false);
76     let component_model_threading = component_model_threading.unwrap_or(false);
77     let component_model_error_context = component_model_error_context.unwrap_or(false);
78     let component_model_gc = component_model_gc.unwrap_or(false);
79     let component_model_map = component_model_map.unwrap_or(false);
80     let component_model_fixed_length_lists = component_model_fixed_length_lists.unwrap_or(false);
81     let nan_canonicalization = nan_canonicalization.unwrap_or(false);
82     let relaxed_simd = relaxed_simd.unwrap_or(false);
83     let legacy_exceptions = legacy_exceptions.unwrap_or(false);
84     let stack_switching = stack_switching.unwrap_or(false);
85 
86     // Some proposals in wasm depend on previous proposals. For example the gc
87     // proposal depends on function-references which depends on reference-types.
88     // To avoid needing to enable all of them at once implicitly enable
89     // downstream proposals once the end proposal is enabled (e.g. when enabling
90     // gc that also enables function-references and reference-types).
91     let function_references = gc || function_references.unwrap_or(false);
92     let reference_types = function_references || reference_types.unwrap_or(false);
93     let simd = relaxed_simd || simd.unwrap_or(false);
94 
95     let exceptions = stack_switching || exceptions.unwrap_or(false);
96 
97     // Not implemented in Wasmtime yet.
98     let _custom_descriptors = custom_descriptors.unwrap_or(false);
99 
100     config
101         .wasm_bulk_memory(bulk_memory)
102         .wasm_multi_memory(multi_memory)
103         .wasm_threads(threads)
104         .wasm_shared_everything_threads(shared_everything_threads)
105         .wasm_memory64(memory64)
106         .wasm_function_references(function_references)
107         .wasm_gc(gc)
108         .wasm_reference_types(reference_types)
109         .wasm_relaxed_simd(relaxed_simd)
110         .wasm_simd(simd)
111         .wasm_tail_call(tail_call)
112         .wasm_custom_page_sizes(custom_page_sizes)
113         .wasm_extended_const(extended_const)
114         .wasm_wide_arithmetic(wide_arithmetic)
115         .wasm_component_model_async(component_model_async)
116         .wasm_component_model_async_builtins(component_model_async_builtins)
117         .wasm_component_model_async_stackful(component_model_async_stackful)
118         .wasm_component_model_threading(component_model_threading)
119         .wasm_component_model_error_context(component_model_error_context)
120         .wasm_component_model_gc(component_model_gc)
121         .wasm_component_model_map(component_model_map)
122         .wasm_component_model_fixed_length_lists(component_model_fixed_length_lists)
123         .wasm_exceptions(exceptions)
124         .wasm_stack_switching(stack_switching)
125         .cranelift_nan_canonicalization(nan_canonicalization);
126     #[expect(deprecated, reason = "forwarding legacy-exceptions")]
127     config.wasm_legacy_exceptions(legacy_exceptions);
128 }
129