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

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

Copy link
Copy Markdown
Member

@ctiller would you be up for resolving CI and rebasing here too?

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 force-pushed the fix/startup-static-memory-fuel branch from c4521b1 to f552cfa Compare October 15, 2026 16:43
@cfallin
cfallin added this pull request to the merge queue Oct 15, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 15, 2026
@cfallin

cfallin commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

@ctiller it looks like this is yet again a merge conflict as one of your other PRs merged first -- could you resolve again?

(In the future if submitting a cluster of PRs that will mutually conflict, we're happy to take a slightly larger single PR with everything pre-merged, if that's easier -- it certainly reduces this kind of churn for us!)

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @ctiller for your contribution to this repository, but
this automated bot is closing this PR.

Bytecode Alliance projects have been overwhelmed with AI-generated
PRs that monopolize reviewer time, and this bot is an attempt to
push back. Please discuss this change on [zulip] with maintainers
first before jumping straight into making a PR. After discussion,
a maintainer may reopen this PR.

AI usage must abide by the Bytecode Alliance's AI Tool Use
Policy
,
and we ask that new contributors engage with maintainers
beforehand as humans to ensure that what you're working on is
reasonable for a newcomer to tackle. For more information, see
the contributing
docs
.

If you believe this PR was caught by this bot erroneously, reach
out to us on [zulip].

@github-actions github-actions Bot closed this Nov 20, 2026
@alexcrichton alexcrichton reopened this Nov 20, 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.

3 participants