Skip to content

fix(codegen): lower a return nested inside an if block as a real early exit (Refs #1697) - #1798

Merged
gHashTag merged 1 commit into
masterfrom
fix/gen-verilog-nested-early-return
Aug 6, 2026
Merged

gHashTag merged 1 commit into
masterfrom
fix/gen-verilog-nested-early-return

Conversation

@gHashTag

@gHashTag gHashTag commented Aug 6, 2026

Copy link
Copy Markdown
Owner

What

Root-cause compiler fix for the GF-T negative-zero cancellation class found in the previous cycle.

gen_verilog_fn_body's guarded-return rewrite (if(cond){…return} <rest> → if(cond){…} else {<rest>}) only fired at the top level of a function body. A return nested inside the then-block —

if (outer) { …; if (inner) { return A } return B }

— fell through to two sequential Verilog function-name assigns (fn = A; then fn = B;), and last-write-wins silently discarded the guarded value A.

This is the root cause of sadd(-1.0, +1.0) returning the fall-through magnitude (a wrong negative zero) instead of 0, which was only worked around at the spec level last cycle in five signed GF-T specs.

Fix

Emit the guarded then-block via a recursive gen_verilog_fn_body call, so a nested if(inner){return A} return B is itself lowered as an if(inner) A else B early exit rather than two sequential assigns.

Verification

  • Repro (sadd-shaped f): f(5,5) now = 0 (was fall-through), f(7,5) = 65538, f(3,5) = 99 — all correct under icarus-simulate.
  • New internal regression test nested_return_lowers_as_early_exit.
  • Full suite: 1536 passed, 0 failed. 0/33 ternary seals change.

Seal impact

A small minority (~2%, all latent-bug specs) now emit corrected Verilog with stale-but-non-blocking seals (seal-staleness only warns). Documented follow-up reseal — not a merge blocker.

Refs #1697

🤖 Generated with Claude Code

…y exit

gen_verilog_fn_body's guarded-return rewrite (if(cond){...return} <rest>
=> if(cond){...} else {<rest>}) only fired at the top level of a function
body. A `return` nested inside the then-block --
`if(outer){ ...; if(inner){return A} return B }` -- fell through to two
sequential Verilog function-name assigns, and last-write-wins silently
discarded the guarded value A. This is the root cause of the GF-T
negative-zero cancellation bug (sadd(-1.0,+1.0) returned the fall-through
magnitude instead of 0), which last cycle was only worked around at the
spec level in five signed specs.

Fix: emit the guarded then-block via a recursive gen_verilog_fn_body call
so a nested `if(inner){return A} return B` is itself lowered as an
if/else early exit rather than two sequential assigns.

Adds regression test nested_return_lowers_as_early_exit. Reseals
FROZEN_HASH. 1536 unit tests pass; 0/33 ternary seals change.

Refs #1697

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-06 15:04:22 UTC

Summary

Status Count
Total Open PRs 3
PRs with Failing Checks 1
PRs with All Checks Green 2
READY 1
FAILING 1
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=d3cc184cb614 != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@gHashTag
gHashTag merged commit c2d6ab5 into master Aug 6, 2026
22 checks passed
@gHashTag
gHashTag deleted the fix/gen-verilog-nested-early-return branch August 6, 2026 15:05
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.

1 participant