✓
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_r1 and NO __koru_unroll_
// machine. expected.txt proves collapse preserves semantics.
import std/io
pub tor hanoi { n: i64, acc: i64 } -> i64
hanoi = if(n == 0)
| then -> acc
| else |> hanoi(n: n - 1, acc): h |> hanoi(n: n - 1, acc: h + 1): v -> v
hanoi(n: 4, acc: 0): r |> std/io:print.ln("{{ r:d }}")
Actual
15
Expected output
15
Flows
subflow ~hanoi click a branch to expand · @labels scroll to their anchor
if (n == 0)
flow ~hanoi click a branch to expand · @labels scroll to their anchor
hanoi (n: 4, acc: 0)
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_r1 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_r1' output_emitted.zig; then
echo "FAIL: __koru_collapse_r1 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