Skip to content

cranelift: flush buffered startup fuel before static data segment branch - #14645

Open
ctiller wants to merge 1 commit into
bytecodealliance:mainfrom
ctiller:fix/startup-static-memory-fuel
Open

ctiller wants to merge 1 commit into
bytecodealliance:mainfrom
ctiller:fix/startup-static-memory-fuel

Conversation

@ctiller

@ctiller ctiller commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

During FuncTranslator::translate_module_startup, fuel costs from earlier startup instructions (such as global.init constant expressions) are buffered in self.fuel_consumed until flushed into the SSA self.fuel_var.

In FuncEnvironment::translate_static_memory_init, the copy-on-write check branches directly to end_block (brif(is_null, end_block, init_block)), while self.fuel_consumed was only flushed inside init_block via fuel_consume_for_bulk_op. When the CoW fast path was taken (is_null != 0), init_block was skipped and the buffered compile-time startup fuel was lost.

Call self.fuel_increment_var(builder) before brif(is_null, end_block, init_block) when consume_fuel is enabled so both arms of the branch see the prior startup fuel.

Assisted-by: Gemini

During `FuncTranslator::translate_module_startup`, fuel costs from earlier
startup instructions (such as `global.init` constant expressions) are buffered
in `self.fuel_consumed` until flushed into the SSA `self.fuel_var`.

In `FuncEnvironment::translate_static_memory_init`, the copy-on-write check
branches directly to `end_block` (`brif(is_null, end_block, init_block)`),
while `self.fuel_consumed` was only flushed inside `init_block` via
`fuel_consume_for_bulk_op`. When the CoW fast path was taken (`is_null != 0`),
`init_block` was skipped and the buffered compile-time startup fuel was lost.

Call `self.fuel_increment_var(builder)` before `brif(is_null, end_block,
init_block)` when `consume_fuel` is enabled so both arms of the branch see the
prior startup fuel.

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

@alexcrichton alexcrichton 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!

@alexcrichton
alexcrichton added this pull request to the merge queue Oct 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks 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