Skip to content

cranelift: save and reload fuel around new_epoch libcall - #14647

Queued
ctiller wants to merge 1 commit into
bytecodealliance:mainfrom
ctiller:fix/epoch-check-fuel
Queued

ctiller wants to merge 1 commit into
bytecodealliance:mainfrom
ctiller:fix/epoch-check-fuel

Conversation

@ctiller

@ctiller ctiller commented Oct 9, 2026

Copy link
Copy Markdown

When both consume_fuel and epoch_interruption are enabled, FuncEnvironment::epoch_check_full emits a conditional call to the new_epoch libcall at function entry and loop headers. Although fuel_check flushes buffered fuel into the SSA variable self.fuel_var immediately beforehand, epoch_check_full did not store self.fuel_var back to VMStoreContext::fuel_consumed before invoking new_epoch or reload it afterwards.

Consequently, if the epoch deadline callback inspected store.get_fuel() or trapped (UpdateDeadline::Interrupt / Err(...)), all fuel consumed since the last store synchronization was missing from the Store.

Save self.fuel_var before calling new_epoch and reload self.fuel_var afterwards when consume_fuel is enabled.

Assisted-by: Gemini

When both `consume_fuel` and `epoch_interruption` are enabled,
`FuncEnvironment::epoch_check_full` emits a conditional call to the `new_epoch`
libcall at function entry and loop headers. Although `fuel_check` flushes
buffered fuel into the SSA variable `self.fuel_var` immediately beforehand,
`epoch_check_full` did not store `self.fuel_var` back to
`VMStoreContext::fuel_consumed` before invoking `new_epoch` or reload it
afterwards.

Consequently, if the epoch deadline callback inspected `store.get_fuel()` or
trapped (`UpdateDeadline::Interrupt` / `Err(...)`), all fuel consumed since the
last store synchronization was missing from the `Store`.

Save `self.fuel_var` before calling `new_epoch` and reload `self.fuel_var`
afterwards when `consume_fuel` is enabled.

Assisted-by: Gemini
@ctiller
ctiller requested review from a team as code owners October 9, 2026 23:47
@ctiller
ctiller requested review from cfallin and removed request for a team October 9, 2026 23:47

@cfallin cfallin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@cfallin
cfallin added this pull request to the merge queue Oct 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants