From 6428717df5a2ecf5f9e0aca4609d635af012d9be Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 30 Jun 2021 15:00:06 -0700 Subject: [PATCH 1/2] Change the injection count of fuel in a store from u32 to u64 This commit updates the type of the amount of times to inject fuel in the `out_of_fuel_async_yield` to `u64` instead of `u32`. This should allow effectively infinite fuel to get injected, even if a small amount of fuel is injected per iteration. Closes #2927 Closes #3046 --- crates/wasmtime/src/func.rs | 2 +- crates/wasmtime/src/store.rs | 8 ++++---- tests/all/async_functions.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/wasmtime/src/func.rs b/crates/wasmtime/src/func.rs index 0698e386103b..95853da838ec 100644 --- a/crates/wasmtime/src/func.rs +++ b/crates/wasmtime/src/func.rs @@ -1606,7 +1606,7 @@ impl Caller<'_, T> { /// /// For more information see /// [`Store::out_of_fuel_async_yield`](crate::Store::out_of_fuel_async_yield) - pub fn out_of_fuel_async_yield(&mut self, injection_count: u32, fuel_to_inject: u64) { + pub fn out_of_fuel_async_yield(&mut self, injection_count: u64, fuel_to_inject: u64) { self.store .out_of_fuel_async_yield(injection_count, fuel_to_inject) } diff --git a/crates/wasmtime/src/store.rs b/crates/wasmtime/src/store.rs index d81d479995a3..b76493290956 100644 --- a/crates/wasmtime/src/store.rs +++ b/crates/wasmtime/src/store.rs @@ -178,7 +178,7 @@ struct StoreInstance { enum OutOfGas { Trap, InjectFuel { - injection_count: u32, + injection_count: u64, fuel_to_inject: u64, }, } @@ -558,7 +558,7 @@ impl Store { /// /// This method will panic if it is not called on a store associated with an [async /// config](crate::Config::async_support). - pub fn out_of_fuel_async_yield(&mut self, injection_count: u32, fuel_to_inject: u64) { + pub fn out_of_fuel_async_yield(&mut self, injection_count: u64, fuel_to_inject: u64) { self.inner .out_of_fuel_async_yield(injection_count, fuel_to_inject) } @@ -655,7 +655,7 @@ impl<'a, T> StoreContextMut<'a, T> { /// runs out. /// /// For more information see [`Store::out_of_fuel_async_yield`] - pub fn out_of_fuel_async_yield(&mut self, injection_count: u32, fuel_to_inject: u64) { + pub fn out_of_fuel_async_yield(&mut self, injection_count: u64, fuel_to_inject: u64) { self.0 .out_of_fuel_async_yield(injection_count, fuel_to_inject) } @@ -838,7 +838,7 @@ impl StoreInnermost { self.out_of_gas_behavior = OutOfGas::Trap; } - fn out_of_fuel_async_yield(&mut self, injection_count: u32, fuel_to_inject: u64) { + fn out_of_fuel_async_yield(&mut self, injection_count: u64, fuel_to_inject: u64) { assert!( self.async_support(), "cannot use `out_of_fuel_async_yield` without enabling async support in the config" diff --git a/tests/all/async_functions.rs b/tests/all/async_functions.rs index f81f08812fb9..e6a151bd74ee 100644 --- a/tests/all/async_functions.rs +++ b/tests/all/async_functions.rs @@ -392,7 +392,7 @@ fn iloop_with_fuel() { fn fuel_eventually_finishes() { let engine = Engine::new(Config::new().async_support(true).consume_fuel(true)).unwrap(); let mut store = Store::new(&engine, ()); - store.out_of_fuel_async_yield(u32::max_value(), 10); + store.out_of_fuel_async_yield(u64::max_value(), 10); let module = Module::new( &engine, " From 2696bcad25b45e16e761f7a9dc5220b765a4852d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 1 Jul 2021 07:31:23 -0700 Subject: [PATCH 2/2] Fix tokio example --- examples/tokio/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tokio/main.rs b/examples/tokio/main.rs index 3b28f55e7a83..f26e7beae1d2 100644 --- a/examples/tokio/main.rs +++ b/examples/tokio/main.rs @@ -95,8 +95,8 @@ async fn run_wasm(inputs: Inputs) -> Result<(), Error> { let mut store = Store::new(&inputs.env.engine, wasi); // WebAssembly execution will be paused for an async yield every time it - // consumes 10000 fuel. Fuel will be refilled u32::MAX times. - store.out_of_fuel_async_yield(u32::MAX, 10000); + // consumes 10000 fuel. Fuel will be refilled u64::MAX times. + store.out_of_fuel_async_yield(u64::MAX, 10000); // Instantiate into our own unique store using the shared linker, afterwards // acquiring the `_start` function for the module and executing it.