Skip to content

Fix HFS write-back insertion using structural inner-label tracking#734

Merged
gfx merged 6 commits intomainfrom
claude/optimize-json-twitter-WBQFl
Mar 30, 2026
Merged

Fix HFS write-back insertion using structural inner-label tracking#734
gfx merged 6 commits intomainfrom
claude/optimize-json-twitter-WBQFl

Conversation

@gfx
Copy link
Copy Markdown
Member

@gfx gfx commented Mar 30, 2026

Summary

The HFS (Hot Field Scalarization) pass inserts struct.set write-backs before break statements 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 all labels defined within the HFS loop body (collect_inner_labels) at the entry point
  • Pass the label set through all recursive replace_in_block calls via a new inner_labels parameter on ReplaceCtx
  • Skip write-back for breaks targeting any inner label, since they remain within the HFS scope where scalarized locals are still valid

This 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

  • E2E fixture hfs_inline_break_no_writeback.wado with wir_not_expect:O2 assertion
  • All 4385 e2e tests pass
  • All 1269 wado module tests pass (mise run on-task-done)
  • Golden fixtures updated to reflect reduced WIR output

https://claude.ai/code/session_01WDWXhoRc8GFXJYeY6Ms4iy

claude added 6 commits March 30, 2026 08:17
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
@gfx gfx enabled auto-merge March 30, 2026 10:59
@gfx gfx changed the title Skip HFS write-back before inlined labeled block breaks Fix HFS write-back insertion using structural inner-label tracking Mar 30, 2026
@gfx gfx merged commit ec4527a into main Mar 30, 2026
10 checks passed
@gfx gfx deleted the claude/optimize-json-twitter-WBQFl branch March 30, 2026 11:04
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