xia-chao opened PR #14391 from xia-chao:fix-fuel-buffer-flush-on-exit to bytecodealliance:main:
Instantiation-time fuel is dropped for modules with no start function.
A module with a multi-op const-expr global initializer reports 1 unit of fuel
consumed instead of 4. Adding an empty start function to the same module makes it
report the expected 6.Those charges accumulate in fuel_consumed. Wasm functions fold that buffer into
fuel_var through the trailing end operator, but the module startup function is
synthesized and has no end, and module_start, the other place that flushes the
buffer, is only emitted when start exists. So the buffer is dropped.fuel_function_exit now folds the buffer before saving. For functions translated
from wasm this is a no-op.<details>
<summary>Screenshots from a debugger session on main (5877086436)</summary>Breakpoint in
fuel_function_exit, wherefuel_consumedis 3 but onlyfuel_var
gets saved:
Breakpoint in
module_start, the only place that folds the buffer. The frame above
it isfunc_environ.rs:6015, themodule_startcall guarded by
if let Some(start_func):
Same module, same initializer:
fuel consumed = 1withoutstart,6with it.
</details>
Fixes #14203.
xia-chao requested wasmtime-compiler-reviewers for a review on PR #14391.
xia-chao requested fitzgen for a review on PR #14391.
xia-chao requested wasmtime-core-reviewers for a review on PR #14391.
fitzgen commented on PR #14391:
FYI: screenshots are not, in general, good for including in bug reports / PRs / issues, since they have worse accessibility for screen readers and tend to include lots of superfluous information for people to visually parse.
:memo: fitzgen submitted PR review:
Thanks! One thing below...
:speech_balloon: fitzgen created PR review comment:
Does this not emit an extra fuel increment? I think a better solution would be to make the synthesized start function update the fuel var before returning.
xia-chao updated PR #14391.
:memo: xia-chao submitted PR review.
:speech_balloon: xia-chao created PR review comment:
No, what I am currently doing is completely equivalent to what you are saying
But I still made the modifications according to what you said
xia-chao commented on PR #14391:
This is just a patch with limited content. You can review it directly. It should not be included here, but for some larger fixes, you cannot distinguish them just by looking at the code. Next time, I will only include them in larger fixes
I think it's very helpful, breakpoint screenshots are the highest level of bug evidence
It is normal to have visual interference, and all the evidence is indicated on the graph. Perhaps it will be helpful when you combine LLM review
xia-chao edited a comment on PR #14391:
This is just a small patch; the content is minimal, and you can easily review it directly. Admittedly, it probably shouldn't have been posted here—I usually reserve posts for more significant fixes where the changes aren't immediately obvious just by looking at the code. I'll only post about major fixes in the future.
I think it’s very helpful, though; a screenshot at the breakpoint serves as the ultimate evidence of the bug.
The visual clutter is to be expected, but all the evidence is right there in the image—it might prove useful when you're reviewing the code in conjunction with an LLM.
xia-chao edited a comment on PR #14391:
This is just a patch with minimal content—you could easily review it directly, and perhaps it shouldn't have been included here. However, for major fixes, the code alone often doesn't tell the whole story; I'll only include screenshots like this for significant fixes in the future.
I believe it’s very helpful; a screenshot of a breakpoint serves as the ultimate evidence of a bug.
It’s normal for there to be some visual clutter, as the image captures all the relevant evidence—it might prove useful when you're reviewing the code in conjunction with an LLM.
xia-chao requested fitzgen for a review on PR #14391.
xia-chao edited a comment on PR #14391:
This is just a patch with minimal content—you could easily review it directly, and perhaps it shouldn't have been included here. However, for major fixes, the code alone often doesn't tell the whole story; I'll only include screenshots like this for significant fixes in the future.
xia-chao updated PR #14391.
xia-chao updated PR #14391.
:thumbs_up: fitzgen submitted PR review.
fitzgen added PR #14391 Fold buffered fuel charges when a function exits to the merge queue.
:check: fitzgen merged PR #14391.
fitzgen removed PR #14391 Fold buffered fuel charges when a function exits from the merge queue.
Last updated: Oct 11 2026 at 04:10 UTC