Skip to content

fix(#378): fail honestly on out-of-layout local — never guess a frame offset - #379

Merged
avrabe merged 1 commit into
mainfrom
fix/378-fail-honestly-local-layout
Jun 19, 2026
Merged

fix(#378): fail honestly on out-of-layout local — never guess a frame offset#379
avrabe merged 1 commit into
mainfrom
fix/378-fail-honestly-local-layout

Conversation

@avrabe

@avrabe avrabe commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Closes #378.

Fail honestly, never guess

select_with_stack's LocalGet/LocalSet/LocalTee handlers emitted a guessed stack offset (local_idx-4)*4 for a local absent from the computed frame layout ("shouldn't happen for valid wasm, fall back to legacy behaviour"). That guess is the pre-#204/#223 layout — wrong under the current compute_local_layout — so if the branch ever fired it would silently load/store the wrong stack slot rather than fail. Same silent-miscompile family as the decoder _ => None (#369/#374) and the encoder index-drop (#206).

All three sites now return a loud Err (loud-skips the function), naming the local index — the GI-FPU-001 / #180 "never emit plausible-but-wrong output" contract.

Verification

  • Frozen bit-identical — control_step 0x00210A55, flight_seam 0x07FDF307, div_const 338/338 (the branch is dead on valid input, so no emitted code changes).
  • Full workspace suite green (cargo test --workspace --exclude synth-verify) with no test triggering the new Err — proving the path was unreachable defensive code that could only ever have silently miscompiled.
  • fmt + clippy clean.

No cycle/size delta — this is correctness/honesty hardening, not an optimization (which is why it's not an oracle-gate cleanup filing). One reversible change, three symmetric sites.

🤖 Generated with Claude Code

… offset

select_with_stack's LocalGet/LocalSet/LocalTee handlers, when a local was
absent from the computed frame layout, fell through to a GUESSED stack offset
`(local_idx-4)*4` (the pre-#204/#223 layout). Under the current
compute_local_layout that guess is wrong, so if the branch ever fired (layout
bug or malformed wasm past validation) it silently emitted a load/store to the
wrong slot — the same silent-miscompile class as the decoder `_ => None`
(#369/#374) and the encoder index-drop (#206).

Replace all three guesses with a loud Err (loud-skips the function), naming the
local index — the GI-FPU-001 / #180 "never emit plausible-but-wrong output"
contract.

Frozen-safe: the branch is dead on valid input (every declared local is in the
layout), so the three fixtures stay bit-identical (control_step 0x00210A55,
flight_seam 0x07FDF307, div_const 338/338) and the full workspace suite is green
with NO test triggering the new Err — confirming it was unreachable defensive
code that could only ever have silently miscompiled. No cycle/size delta; this
is correctness/honesty hardening, not an optimization.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@avrabe
avrabe merged commit 4b9694d into main Jun 19, 2026
13 checks passed
@avrabe
avrabe deleted the fix/378-fail-honestly-local-layout branch June 19, 2026 14:08
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/synth-synthesis/src/instruction_selector.rs 0.00% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

Fail honestly, never guess: out-of-layout local emitted a guessed frame offset instead of a loud error

1 participant