Skip to content

Commit b9985fe

Browse files
authored
Change the injection count of fuel in a store from u32 to u64 (bytecodealliance#3048)
* 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 bytecodealliance#2927 Closes bytecodealliance#3046 * Fix tokio example
1 parent 7453bd5 commit b9985fe

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

crates/wasmtime/src/func.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ impl<T> Caller<'_, T> {
16061606
///
16071607
/// For more information see
16081608
/// [`Store::out_of_fuel_async_yield`](crate::Store::out_of_fuel_async_yield)
1609-
pub fn out_of_fuel_async_yield(&mut self, injection_count: u32, fuel_to_inject: u64) {
1609+
pub fn out_of_fuel_async_yield(&mut self, injection_count: u64, fuel_to_inject: u64) {
16101610
self.store
16111611
.out_of_fuel_async_yield(injection_count, fuel_to_inject)
16121612
}

crates/wasmtime/src/store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ struct StoreInstance {
178178
enum OutOfGas {
179179
Trap,
180180
InjectFuel {
181-
injection_count: u32,
181+
injection_count: u64,
182182
fuel_to_inject: u64,
183183
},
184184
}
@@ -558,7 +558,7 @@ impl<T> Store<T> {
558558
///
559559
/// This method will panic if it is not called on a store associated with an [async
560560
/// config](crate::Config::async_support).
561-
pub fn out_of_fuel_async_yield(&mut self, injection_count: u32, fuel_to_inject: u64) {
561+
pub fn out_of_fuel_async_yield(&mut self, injection_count: u64, fuel_to_inject: u64) {
562562
self.inner
563563
.out_of_fuel_async_yield(injection_count, fuel_to_inject)
564564
}
@@ -655,7 +655,7 @@ impl<'a, T> StoreContextMut<'a, T> {
655655
/// runs out.
656656
///
657657
/// For more information see [`Store::out_of_fuel_async_yield`]
658-
pub fn out_of_fuel_async_yield(&mut self, injection_count: u32, fuel_to_inject: u64) {
658+
pub fn out_of_fuel_async_yield(&mut self, injection_count: u64, fuel_to_inject: u64) {
659659
self.0
660660
.out_of_fuel_async_yield(injection_count, fuel_to_inject)
661661
}
@@ -838,7 +838,7 @@ impl StoreInnermost {
838838
self.out_of_gas_behavior = OutOfGas::Trap;
839839
}
840840

841-
fn out_of_fuel_async_yield(&mut self, injection_count: u32, fuel_to_inject: u64) {
841+
fn out_of_fuel_async_yield(&mut self, injection_count: u64, fuel_to_inject: u64) {
842842
assert!(
843843
self.async_support(),
844844
"cannot use `out_of_fuel_async_yield` without enabling async support in the config"

examples/tokio/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ async fn run_wasm(inputs: Inputs) -> Result<(), Error> {
9595
let mut store = Store::new(&inputs.env.engine, wasi);
9696

9797
// WebAssembly execution will be paused for an async yield every time it
98-
// consumes 10000 fuel. Fuel will be refilled u32::MAX times.
99-
store.out_of_fuel_async_yield(u32::MAX, 10000);
98+
// consumes 10000 fuel. Fuel will be refilled u64::MAX times.
99+
store.out_of_fuel_async_yield(u64::MAX, 10000);
100100

101101
// Instantiate into our own unique store using the shared linker, afterwards
102102
// acquiring the `_start` function for the module and executing it.

tests/all/async_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ fn iloop_with_fuel() {
392392
fn fuel_eventually_finishes() {
393393
let engine = Engine::new(Config::new().async_support(true).consume_fuel(true)).unwrap();
394394
let mut store = Store::new(&engine, ());
395-
store.out_of_fuel_async_yield(u32::max_value(), 10);
395+
store.out_of_fuel_async_yield(u64::max_value(), 10);
396396
let module = Module::new(
397397
&engine,
398398
"

0 commit comments

Comments
 (0)