Repository navigation
feat(t27b): lower if-expressions natively; refuse what t27c misprints - #6328
Merged
Merged
Conversation
An `if` used as a value becomes IR `Select { cond, then, els }`, a branch
in codegen so only the taken arm runs (a trap in the other never fires).
Arms take the result type or their peer type; string and struct arms
select an address; a comptime condition lowers only its arm.
Refused by name: ExprIf(no else), ExprIf(comptime arms), and
ExprIf(left operand): t27c prints `(if (c) a else b) + 1` without the
parentheses, so Zig reads the `+ 1` into the else arm.
Corpus vs t27c reference: counted 597 -> 601 of 720, checked passes
326 -> 329, mismatch 0.
Closes #6327
Refs #6063
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
This was referenced Oct 5, 2026
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.
Closes #6327
Refs #6063
What
ifused as a value -> IRSelect { cond, then, els }. Codegen emits a branch, not a csel, so only the taken arm runs: a trap or call in the other arm never fires, as in Zig. Interpreter (eval.rs), AArch64 (codegen.rs, spilled destinations stored on both paths), and the differential fuzzer (randomSelectchecked against the interpreter oracle).ExprIf(no else)ExprIf(comptime arms): Zig cannot type two comptime_int arms behind a runtime condition.ExprIf(left operand): t27c prints(if (c) a else b) + 1asif (c) a else b + 1, and the same for(if ...).xand(if ...)[i]. Zig reads what follows into the else arm, so no lowering of the source can match the reference. Checked: this probe passes in t27b and fails int27c test-report.if_expression_runs_only_the_taken_armincli/t27b/tests/source.rs. Its module gives the same per-test verdict undert27c test-report: 5 pass andtaken_arm_trapsfails in both.Corpus (
t27b corpus specs --blockers --reference <t27c from origin/master a82d61dcd> --reference-cache <own>)port/trinity/src/cli/health_check.t27(3),port/trinity/src/tri/gen_relu.t27(4),port/trios/crates/trios-cli/src/cmd/agent.t27(4).port/trios/crates/trios-sacred/rings/SC-01/src/lib.t27.ExprIf(comptime arms). The only one refused byExprIf(left operand)isport/fpga/verilog/ternary_mac_demo_top.t27, which is also blocked by a tuple and has no tests.Next greedy steps after this PR: char literal +5, StmtExpr +4, StmtFor +4, ExprArrayLiteral +4, type [N]T +8.
Seen, not fixed here: t27c prints
-(x - y)as-x - y. t27b lowers the source meaning, so any test that reaches that shape is a reference bug.docs/reports/t27b_expectations.jsonis untouched.🤖 Generated with Claude Code