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
4 changes: 0 additions & 4 deletions crates/winch/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ impl CompilerBuilder for Builder {
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");
}
Expand Down
1 change: 1 addition & 0 deletions crates/winch/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl wasmtime_environ::Compiler for Compiler {
types,
&mut context.builtins,
&mut validator,
&self.tunables,
)
.map_err(|e| CompileError::Codegen(format!("{e:?}")));
self.save_context(context, validator.into_allocations());
Expand Down
71 changes: 27 additions & 44 deletions tests/all/fuel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ impl<'a> Parse<'a> for FuelWast<'a> {
}
}

#[test]
#[wasmtime_test]
#[cfg_attr(miri, ignore)]
fn run() -> Result<()> {
fn run(config: &mut Config) -> Result<()> {
config.consume_fuel(true);
let test = std::fs::read_to_string("tests/all/fuel.wast")?;
let buf = ParseBuffer::new(&test)?;
let mut wast = parser::parse::<FuelWast<'_>>(&buf)?;
for (span, fuel, module) in wast.assertions.iter_mut() {
let consumed = fuel_consumed(&module.encode()?);
let consumed = fuel_consumed(&config, &module.encode()?);
if consumed == *fuel {
continue;
}
Expand All @@ -47,9 +48,7 @@ fn run() -> Result<()> {
Ok(())
}

fn fuel_consumed(wasm: &[u8]) -> u64 {
let mut config = Config::new();
config.consume_fuel(true);
fn fuel_consumed(config: &Config, wasm: &[u8]) -> u64 {
let engine = Engine::new(&config).unwrap();
let module = Module::new(&engine, wasm).unwrap();
let mut store = Store::new(&engine, ());
Expand All @@ -58,10 +57,12 @@ fn fuel_consumed(wasm: &[u8]) -> u64 {
u64::MAX - store.get_fuel().unwrap()
}

#[test]
#[wasmtime_test]
#[cfg_attr(miri, ignore)]
fn iloop() {
fn iloop(config: &mut Config) -> Result<()> {
config.consume_fuel(true);
iloop_aborts(
&config,
r#"
(module
(start 0)
Expand All @@ -70,6 +71,7 @@ fn iloop() {
"#,
);
iloop_aborts(
&config,
r#"
(module
(start 0)
Expand All @@ -78,6 +80,7 @@ fn iloop() {
"#,
);
iloop_aborts(
&config,
r#"
(module
(start 0)
Expand All @@ -86,6 +89,7 @@ fn iloop() {
"#,
);
iloop_aborts(
&config,
r#"
(module
(start 0)
Expand All @@ -110,21 +114,20 @@ fn iloop() {
"#,
);

fn iloop_aborts(wat: &str) {
let mut config = Config::new();
config.consume_fuel(true);
fn iloop_aborts(config: &Config, wat: &str) {
let engine = Engine::new(&config).unwrap();
let module = Module::new(&engine, wat).unwrap();
let mut store = Store::new(&engine, ());
store.set_fuel(10_000).unwrap();
let error = Instance::new(&mut store, &module, &[]).err().unwrap();
assert_eq!(error.downcast::<Trap>().unwrap(), Trap::OutOfFuel);
}

Ok(())
}

#[test]
fn manual_fuel() {
let mut config = Config::new();
#[wasmtime_test]
fn manual_fuel(config: &mut Config) {
config.consume_fuel(true);
let engine = Engine::new(&config).unwrap();
let mut store = Store::new(&engine, ());
Expand All @@ -134,11 +137,10 @@ fn manual_fuel() {
assert_eq!(store.get_fuel().ok(), Some(1));
}

#[test]
#[wasmtime_test]
#[cfg_attr(miri, ignore)]
fn host_function_consumes_all() {
fn host_function_consumes_all(config: &mut Config) {
const FUEL: u64 = 10_000;
let mut config = Config::new();
config.consume_fuel(true);
let engine = Engine::new(&config).unwrap();
let module = Module::new(
Expand Down Expand Up @@ -167,20 +169,18 @@ fn host_function_consumes_all() {
assert_eq!(trap.downcast::<Trap>().unwrap(), Trap::OutOfFuel);
}

#[test]
fn manual_edge_cases() {
let mut config = Config::new();
#[wasmtime_test]
fn manual_edge_cases(config: &mut Config) {
config.consume_fuel(true);
let engine = Engine::new(&config).unwrap();
let mut store = Store::new(&engine, ());
store.set_fuel(u64::MAX).unwrap();
assert_eq!(store.get_fuel().unwrap(), u64::MAX);
}

#[test]
#[wasmtime_test]
#[cfg_attr(miri, ignore)]
fn unconditionally_trapping_memory_accesses_save_fuel_before_trapping() {
let mut config = Config::new();
fn unconditionally_trapping_memory_accesses_save_fuel_before_trapping(config: &mut Config) {
config.consume_fuel(true);
config.static_memory_maximum_size(0x1_0000);

Expand Down Expand Up @@ -221,10 +221,11 @@ fn unconditionally_trapping_memory_accesses_save_fuel_before_trapping() {
assert!(consumed_fuel > 0);
}

#[test]
#[wasmtime_test]
#[cfg_attr(miri, ignore)]
fn get_fuel_clamps_at_zero() -> Result<()> {
let engine = Engine::new(Config::new().consume_fuel(true))?;
fn get_fuel_clamps_at_zero(config: &mut Config) -> Result<()> {
config.consume_fuel(true);
let engine = Engine::new(config)?;
let mut store = Store::new(&engine, ());
let module = Module::new(
&engine,
Expand Down Expand Up @@ -257,21 +258,3 @@ 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(())
}
2 changes: 1 addition & 1 deletion winch/codegen/src/codegen/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub enum HeapStyle {
#[derive(Debug, Copy, Clone)]
pub struct HeapData {
/// The offset to the base of the heap.
/// Relative to the VMContext pointer if the WebAssembly memory is locally
/// Relative to the `VMContext` pointer if the WebAssembly memory is locally
/// defined. Else this is relative to the location of the imported WebAssembly
/// memory location.
pub offset: u32,
Expand Down
Loading