✓
Passing This code compiles and runs correctly.
Code
// ASPIRATIONAL: per-arm take analysis restores the fast `for` on a query
// whose body does not take.
//
// Same program as 690_300. The take is not in the query; the query only
// prints. When the emitter scopes `may_remove` to the sweep arm and
// verifies the take addresses the cursor, this query is provably
// non-removing and must emit `for (0..len)`. Today it emits `while`
// because the scan is program-wide — that is 690_300, green. This pin
// flips red→green when the analysis lands.
import std/io
import std/store
std/store:new(arena, capacity: 8) { hp: i64 }
std/store:insert(arena) { hp: 1 }
| row a |> std/store:insert(arena) { hp: 2 }
| row _ |> std/store:take(arena[a])
| item gone |> std/io:print.ln("took {{ gone.hp:d }}")
std/store:rule(arena)
! row e |> std/io:print.ln("see {{ e.hp:d }}")
Actual
took 1
see 2
Expected output
took 1
see 2
Flows
flow ~new click a branch to expand · @labels scroll to their anchor
new (arena, capacity: 8, source: hp: i64)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (arena, source: hp: 1)
flow ~rule click a branch to expand · @labels scroll to their anchor
rule (arena)
Test Configuration
MUST_RUN
Post-validation Script:
#!/bin/bash
# Per-arm analysis: a query whose body does not take must emit the fast
# for, even when the same store is taken elsewhere in the program.
set -u
if [ ! -f output_emitted.zig ]; then
echo "FAIL: no output_emitted.zig"
exit 1
fi
if ! grep -q 'for (0..__koru_store_arena.len)' output_emitted.zig; then
echo "FAIL: expected per-arm analysis to restore for on a query whose body does not take"
exit 1
fi
if grep -q 'while (__koru_i < __koru_store_arena.len)' output_emitted.zig; then
echo "FAIL: tolerant while still emitted; per-arm analysis should have dropped it"
exit 1
fi
echo "PASS: query without a take emits the fast for"
exit 0