✓
Passing This code compiles and runs correctly.
Code
// PINS: `! query <row> when <row>.<icol> == <k>` on an `std/indexes`-declared
// store routes to the key's membership bucket instead of sweeping — the same
// declaration `! first` consumes, widened to a key→ordered-member map.
// Three oracles, one mechanism:
// 1. Membership: the routed query visits exactly the rows carrying the
// key, in join order — the bucket's order, which coincides with the
// sweep's until a take reshuffles dense slots.
// 2. A `stored` write to the indexed column MOVES membership eagerly:
// the row leaves the old bucket and joins the new one at the end —
// a write that moves membership is a join for ordering purposes.
// 3. A take inside a routed query is safe: the taken row's handle stays
// a dead member the row-resolve skips — the sweep's re-check
// contract (690_031) carried at bucket granularity.
// Plus the floor: a `when` on a NON-indexed column still sweeps, and
// `! first` still answers the lowest dense live member (690_327's parity).
import std/store
import std/indexes
import std/io
std/store:new(players, capacity: 8) { key: i64, val: i64 }
std/indexes:store(players, key)
std/store:insert(players) { key: 1, val: 10 }
std/store:insert(players) { key: 2, val: 20 }
std/store:insert(players) { key: 1, val: 11 }
std/store:insert(players) { key: 1, val: 12 }
std/store:insert(players) { key: 2, val: 21 }
// 1. routed membership, join order
std/store:query(players)
! query p when p.key == 1 |> std/io:print.ln("one {{ p.val:d }}")
// 2. the val==11 row moves to key 2 — membership follows the write
std/store:query(players)
! first p when p.val == 11 |> std/store:stored { p.key: 2 }
std/store:query(players)
! query p when p.key == 1 |> std/io:print.ln("one' {{ p.val:d }}")
std/store:query(players)
! query p when p.key == 2 |> std/io:print.ln("two {{ p.val:d }}")
// 3. take every key-2 member inside the routed walk — all three must be
// visited even though each take is mid-iteration
std/store:query(players)
! query p when p.key == 2 |> std/store:take(players[p])
| item i |> std/io:print.ln("took {{ i.val:d }}")
// the taken rows are gone — the bucket answers honestly through dead members
std/store:query(players)
! first p when p.key == 2 |> std/io:print.ln("key2 {{ p.val:d }}")
| none |> std/io:print.ln("key2 none")
// the untouched bucket is still whole
std/store:query(players)
! query p when p.key == 1 |> std/io:print.ln("last {{ p.val:d }}")
// floor: a non-indexed predicate still scans
std/store:query(players)
! query p when p.val == 10 |> std/io:print.ln("scan {{ p.val:d }}")
// 4. a routed query whose body writes the INDEXED column takes the
// survival walk — each visited member leaves the bucket mid-iteration
// and hands its slot to the next unvisited member, which the walk must
// still examine. Both key-1 rows must move, exactly once each.
std/store:query(players)
! query p when p.key == 1 |> std/store:stored { p.key: 9 }
std/store:query(players)
! query p when p.key == 9 |> std/io:print.ln("nine {{ p.val:d }}")
Actual
one 10
one 11
one 12
one' 10
one' 12
two 20
two 21
two 11
took 20
took 21
took 11
key2 none
last 10
last 12
scan 10
nine 10
nine 12
Expected output
✓ Zig✓ JavaScriptone 10
one 11
one 12
one' 10
one' 12
two 20
two 21
two 11
took 20
took 21
took 11
key2 none
last 10
last 12
scan 10
nine 10
nine 12
Flows
flow ~new click a branch to expand · @labels scroll to their anchor
new (players, capacity: 8, source: key: i64, val: i64)
flow ~store click a branch to expand · @labels scroll to their anchor
store (expr: players, key, source: <implicit_source>)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (players, source: key: 1, val: 10)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (players, source: key: 2, val: 20)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (players, source: key: 1, val: 11)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (players, source: key: 1, val: 12)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (players, source: key: 2, val: 21)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
flow ~query click a branch to expand · @labels scroll to their anchor
query (players)
Test Configuration
MUST_RUN LANGUAGES: zig js
Post-validation Script:
#!/bin/bash
# Emitted-code oracle: `! query` on the indexed column must ROUTE, not
# sweep — membership output alone cannot tell a bucket walk from a full
# store scan. The stable path (bodies that cannot disturb the bucket)
# emits a direct `for` over the member list; a body that writes the
# indexed column emits the removal-tolerant cursor walk; the
# non-indexed guard keeps the dense sweep.
set -u
if [ ! -f output_emitted.zig ]; then
echo "FAIL: no output_emitted.zig"
exit 1
fi
if ! grep -q '__index_key: @import' output_emitted.zig; then
echo "FAIL: std/indexes:store(players, key) emitted no __index_key map"
exit 1
fi
if ! grep -q '__index_key.getPtr(__koru_ik)) |__koru_ib|' output_emitted.zig; then
echo "FAIL: '! query p when p.key == 1' did not route to the bucket"
exit 1
fi
if ! grep -q 'for (__koru_ib.items) |__koru_bh|' output_emitted.zig; then
echo "FAIL: the non-disturbing body lost the stable bucket walk"
exit 1
fi
if ! grep -q '__koru_bi: usize = 0;' output_emitted.zig; then
echo "FAIL: the indexed-column-writing body lost the survival walk"
exit 1
fi
if ! grep -q '__koru_ib2.items\[__koru_bi\] == __koru_bh' output_emitted.zig; then
echo "FAIL: the survival walk lost its post-body cursor re-check"
exit 1
fi
if ! grep -q 'for (0..main_module.__koru_store_players.len)' output_emitted.zig; then
echo "FAIL: the non-indexed guard (p.val) lost its sweep"
exit 1
fi
echo "PASS: ! query routes to the bucket — stable walk for take bodies, survival walk for indexed-column writes, sweep preserved"
exit 0