Skip to content

fix(gen-c): a _ switch arm is the catch-all, not (x == _) (Closes #7428) - #7456

Merged
gHashTag merged 2 commits into
masterfrom
genc-switch-underscore
Oct 7, 2026
Merged

gHashTag merged 2 commits into
masterfrom
genc-switch-underscore

Conversation

@gHashTag

@gHashTag gHashTag commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Closes #7428
Part of #5980

What was wrong

gen-c lowers a switch expression to a chain of ternaries, and the else arm becomes the value at the end of the chain. _ => is the same catch-all, but gen-c wrote it as the comparison (x == _). C rejects that: '_' undeclared.

The fix

bootstrap/src/compiler.rs: an arm named _ is treated like else (+4/-1).

Test

bootstrap/tests/backend_behaviour.rs, new test c_takes_the_underscore_arm_of_a_switch (+15). It generates C for an integer switch and an enum switch, compiles it with cc, runs it, and checks the output 10 99 1 7.

Run on the t27c lab with try.sh, both ways:

  • with the fix: backend_behaviour 23 passed
  • with compiler.rs and FROZEN_HASH reverted to master: 22 passed, 1 failed (this test; cc refuses the C)

Reseals

The corpus gen-c diff, old binary vs new over every spec under specs/ plus the 28 sealed specs outside it, changes exactly one file: specs/demos/jones_topology_decision_gate.t27. Its == _ arms become the catch-all value. That spec is resealed, together with its twin seal: JonesTopologyDecisionGate.json and demos_JonesTopologyDecisionGate.json. Only gen_hash_c (db1eb4ba -> f692906e) and the bookkeeping fields move. No other seal goes stale.

Budget

check_budget() from master (#7371) passes: compiler.rs +4, backend_behaviour.rs +15, 19 in total. Both files are already listed in tools/policy/foreign-exceptions.txt on master, so this PR does not touch that file.

🤖 Generated with Claude Code

gHashTag and others added 2 commits October 7, 2026 17:01
gen-c lowers a switch to a chain of ternaries ending in the else value. The
arm `_ =>` is the same catch-all and was written as the comparison
`(x == _)`, which C rejects. The test in backend_behaviour.rs compiles and
runs the C for an integer and an enum switch. Part of #5980.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only gen_hash_c moves: the `== _` arms become the catch-all value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gHashTag gHashTag added the owner-approved-foreign Owner-approved exception to the only-t27 rule: hand-written foreign code allowed in this PR label Oct 7, 2026
@gHashTag
gHashTag enabled auto-merge (squash) October 7, 2026 10:06
This was referenced Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-10-07 11:15:08 UTC

Summary

Status Count
Total Open PRs 50
PRs with Failing Checks 42
PRs with All Checks Green 8
READY 1
FAILING 42
PENDING 0
NO CHECKS YET 0

These columns do not partition: 1 + 42 + 0 + 0 = 43, and there are 50 open PRs. A PR is being counted twice or not at all.

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=9c251d791289 != 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 185030e into master Oct 7, 2026
32 of 39 checks passed
gHashTag added a commit that referenced this pull request Oct 8, 2026
…w lowers it as the catch-all (Closes #7879) (#7880)

#7331 dropped the switch fixture's `_ =>` arm (43dbe54) because gen-c
then wrote `(x == _)` for it, which C cannot compile. #7456 made `_` the
catch-all, so `rest()` and its two asserts come back unchanged and the
`_` catch-all is built and run, not only accepted.

On the t27c lab (master ce605a6 with #7436): gen-c of the fixture has
no `(x == _)`, and `cargo test --release -p t27c --test core_selfhost`
passes 1/1.

Co-authored-by: Claude <claude@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

owner-approved-foreign Owner-approved exception to the only-t27 rule: hand-written foreign code allowed in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gen-c: a _ switch arm is compared as a value, (x == _), instead of being the catch-all

1 participant