✓
Passing This code compiles and runs correctly.
Code
// PIN (collapse-before-unroll ordering, WAY-TWO leg): collapse-recursion
// runs before unroll-recursion in elaborate and admits this shape first —
// the emitted body must carry __koru_collapse_b2_binom and NO __koru_unroll_
// machine. expected.txt proves collapse preserves semantics.
import std/io
pub tor binom { n: i64, k: i64 } -> i64
binom = if(k == 0)
| then -> 1
| else |> if(k == n)
| then -> 1
| else |> binom(n: n - 1, k: k - 1): a |> binom(n: n - 1, k): b -> a + b
binom(n: 6, k: 3): r |> std/io:print.ln("{{ r:d }}")
Actual
20
Expected output
20
Flows
subflow ~binom click a branch to expand · @labels scroll to their anchor
if (k == 0)
flow ~binom click a branch to expand · @labels scroll to their anchor
binom (n: 6, k: 3)
Test Configuration
MUST_RUN
Post-validation Script:
#!/bin/bash
# Pin (RE-PINNED for collapse-before-unroll ordering): collapse-recursion
# runs before unroll-recursion in elaborate, so this shape collapses to a
# closed form FIRST — the __koru_collapse_b2_binom marker must be present and
# the __koru_unroll_ machine must be absent. This pins ORDERING, not just
# collapse correctness (270_013-018 own that). expected.txt proves the
# collapse preserves semantics.
set -e
if ! grep -q '__koru_collapse_b2_binom' output_emitted.zig; then
echo "FAIL: __koru_collapse_b2_binom marker absent — collapse did not fire before unroll"
exit 1
fi
if grep -q '__koru_unroll_' output_emitted.zig; then
echo "FAIL: __koru_unroll_ machine present — unroll fired on a collapse-admitted shape (ordering violated)"
exit 1
fi