Skip to content
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
7 changes: 6 additions & 1 deletion crates/fuzzing/src/generators/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,13 @@ impl WasmtimeConfig {
config.reference_types_enabled = false;
config.wide_arithmetic_enabled = false;

// Winch requires host trap handlers to be enabled at this time.
// Tuning the following engine options is currently not supported
// by Winch.
self.signals_based_traps = true;
self.table_lazy_init = true;
self.epoch_interruption = false;
self.consume_fuel = false;
self.debug_info = false;
}

// If using the pooling allocator, constrain the memory and module configurations
Expand Down
17 changes: 9 additions & 8 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ impl Config {
/// guest WebAssembly programs.
///
/// By default this option is `false`.
/// **Note** Enabling this option is not compatible with the Winch compiler.
pub fn debug_info(&mut self, enable: bool) -> &mut Self {
self.tunables.generate_native_debuginfo = Some(enable);
self
Expand Down Expand Up @@ -515,6 +516,8 @@ impl Config {
///
/// By default this option is `false`.
///
/// **Note** Enabling this option is not compatible with the Winch compiler.
///
/// [`Store`]: crate::Store
pub fn consume_fuel(&mut self, enable: bool) -> &mut Self {
self.tunables.consume_fuel = Some(enable);
Expand Down Expand Up @@ -621,6 +624,8 @@ impl Config {
/// deterministically, then fuel with a fixed bound should be
/// used.
///
/// **Note** Enabling this option is not compatible with the Winch compiler.
///
/// # See Also
///
/// - [`Engine::increment_epoch`](crate::Engine::increment_epoch)
Expand Down Expand Up @@ -1559,6 +1564,8 @@ impl Config {
/// are initialized eagerly during instantiation from any active element
/// segments that apply to them.
///
/// **Note** Disabling this option is not compatible with the Winch compiler.
///
/// ## Default
///
/// This value defaults to `true`.
Expand Down Expand Up @@ -1970,14 +1977,6 @@ impl Config {
#[cfg(any(feature = "cranelift", feature = "winch"))]
{
tunables.winch_callable = self.compiler_config.strategy == Some(Strategy::Winch);

if tunables.winch_callable && !tunables.table_lazy_init {
bail!("Winch requires the table-lazy-init configuration option");
}

if tunables.winch_callable && !tunables.signals_based_traps {
bail!("Winch requires signals-based traps to be enabled");
}
}

if tunables.static_memory_offset_guard_size < tunables.dynamic_memory_offset_guard_size {
Expand Down Expand Up @@ -2280,6 +2279,8 @@ impl Config {
///
/// This option defaults to `true` meaning that signals-based trap handlers
/// are enabled by default.
///
/// **Note** Disabling this option is not compatible with the Winch compiler.
pub fn signals_based_traps(&mut self, enable: bool) -> &mut Self {
self.tunables.signals_based_traps = Some(enable);
self
Expand Down
25 changes: 24 additions & 1 deletion crates/winch/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,30 @@ impl CompilerBuilder for Builder {
}

fn set_tunables(&mut self, tunables: Tunables) -> Result<()> {
assert!(tunables.winch_callable);
if !tunables.winch_callable {
bail!("Winch requires the winch calling convention");
}

if !tunables.table_lazy_init {
bail!("Winch requires the table-lazy-init option to be enabled");
}

if !tunables.signals_based_traps {
bail!("Winch requires the signals-based-traps option to be enabled");
}

if tunables.epoch_interruption {
bail!("Winch does not currently support epoch based interruption");
}

if tunables.consume_fuel {
bail!("Winch does not currently support fuel based interruption");
}

if tunables.generate_native_debuginfo {
bail!("Winch does not currently support generating native debug information");
}

self.tunables = Some(tunables.clone());
self.cranelift.set_tunables(tunables)?;
Ok(())
Expand Down
19 changes: 19 additions & 0 deletions tests/all/epoch_interruption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anyhow::anyhow;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use wasmtime::*;
use wasmtime_test_macros::wasmtime_test;

fn build_engine() -> Arc<Engine> {
let mut config = Config::new();
Expand Down Expand Up @@ -448,3 +449,21 @@ async fn drop_future_on_epoch_yield() {

assert_eq!(true, alive_flag.load(Ordering::Acquire));
}

#[wasmtime_test(strategies(not(Cranelift)))]
#[cfg_attr(miri, ignore)]
fn ensure_compatibility_between_winch_and_epoch(config: &mut Config) -> Result<()> {
config.epoch_interruption(true);
let result = Engine::new(&config);
match result {
Ok(_) => anyhow::bail!("Expected incompatibility between epoch interruption and Winch"),
Err(e) => {
assert_eq!(
e.to_string(),
"Winch does not currently support epoch based interruption"
);
}
}

Ok(())
}
19 changes: 19 additions & 0 deletions tests/all/fuel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use wasmtime::*;
use wasmtime_test_macros::wasmtime_test;
use wast::parser::{self, Parse, ParseBuffer, Parser};
use wast::token::Span;

Expand Down Expand Up @@ -256,3 +257,21 @@ fn get_fuel_clamps_at_zero() -> Result<()> {

Ok(())
}

#[wasmtime_test(strategies(not(Cranelift)))]
#[cfg_attr(miri, ignore)]
fn ensure_compatibility_between_winch_and_fuel(config: &mut Config) -> Result<()> {
config.consume_fuel(true);
let result = Engine::new(&config);
match result {
Ok(_) => anyhow::bail!("Expected incompatibility between fuel and Winch"),
Err(e) => {
assert_eq!(
e.to_string(),
"Winch does not currently support fuel based interruption"
);
}
}

Ok(())
}
1 change: 1 addition & 0 deletions tests/all/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod traps;
mod types;
mod wait_notify;
mod wasi_testsuite;
mod winch_engine_features;

/// A helper to compile a module in a new store with reference types enabled.
pub(crate) fn ref_types_module(
Expand Down
68 changes: 68 additions & 0 deletions tests/all/winch_engine_features.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use wasmtime::*;
use wasmtime_test_macros::wasmtime_test;

#[wasmtime_test(strategies(not(Cranelift)))]
#[cfg_attr(miri, ignore)]
fn ensure_compatibility_between_winch_and_table_lazy_init(config: &mut Config) -> Result<()> {
config.table_lazy_init(false);
let result = Engine::new(&config);
match result {
Ok(_) => {
anyhow::bail!("Expected incompatibility between the `table_lazy_init` option and Winch")
}
Err(e) => {
assert_eq!(
e.to_string(),
"Winch requires the table-lazy-init option to be enabled"
);
}
}

Ok(())
}

#[wasmtime_test(strategies(not(Cranelift)))]
#[cfg_attr(miri, ignore)]
fn ensure_compatibility_between_winch_and_signals_based_traps(config: &mut Config) -> Result<()> {
config.signals_based_traps(false);
let result = Engine::new(&config);
match result {
Ok(_) => {
anyhow::bail!(
"Expected incompatibility between the `signals_based_traps` option and Winch"
)
}
Err(e) => {
assert_eq!(
e.to_string(),
"Winch requires the signals-based-traps option to be enabled"
);
}
}

Ok(())
}

#[wasmtime_test(strategies(not(Cranelift)))]
#[cfg_attr(miri, ignore)]
fn ensure_compatibility_between_winch_and_generate_native_debuginfo(
config: &mut Config,
) -> Result<()> {
config.debug_info(true);
let result = Engine::new(&config);
match result {
Ok(_) => {
anyhow::bail!(
"Expected incompatibility between the `generate_native_debuginfo` option and Winch"
)
}
Err(e) => {
assert_eq!(
e.to_string(),
"Winch does not currently support generating native debug information"
);
}
}

Ok(())
}