✓
Passing This code compiles and runs correctly.
Code
// PIN (recursion-unroll pass, challenge 035 leg — CONTROL): mutual
// recursion is excluded — it is not DIRECT self-recursion (is-even calls
// is-odd, is-odd calls is-even; neither calls itself). Measured 0.24 ns/
// call on the kernel — LLVM already collapses the parity chain, so even a
// hypothetical mutual-to-self fusion would chase noise. The pass must
// refuse both bodies: emitted shape stays baseline (whatever the current
// lowering is — this pin asserts the census does not change), no
// substituted guards, correct output.
import std/io
pub tor is-even { n: i64 } -> i64
pub tor is-odd { n: i64 } -> i64
is-even = if(n == 0)
| then -> 1
| else |> is-odd(n: n - 1): v -> v
is-odd = if(n == 0)
| then -> 0
| else |> is-even(n: n - 1): v -> v
is-even(n: 10): r |> std/io:print.ln("{{ r:d }}")
Actual
1
Expected output
1
Flows
subflow ~is-even click a branch to expand · @labels scroll to their anchor
if (n == 0)
subflow ~is-odd click a branch to expand · @labels scroll to their anchor
if (n == 0)
flow ~is-even click a branch to expand · @labels scroll to their anchor
is-even (n: 10)
Test Configuration
MUST_RUN
Post-validation Script:
#!/bin/bash
# Pin (CONTROL): mutual recursion must NOT be transformed — neither tor is
# direct self-recursion. Baseline census measured on the current lowering
# (tail-mutual flattens: is_even=1 is_odd=0 handler sites — the parity chain
# runs as loops inside the handler_impls, only the external is-even call
# remains). The pin asserts those counts are UNCHANGED and no
# parameter-substituted guards appear.
set -e
esites=$(grep -o 'is_even_event\.handler(' output_emitted.zig | wc -l | tr -d ' ')
osites=$(grep -o 'is_odd_event\.handler(' output_emitted.zig | wc -l | tr -d ' ')
if [ "$esites" -ne 1 ] || [ "$osites" -ne 0 ]; then
echo "FAIL: mutual handler census changed (is_even=$esites is_odd=$osites, baseline 1/0) — mutual recursion was transformed"
exit 1
fi
if grep -qE 'n - 1\)?.*== 0|\(n - 1\) == 0' output_emitted.zig; then
echo "FAIL: parameter-substituted guard present — mutual recursion was unrolled"
exit 1
fi