Fix HFS write-back insertion using structural inner-label tracking#734
Merged
Fix HFS write-back insertion using structural inner-label tracking#734
Conversation
Hot Field Scalarization (HFS) was inserting write-back stores (self.field = _hfs_local) before every `break` statement, including breaks inside inlined function bodies (__inline_ labeled blocks). These breaks are value-returning exits within the same scope, not control flow that leaves the loop — the containing block's own exit handles the write-back. This caused unnecessary struct.set instructions in hot loops like JsonDeserializer::skip_whitespace, where the inlined get_byte block had a redundant `self.pos = _hfs_pos` before the break. Now breaks targeting __inline_ labels skip write-back insertion. https://claude.ai/code/session_01WDWXhoRc8GFXJYeY6Ms4iy
The field_scalarize change eliminates redundant struct.set write-backs before breaks targeting __inline_ labeled blocks, reducing generated WIR across serde/json tests. https://claude.ai/code/session_01WDWXhoRc8GFXJYeY6Ms4iy
Instead of checking if a break label starts with "__inline_", collect all labels defined within the HFS scope (loop body) and skip write-back for breaks targeting any inner label. This is structurally correct and decouples the optimizer from the inliner's naming convention. The inner_labels set is computed once at the HFS entry point and passed through all recursive replace_in_block calls, ensuring breaks at any nesting depth correctly identify scope-local targets. https://claude.ai/code/session_01WDWXhoRc8GFXJYeY6Ms4iy
Golden fixture conflicts only — will be regenerated by on-task-done. https://claude.ai/code/session_01WDWXhoRc8GFXJYeY6Ms4iy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The HFS (Hot Field Scalarization) pass inserts
struct.setwrite-backs beforebreakstatements that escape the HFS scope. Previously, breaks targeting inlined labeled blocks (e.g.break __inline_foo_1) incorrectly received write-backs too, even though they stay within the HFS-managed loop body.The initial fix checked for the
__inline_label prefix, but this was an ad-hoc coupling between the optimizer and the inliner's naming convention. This PR replaces it with a structural approach:collect_inner_labels) at the entry pointreplace_in_blockcalls via a newinner_labelsparameter onReplaceCtxThis is more correct (catches cases the prefix check missed, e.g.
base64_decode,base64_encode) and decouples the optimizer from label naming conventions.Test plan
hfs_inline_break_no_writeback.wadowithwir_not_expect:O2assertionmise run on-task-done)https://claude.ai/code/session_01WDWXhoRc8GFXJYeY6Ms4iy