✓
Passing This code compiles and runs correctly.
Code
// PINS: a `for ! each |> insert` on an INDEXED store takes the bulk append
// lowering AND keeps the index — the batch emits the bucket join inside its
// fill loop, so bulk-inserted rows are visible to `! first` and `! query`
// routing exactly as per-row inserts are. The `tags` half pins the
// multi-key shape: a boundary every row through three keys, then a second
// batch that must keep appending to the SAME buckets — the bucket memo and
// the just-left cache both have to stay honest.
import std/store
import std/indexes
import std/io
import std/control
std/store:new(players, capacity: 8) { key: i64, val: i64 }
std/indexes:store(players, key)
std/store:new(acc) { n: 0[i64] }
std/store:new(out) { v: 0[i64] }
std/store:watch(out)
! v x |> std/io:print.ln("{{ x:d }}")
for(0..4)
! each i |> std/store:insert(players) { key: 2, val: @as(i64, @intCast(i)) }
std/store:query(players)
! first p when p.key == 2 |> std/io:print.ln("first {{ p.val:d }}")
| none |> std/io:print.ln("lost")
std/store:query(players)
! query p when p.key == 2 |> std/store:stored { acc.n: acc.n + 1 }
std/store:stored { out.v: acc.n }
std/store:new(tags, capacity: 16) { grp: i32, val: i32 }
std/indexes:store(tags, grp)
// three keys cycling — every row is a boundary, and keys 1/2 arrive fresh
// mid-batch (the map's rehash path must not hand back a moved bucket)
for(0..10)
! each i |> std/store:insert(tags) { grp: @as(i32, @intCast(i % 3)), val: @as(i32, @intCast(i)) }
// two keys alternating into the SAME store — appends to live buckets
for(10..16)
! each i |> std/store:insert(tags) { grp: @as(i32, @intCast(i % 2)), val: @as(i32, @intCast(i)) }
std/store:query(tags)
! query t when t.grp == 0 |> std/io:print.ln("g0 {{ t.val:d }}")
std/store:query(tags)
! query t when t.grp == 1 |> std/io:print.ln("g1 {{ t.val:d }}")
std/store:query(tags)
! query t when t.grp == 2 |> std/io:print.ln("g2 {{ t.val:d }}")
Actual
first 0
4
g0 0
g0 3
g0 6
g0 9
g0 10
g0 12
g0 14
g1 1
g1 4
g1 7
g1 11
g1 13
g1 15
g2 2
g2 5
g2 8
Expected output
✓ Zig✓ JavaScript✓ C#first 0
4
g0 0
g0 3
g0 6
g0 9
g0 10
g0 12
g0 14
g1 1
g1 4
g1 7
g1 11
g1 13
g1 15
g2 2
g2 5
g2 8
Emitted Zig source
// Access compiler flags via the per-user compiler_env module
const CompilerEnv = @import("compiler_env").CompilerEnv;
pub const panic = if (@import("builtin").mode == .Debug)
@import("std").debug.FullPanic(@import("std").debug.defaultPanic)
else
@import("std").debug.simple_panic;
const __koru_bare = struct {
extern fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
extern fn free(ptr: ?*anyopaque) void;
fn bareAlloc(_: *anyopaque, len: usize, alignment: @import("std").mem.Alignment, _: usize) ?[*]u8 {
var p: ?*anyopaque = null;
const a = @max(alignment.toByteUnits(), @sizeOf(usize));
if (posix_memalign(&p, a, len) != 0) return null;
return @ptrCast(p);
}
fn bareResize(_: *anyopaque, _: []u8, _: @import("std").mem.Alignment, _: usize, _: usize) bool { return false; }
fn bareRemap(_: *anyopaque, _: []u8, _: @import("std").mem.Alignment, _: usize, _: usize) ?[*]u8 { return null; }
fn bareFree(_: *anyopaque, memory: []u8, _: @import("std").mem.Alignment, _: usize) void { free(@ptrCast(memory.ptr)); }
const vtable = @import("std").mem.Allocator.VTable{ .alloc = bareAlloc, .resize = bareResize, .remap = bareRemap, .free = bareFree };
const allocator = @import("std").mem.Allocator{ .ptr = undefined, .vtable = &vtable };
};
const __koru_backing = if (@import("builtin").link_libc) @import("std").heap.c_allocator else if (@import("builtin").os.tag == .freestanding) __koru_bare.allocator else @import("std").heap.page_allocator;
var __koru_leak_count: @import("std").atomic.Value(usize) = .init(0);
fn __koru_alloc(ctx: *anyopaque, len: usize, alignment: @import("std").mem.Alignment, ret_addr: usize) ?[*]u8 {
_ = ctx;
const r = __koru_backing.rawAlloc(len, alignment, ret_addr);
if (comptime @import("builtin").mode == .Debug) {
if (r != null) _ = __koru_leak_count.fetchAdd(1, .monotonic);
}
return r;
}
fn __koru_resize(ctx: *anyopaque, memory: []u8, alignment: @import("std").mem.Alignment, new_len: usize, ret_addr: usize) bool {
_ = ctx;
return __koru_backing.rawResize(memory, alignment, new_len, ret_addr);
}
fn __koru_remap(ctx: *anyopaque, memory: []u8, alignment: @import("std").mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {
_ = ctx;
return __koru_backing.rawRemap(memory, alignment, new_len, ret_addr);
}
fn __koru_free(ctx: *anyopaque, memory: []u8, alignment: @import("std").mem.Alignment, ret_addr: usize) void {
_ = ctx;
__koru_backing.rawFree(memory, alignment, ret_addr);
if (comptime @import("builtin").mode == .Debug) {
_ = __koru_leak_count.fetchSub(1, .monotonic);
}
}
const __koru_vtable = @import("std").mem.Allocator.VTable{ .alloc = __koru_alloc, .resize = __koru_resize, .remap = __koru_remap, .free = __koru_free };
pub fn koru_allocator() @import("std").mem.Allocator {
return .{ .ptr = undefined, .vtable = &__koru_vtable };
}
pub inline fn __koru_intcast(comptime T: type, x: anytype) T {
if (comptime (@import("builtin").mode == .Debug or @import("builtin").mode == .ReleaseSafe))
return @as(T, @intCast(x));
const dst = @typeInfo(T);
const src = @typeInfo(@TypeOf(x));
if (comptime (dst == .int and src == .int and dst.int.bits == src.int.bits and dst.int.signedness != src.int.signedness))
return @as(T, @bitCast(x));
return @as(T, @intCast(x));
}
pub fn koru_leak_check() void {
if (comptime @import("builtin").mode != .Debug) return;
if (__koru_leak_count.load(.acquire) == 0) return;
if (comptime @import("builtin").target.os.tag == .freestanding) {
if (comptime @import("builtin").cpu.arch == .wasm32 or @import("builtin").cpu.arch == .wasm64) {
@panic("KORU LEAK CHECK FAILED: the produced program leaked");
} else {
const __klc = struct { extern var stdout: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; };
var __lb: [128]u8 = undefined;
const __lm = "KORU LEAK CHECK FAILED: allocations still outstanding at end of run: ";
@memcpy(__lb[0..__lm.len], __lm);
var __ln: usize = __lm.len;
var __lv = __koru_leak_count.load(.acquire);
var __ld: [20]u8 = undefined;
var __lk: usize = 0;
while (__lv > 0) : (__lk += 1) { __ld[__lk] = @intCast('0' + __lv % 10); __lv /= 10; }
for (0..__lk) |__li| { __lb[__ln] = __ld[__lk - 1 - __li]; __ln += 1; }
__lb[__ln] = '\n'; __ln += 1; __lb[__ln] = 0;
_ = __klc.fputs(@as([*:0]const u8, @ptrCast(&__lb)), __klc.stdout);
@trap();
}
} else {
@import("std").debug.print("KORU LEAK CHECK FAILED: the produced program leaked (trace above)\n", .{});
@import("std").process.exit(1);
}
}
pub const main_module = struct {
// std/store: plural store 'players' created (SoA cell + insert/query/write/take/stripe units); fields key: i64, val: i64
// std/store: 'acc' created (cell + write-subflow at module scope); fields n: i64
// std/store: 'out' created (cell + write-subflow at module scope); fields v: i64
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:23 ~std.control:for()
pub fn flow0() void {
{
const __koru_bulk_lo = (0);
const __koru_bulk_hi = (4);
const __koru_bulk_n = __koru_bulk_hi - __koru_bulk_lo;
if (__koru_bulk_n > 8 - __koru_store_players.len) @panic("std/store: store 'players' is full (capacity 8) - declared capacity and the `| full` branch are pinned at 690_011");
const __koru_bulk_base = __koru_store_players.len;
const __koru_bulk_frem = __koru_store_players.__koru_hslot_free_len;
var __koru_bulk_fresh = __koru_store_players.__koru_hslot_next;
const __koru_bulk_idt = __koru_store_players.__koru_ident;
const __koru_g0 = __koru_store_players.__koru_gen0;
var __koru_im: ?*@import("std").ArrayListUnmanaged(i64) = null;
var __koru_mp: ?*@import("std").ArrayListUnmanaged(i64) = null;
var __koru_mk: @TypeOf(__koru_store_players.key[0]) = undefined;
var __koru_pv: @TypeOf(__koru_store_players.key[0]) = undefined;
var __koru_bl: usize = 0;
var __koru_bp: [*]i64 = undefined;
var __koru_bc: usize = 0;
for (0..__koru_bulk_n) |__koru_bulk_j| {
const __koru_bulk_slot = if (__koru_bulk_j < __koru_bulk_frem) __koru_store_players.__koru_hslot_free[__koru_bulk_frem - 1 - __koru_bulk_j] else blk_hm: { const __koru_s2 = __koru_bulk_fresh; __koru_bulk_fresh += 1; break :blk_hm __koru_s2; };
if (!__koru_bulk_idt) {
__koru_store_players.__koru_row_hslot[__koru_bulk_base + __koru_bulk_j] = __koru_bulk_slot;
__koru_store_players.__koru_hslot_row[__koru_bulk_slot] = __koru_bulk_base + __koru_bulk_j;
}
const i = __koru_bulk_lo + __koru_bulk_j;
const __koru_ik = 2;
__koru_store_players.key[__koru_bulk_base + __koru_bulk_j] = __koru_ik;
__koru_store_players.val[__koru_bulk_base + __koru_bulk_j] = @as(i64, @intCast(i));
if (__koru_bulk_j == 0 or __koru_pv != __koru_ik) {
const __koru_ol = __koru_im;
var __koru_fk = false;
if (__koru_ol) |__koru_op| __koru_op.items.len = __koru_bl;
if (__koru_mp != null and __koru_mk == __koru_ik) {
__koru_im = __koru_mp;
} else {
const __koru_ig = __koru_store_players.__index_key.getOrPut(koru_allocator(), __koru_ik) catch @panic("std/indexes: index insert ran out of memory");
__koru_fk = !__koru_ig.found_existing;
if (__koru_fk) __koru_ig.value_ptr.* = .{};
__koru_im = __koru_ig.value_ptr;
}
if (__koru_fk) __koru_mp = null else if (__koru_ol != null) { __koru_mk = __koru_pv; __koru_mp = __koru_ol; }
__koru_bl = __koru_im.?.items.len;
__koru_bp = __koru_im.?.items.ptr;
__koru_bc = __koru_im.?.capacity;
}
__koru_pv = __koru_ik;
if (__koru_bl == __koru_bc) {
__koru_im.?.items.len = __koru_bl;
__koru_im.?.ensureUnusedCapacity(koru_allocator(), 1) catch @panic("std/indexes: index insert ran out of memory");
__koru_bp = __koru_im.?.items.ptr;
__koru_bc = __koru_im.?.capacity;
}
__koru_bp[__koru_bl] = if (__koru_g0) @as(i64, @intCast((__koru_bulk_base + __koru_bulk_j) | (@as(usize, __KoruStoreT_players.__koru_brand) << 24))) else (@as(i64, @intCast(__koru_bulk_slot | (@as(usize, __KoruStoreT_players.__koru_brand) << 24))) | (@as(i64, @intCast(__koru_store_players.__koru_hslot_gen[__koru_bulk_slot])) << 32));
__koru_bl += 1;
}
if (__koru_im) |__koru_lb| __koru_lb.items.len = __koru_bl;
__koru_store_players.__koru_hslot_free_len = __koru_bulk_frem -| __koru_bulk_n;
__koru_store_players.__koru_hslot_next = __koru_bulk_fresh;
__koru_store_players.len += __koru_bulk_n;
}
{ }
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:26 ~input:__store_sweeprun_players_L27_690_342_indexed_store_bulk_maintains_index_input_19c9f7()
pub fn flow1() void {
_ = main_module.__store_sweeprun_players_L27_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:30 ~input:__store_sweeprun_players_L31_690_342_indexed_store_bulk_maintains_index_input_19c9f7()
pub fn flow2() void {
_ = main_module.__store_sweeprun_players_L31_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:33 ~input:__store_write_out()
pub fn flow3() void {
_ = main_module.__store_write_out_event.handler(.{ .field = 0, .value = __koru_store_acc.n });
}
// std/store: plural store 'tags' created (SoA cell + insert/query/write/take/stripe units); fields grp: i32, val: i32
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:40 ~std.control:for()
pub fn flow4() void {
{
const __koru_bulk_lo = (0);
const __koru_bulk_hi = (10);
const __koru_bulk_n = __koru_bulk_hi - __koru_bulk_lo;
if (__koru_bulk_n > 16 - __koru_store_tags.len) @panic("std/store: store 'tags' is full (capacity 16) - declared capacity and the `| full` branch are pinned at 690_011");
const __koru_bulk_base = __koru_store_tags.len;
const __koru_bulk_frem = __koru_store_tags.__koru_hslot_free_len;
var __koru_bulk_fresh = __koru_store_tags.__koru_hslot_next;
const __koru_bulk_idt = __koru_store_tags.__koru_ident;
const __koru_g0 = __koru_store_tags.__koru_gen0;
var __koru_im: ?*@import("std").ArrayListUnmanaged(i64) = null;
var __koru_mp: ?*@import("std").ArrayListUnmanaged(i64) = null;
var __koru_mk: @TypeOf(__koru_store_tags.grp[0]) = undefined;
var __koru_pv: @TypeOf(__koru_store_tags.grp[0]) = undefined;
var __koru_bl: usize = 0;
var __koru_bp: [*]i64 = undefined;
var __koru_bc: usize = 0;
for (0..__koru_bulk_n) |__koru_bulk_j| {
const __koru_bulk_slot = if (__koru_bulk_j < __koru_bulk_frem) __koru_store_tags.__koru_hslot_free[__koru_bulk_frem - 1 - __koru_bulk_j] else blk_hm: { const __koru_s2 = __koru_bulk_fresh; __koru_bulk_fresh += 1; break :blk_hm __koru_s2; };
if (!__koru_bulk_idt) {
__koru_store_tags.__koru_row_hslot[__koru_bulk_base + __koru_bulk_j] = __koru_bulk_slot;
__koru_store_tags.__koru_hslot_row[__koru_bulk_slot] = __koru_bulk_base + __koru_bulk_j;
}
const i = __koru_bulk_lo + __koru_bulk_j;
const __koru_ik = @as(i32, @intCast(i % 3));
__koru_store_tags.grp[__koru_bulk_base + __koru_bulk_j] = __koru_ik;
__koru_store_tags.val[__koru_bulk_base + __koru_bulk_j] = @as(i32, @intCast(i));
if (__koru_bulk_j == 0 or __koru_pv != __koru_ik) {
const __koru_ol = __koru_im;
var __koru_fk = false;
if (__koru_ol) |__koru_op| __koru_op.items.len = __koru_bl;
if (__koru_mp != null and __koru_mk == __koru_ik) {
__koru_im = __koru_mp;
} else {
const __koru_ig = __koru_store_tags.__index_grp.getOrPut(koru_allocator(), __koru_ik) catch @panic("std/indexes: index insert ran out of memory");
__koru_fk = !__koru_ig.found_existing;
if (__koru_fk) __koru_ig.value_ptr.* = .{};
__koru_im = __koru_ig.value_ptr;
}
if (__koru_fk) __koru_mp = null else if (__koru_ol != null) { __koru_mk = __koru_pv; __koru_mp = __koru_ol; }
__koru_bl = __koru_im.?.items.len;
__koru_bp = __koru_im.?.items.ptr;
__koru_bc = __koru_im.?.capacity;
}
__koru_pv = __koru_ik;
if (__koru_bl == __koru_bc) {
__koru_im.?.items.len = __koru_bl;
__koru_im.?.ensureUnusedCapacity(koru_allocator(), 1) catch @panic("std/indexes: index insert ran out of memory");
__koru_bp = __koru_im.?.items.ptr;
__koru_bc = __koru_im.?.capacity;
}
__koru_bp[__koru_bl] = if (__koru_g0) @as(i64, @intCast((__koru_bulk_base + __koru_bulk_j) | (@as(usize, __KoruStoreT_tags.__koru_brand) << 24))) else (@as(i64, @intCast(__koru_bulk_slot | (@as(usize, __KoruStoreT_tags.__koru_brand) << 24))) | (@as(i64, @intCast(__koru_store_tags.__koru_hslot_gen[__koru_bulk_slot])) << 32));
__koru_bl += 1;
}
if (__koru_im) |__koru_lb| __koru_lb.items.len = __koru_bl;
__koru_store_tags.__koru_hslot_free_len = __koru_bulk_frem -| __koru_bulk_n;
__koru_store_tags.__koru_hslot_next = __koru_bulk_fresh;
__koru_store_tags.len += __koru_bulk_n;
}
{ }
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:44 ~std.control:for()
pub fn flow5() void {
{
const __koru_bulk_lo = (10);
const __koru_bulk_hi = (16);
const __koru_bulk_n = __koru_bulk_hi - __koru_bulk_lo;
if (__koru_bulk_n > 16 - __koru_store_tags.len) @panic("std/store: store 'tags' is full (capacity 16) - declared capacity and the `| full` branch are pinned at 690_011");
const __koru_bulk_base = __koru_store_tags.len;
const __koru_bulk_frem = __koru_store_tags.__koru_hslot_free_len;
var __koru_bulk_fresh = __koru_store_tags.__koru_hslot_next;
const __koru_bulk_idt = __koru_store_tags.__koru_ident;
const __koru_g0 = __koru_store_tags.__koru_gen0;
var __koru_im: ?*@import("std").ArrayListUnmanaged(i64) = null;
var __koru_mp: ?*@import("std").ArrayListUnmanaged(i64) = null;
var __koru_mk: @TypeOf(__koru_store_tags.grp[0]) = undefined;
var __koru_pv: @TypeOf(__koru_store_tags.grp[0]) = undefined;
var __koru_bl: usize = 0;
var __koru_bp: [*]i64 = undefined;
var __koru_bc: usize = 0;
for (0..__koru_bulk_n) |__koru_bulk_j| {
const __koru_bulk_slot = if (__koru_bulk_j < __koru_bulk_frem) __koru_store_tags.__koru_hslot_free[__koru_bulk_frem - 1 - __koru_bulk_j] else blk_hm: { const __koru_s2 = __koru_bulk_fresh; __koru_bulk_fresh += 1; break :blk_hm __koru_s2; };
if (!__koru_bulk_idt) {
__koru_store_tags.__koru_row_hslot[__koru_bulk_base + __koru_bulk_j] = __koru_bulk_slot;
__koru_store_tags.__koru_hslot_row[__koru_bulk_slot] = __koru_bulk_base + __koru_bulk_j;
}
const i = __koru_bulk_lo + __koru_bulk_j;
const __koru_ik = @as(i32, @intCast(i % 2));
__koru_store_tags.grp[__koru_bulk_base + __koru_bulk_j] = __koru_ik;
__koru_store_tags.val[__koru_bulk_base + __koru_bulk_j] = @as(i32, @intCast(i));
if (__koru_bulk_j == 0 or __koru_pv != __koru_ik) {
const __koru_ol = __koru_im;
var __koru_fk = false;
if (__koru_ol) |__koru_op| __koru_op.items.len = __koru_bl;
if (__koru_mp != null and __koru_mk == __koru_ik) {
__koru_im = __koru_mp;
} else {
const __koru_ig = __koru_store_tags.__index_grp.getOrPut(koru_allocator(), __koru_ik) catch @panic("std/indexes: index insert ran out of memory");
__koru_fk = !__koru_ig.found_existing;
if (__koru_fk) __koru_ig.value_ptr.* = .{};
__koru_im = __koru_ig.value_ptr;
}
if (__koru_fk) __koru_mp = null else if (__koru_ol != null) { __koru_mk = __koru_pv; __koru_mp = __koru_ol; }
__koru_bl = __koru_im.?.items.len;
__koru_bp = __koru_im.?.items.ptr;
__koru_bc = __koru_im.?.capacity;
}
__koru_pv = __koru_ik;
if (__koru_bl == __koru_bc) {
__koru_im.?.items.len = __koru_bl;
__koru_im.?.ensureUnusedCapacity(koru_allocator(), 1) catch @panic("std/indexes: index insert ran out of memory");
__koru_bp = __koru_im.?.items.ptr;
__koru_bc = __koru_im.?.capacity;
}
__koru_bp[__koru_bl] = if (__koru_g0) @as(i64, @intCast((__koru_bulk_base + __koru_bulk_j) | (@as(usize, __KoruStoreT_tags.__koru_brand) << 24))) else (@as(i64, @intCast(__koru_bulk_slot | (@as(usize, __KoruStoreT_tags.__koru_brand) << 24))) | (@as(i64, @intCast(__koru_store_tags.__koru_hslot_gen[__koru_bulk_slot])) << 32));
__koru_bl += 1;
}
if (__koru_im) |__koru_lb| __koru_lb.items.len = __koru_bl;
__koru_store_tags.__koru_hslot_free_len = __koru_bulk_frem -| __koru_bulk_n;
__koru_store_tags.__koru_hslot_next = __koru_bulk_fresh;
__koru_store_tags.len += __koru_bulk_n;
}
{ }
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:47 ~input:__store_sweeprun_tags_L48_690_342_indexed_store_bulk_maintains_index_input_19c9f7()
pub fn flow6() void {
_ = main_module.__store_sweeprun_tags_L48_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:50 ~input:__store_sweeprun_tags_L51_690_342_indexed_store_bulk_maintains_index_input_19c9f7()
pub fn flow7() void {
_ = main_module.__store_sweeprun_tags_L51_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_342_indexed_store_bulk_maintains_index/input.k:53 ~input:__store_sweeprun_tags_L54_690_342_indexed_store_bulk_maintains_index_input_19c9f7()
pub fn flow8() void {
_ = main_module.__store_sweeprun_tags_L54_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.handler(.{ });
}
pub fn koru_start_flow() void {
const result_0 = koru_koru.start_event.handler(.{ });
const result_0_done = result_0.done;
_ = &result_0_done;
}
pub fn koru_end_flow() void {
const result_0 = koru_koru.end_event.handler(.{ });
const result_0_done = result_0.done;
_ = &result_0_done;
}
const __KoruStoreT_players = struct {
key: [8]i64 = undefined,
val: [8]i64 = undefined,
len: usize = 0,
__index_key: @import("std").AutoHashMapUnmanaged(i64, @import("std").ArrayListUnmanaged(i64)) = .{},
__koru_hslot_row: [8]usize = undefined,
__koru_hslot_gen: [8]u32 = [_]u32{0} ** 8,
__koru_row_hslot: [8]usize = undefined,
__koru_hslot_free: [8]usize = undefined,
__koru_hslot_free_len: usize = 0,
__koru_hslot_next: usize = 0,
// `__koru_ident` — no removal has run, so slot == dense row
// for every live row; mint/resolve skip both table loads, the
// first take materialises
... [truncated - 65KB total]Emitted C# source
static class main_module {
public static void __koru_stdout_write(dynamic s) => global::System.Console.Out.Write(s);
public static void __koru_stderr_write(dynamic s) => global::System.Console.Error.Write(s);
// The mutable handle carrier — `*String`-style resources are
// `new __KoruBox { data = … }` because C# anonymous types are
// read-only: `s.data = …` (std/string append/clear, handle
// mutation generally) needs a settable member.
public class __KoruBox { public dynamic data; }
// Textification for `{{ … }}` operands: C# bool ToStrings as
// `True` where Koru prints `true`, and the operand's static type
// is unknown at this boundary — a `(x) is bool` inline test would
// be a compile error on statically-typed operands instead. Generic
// on purpose: `dynamic` boxed every value-type operand — measured
// ~1s/10M elements on 012_threat_scanner — while T specializes to
// the operand's own ToString() with no box.
public static string __koru_str<T>(T v) => v is bool b ? (b ? "true" : "false") : v?.ToString();
// std/store: plural store 'players' created (SoA cell + insert/query/write/take/stripe units); fields key: i64, val: i64
// std/store: 'acc' created (cell + write-subflow at module scope); fields n: i64
// std/store: 'out' created (cell + write-subflow at module scope); fields v: i64
// std/store: plural store 'tags' created (SoA cell + insert/query/write/take/stripe units); fields grp: i32, val: i32
static class __koru_store_players {
public static long[] key = new long[8];
public static dynamic __koru_read_key(long __h) { long __r = __koru_resolve(__h); return key[(int)__r]; }
public static long[] val = new long[8];
public static dynamic __koru_read_val(long __h) { long __r = __koru_resolve(__h); return val[(int)__r]; }
public static global::System.Collections.Generic.Dictionary<long, global::System.Collections.Generic.List<long>> __index_key = new global::System.Collections.Generic.Dictionary<long, global::System.Collections.Generic.List<long>>();
public static long len = 0;
public static long[] __koru_hslot_row = new long[8];
public static long[] __koru_hslot_gen = new long[8];
public static long[] __koru_row_hslot = new long[8];
public static long[] __koru_hslot_free = new long[8];
public static long __koru_hslot_free_len = 0;
public static long __koru_hslot_next = 0;
public static long __koru_brand = 1;
public static bool __koru_ident = true;
public static bool __koru_gen0 = true;
public static void __koru_materialize() {
if (!__koru_ident) return;
for (long __i = 0; __i < len; __i++) { __koru_hslot_row[__i] = __i; __koru_row_hslot[__i] = __i; }
__koru_ident = false;
}
public static long __koru_row_of(long h) {
if (h < 0) return -1;
ulong __u = (ulong)h;
long __slot32 = (long)(__u & 0xFFFFFFFFUL);
if ((__slot32 >> 24) != __koru_brand) return -1;
long __slot = __slot32 & 0xFFFFFF;
if (__slot >= __koru_hslot_next) return -1;
if (__koru_gen0) { if ((__u >> 32) != 0) return -1; return __slot; }
if ((long)(__u >> 32) != __koru_hslot_gen[__slot]) return -1;
if (__koru_ident) return __slot;
long __r = __koru_hslot_row[__slot];
if (__r >= len) return -1;
return __r;
}
public static long __koru_resolve(long h) {
if (h >= 0) {
ulong __u = (ulong)h;
long __slot32 = (long)(__u & 0xFFFFFFFFUL);
if ((__slot32 >> 24) != __koru_brand) throw new global::System.Exception("std/store: 'players[...]' does not address a row - the value is not a handle this store issued (handles come from `| row` and row cursors)");
long __slot = __slot32 & 0xFFFFFF;
if (__koru_gen0) {
if ((__u >> 32) != 0 && __slot < __koru_hslot_next) throw new global::System.Exception("std/store: stale row handle into store 'players' - the row it addressed was removed (stale-handle trap pinned at 690_115)");
} else if (__slot < __koru_hslot_next && (long)(__u >> 32) != __koru_hslot_gen[__slot]) throw new global::System.Exception("std/store: stale row handle into store 'players' - the row it addressed was removed (stale-handle trap pinned at 690_115)");
}
long __r = __koru_row_of(h);
if (__r < 0) throw new global::System.Exception("std/store: 'players[...]' does not address a row - the value is not a handle this store issued (handles come from `| row` and row cursors)");
return __r;
}
public static long __koru_handle_of(long dense) {
if (__koru_gen0) return dense | (__koru_brand << 24);
long __slot = dense;
if (!__koru_ident) __slot = __koru_row_hslot[dense];
return (__slot | (__koru_brand << 24)) | (__koru_hslot_gen[__slot] << 32);
}
}
static class __koru_store_acc {
public static long n = 0;
public static long __koru_brand = -1;
}
static class __koru_store_out {
public static long v = 0;
public static long __koru_brand = -1;
}
static class __koru_store_tags {
public static int[] grp = new int[16];
public static dynamic __koru_read_grp(long __h) { long __r = __koru_resolve(__h); return grp[(int)__r]; }
public static int[] val = new int[16];
public static dynamic __koru_read_val(long __h) { long __r = __koru_resolve(__h); return val[(int)__r]; }
public static global::System.Collections.Generic.Dictionary<long, global::System.Collections.Generic.List<long>> __index_grp = new global::System.Collections.Generic.Dictionary<long, global::System.Collections.Generic.List<long>>();
public static long len = 0;
public static long[] __koru_hslot_row = new long[16];
public static long[] __koru_hslot_gen = new long[16];
public static long[] __koru_row_hslot = new long[16];
public static long[] __koru_hslot_free = new long[16];
public static long __koru_hslot_free_len = 0;
public static long __koru_hslot_next = 0;
public static long __koru_brand = 4;
public static bool __koru_ident = true;
public static bool __koru_gen0 = true;
public static void __koru_materialize() {
if (!__koru_ident) return;
for (long __i = 0; __i < len; __i++) { __koru_hslot_row[__i] = __i; __koru_row_hslot[__i] = __i; }
__koru_ident = false;
}
public static long __koru_row_of(long h) {
if (h < 0) return -1;
ulong __u = (ulong)h;
long __slot32 = (long)(__u & 0xFFFFFFFFUL);
if ((__slot32 >> 24) != __koru_brand) return -1;
long __slot = __slot32 & 0xFFFFFF;
if (__slot >= __koru_hslot_next) return -1;
if (__koru_gen0) { if ((__u >> 32) != 0) return -1; return __slot; }
if ((long)(__u >> 32) != __koru_hslot_gen[__slot]) return -1;
if (__koru_ident) return __slot;
long __r = __koru_hslot_row[__slot];
if (__r >= len) return -1;
return __r;
}
public static long __koru_resolve(long h) {
if (h >= 0) {
ulong __u = (ulong)h;
long __slot32 = (long)(__u & 0xFFFFFFFFUL);
if ((__slot32 >> 24) != __koru_brand) throw new global::System.Exception("std/store: 'tags[...]' does not address a row - the value is not a handle this store issued (handles come from `| row` and row cursors)");
long __slot = __slot32 & 0xFFFFFF;
if (__koru_gen0) {
if ((__u >> 32) != 0 && __slot < __koru_hslot_next) throw new global::System.Exception("std/store: stale row handle into store 'tags' - the row it addressed was removed (stale-handle trap pinned at 690_115)");
} else if (__slot < __koru_hslot_next && (long)(__u >> 32) != __koru_hslot_gen[__slot]) throw new global::System.Exception("std/store: stale row handle into store 'tags' - the row it addressed was removed (stale-handle trap pinned at 690_115)");
}
long __r = __koru_row_of(h);
if (__r < 0) throw new global::System.Exception("std/store: 'tags[...]' does not address a row - the value is not a handle this store issued (handles come from `| row` and row cursors)");
return __r;
}
public static long __koru_handle_of(long dense) {
if (__koru_gen0) return dense | (__koru_brand << 24);
long __slot = dense;
if (!__koru_ident) __slot = __koru_row_hslot[dense];
return (__slot | (__koru_brand << 24)) | (__koru_hslot_gen[__slot] << 32);
}
}
public static class __store_insert_players_event {
public struct Input {
public long key;
public long val;
public long __site_line;
}
public static dynamic handler(Input __koru_input) {
var key = __koru_input.key;
var val = __koru_input.val;
var __site_line = __koru_input.__site_line;
if (__koru_store_players.len >= 8) throw new global::System.Exception("std/store: store 'players' is full (capacity 8) - declared capacity and the `| full` branch are pinned at 690_011");
long __koru_new_row = __koru_store_players.len;
long __koru_hslot;
if (__koru_store_players.__koru_hslot_free_len > 0) {
__koru_store_players.__koru_hslot_free_len -= 1;
__koru_hslot = __koru_store_players.__koru_hslot_free[__koru_store_players.__koru_hslot_free_len];
} else {
__koru_hslot = __koru_store_players.__koru_hslot_next;
__koru_store_players.__koru_hslot_next += 1;
}
if (!__koru_store_players.__koru_ident) {
__koru_store_players.__koru_hslot_row[__koru_hslot] = __koru_new_row;
__koru_store_players.__koru_row_hslot[__koru_new_row] = __koru_hslot;
}
__koru_store_players.key[__koru_new_row] = key;
__koru_store_players.val[__koru_new_row] = val;
__koru_store_players.len += 1;
long __koru_ik = (long)(__koru_store_players.key[__koru_new_row]);
global::System.Collections.Generic.List<long> __koru_ib;
if (!__koru_store_players.__index_key.TryGetValue(__koru_ik, out __koru_ib)) { __koru_ib = new global::System.Collections.Generic.List<long>(); __koru_store_players.__index_key[__koru_ik] = __koru_ib; }
__koru_ib.Add(__koru_store_players.__koru_handle_of(__koru_new_row));
return default;
}
}
public static class __store_apply_players_event {
public struct Input {
public long row;
public long field;
public long value_0;
public long value_1;
}
public struct Output {
public string tag;
public long key;
public long val;
}
public static Output handler(Input __koru_input) {
var row = __koru_input.row;
var field = __koru_input.field;
var value_0 = __koru_input.value_0;
var value_1 = __koru_input.value_1;
var __koru_r = row;
switch (field) {
case 0: { long __koru_iold = (long)(__koru_store_players.key[__koru_r]);
long __koru_ih = __koru_store_players.__koru_handle_of(__koru_r);
__koru_store_players.key[__koru_r] = value_0; if (__koru_iold != (long)(value_0)) {
global::System.Collections.Generic.List<long> __koru_ib;
if (__koru_store_players.__index_key.TryGetValue(__koru_iold, out __koru_ib)) {
__koru_ib.Remove(__koru_ih);
if (__koru_ib.Count == 0) __koru_store_players.__index_key.Remove(__koru_iold);
}
global::System.Collections.Generic.List<long> __koru_ib2;
if (!__koru_store_players.__index_key.TryGetValue((long)(value_0), out __koru_ib2)) { __koru_ib2 = new global::System.Collections.Generic.List<long>(); __koru_store_players.__index_key[(long)(value_0)] = __koru_ib2; }
__koru_ib2.Add(__koru_ih);
}
return new Output { tag = "key", key = value_0 }; }
case 1: { __koru_store_players.val[__koru_r] = value_1; return new Output { tag = "val", val = value_1 }; }
}
throw new global::System.Exception("__store_apply_players: field index " + field + " is not a column of store 'players'");
return default;
}
}
public static class __store_teardown_players_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
__koru_store_players.__index_key.Clear();
__koru_store_players.len = 0;
return default;
}
}
public static class __store_apply_acc_event {
public struct Input {
public long field;
public long value;
}
public struct Output {
public string tag;
public long n;
}
public static Output handler(Input __koru_input) {
var field = __koru_input.field;
var value = __koru_input.value;
switch (field) {
case 0: { __koru_store_acc.n = value; return new Output { tag = "n", n = value }; }
}
throw new global::System.Exception("__store_apply_acc: field index " + field + " is not a column of store 'acc'");
return default;
}
}
public static class __store_write_acc_event {
public struct Input {
public long field;
public long value;
}
public static dynamic handler(Input __koru_input) {
var field = __koru_input.field;
var value = __koru_input.value;
var result_0 = main_module.__store_apply_acc_event.handler(new __store_apply_acc_event.Input { field = (long)(field), value = (long)(value)});
var _auto_11 = result_0.n;
return default;
}
}
public static class __store_announce_acc_event {
public struct Input {
public long field;
}
public static dynamic handler(Input __koru_input) {
var field = __koru_input.field;
return default;
}
}
public static class __store_apply_out_event {
public struct Input {
public long field;
public long value;
}
public struct Output {
public string tag;
public long v;
}
public static Output handler(Input __koru_input) {
var field = __koru_input.field;
var value = __koru_input.value;
switch (field) {
case 0: { __koru_store_out.v = value; return new Output { tag = "v", v = value }; }
}
throw new global::System.Exception("__store_apply_out: field index " + field + " is not a column of store 'out'");
return default;
}
}
public static class __store_write_out_event {
public struct Input {
public long field;
public long value;
}
public static dynamic handler(Input __koru_input) {
var field = __koru_input.field;
var value = __koru_input.value;
var result_1 = main_module.__store_apply_out_event.handler(new __store_apply_out_event.Input { field = (long)(field), value = (long)(value)});
var x = result_1.v;
__koru_stdout_write("" + __koru_str(x) + "\n");
return default;
}
}
public static class __store_peek_out_event {
public struct Input {
public long field;
}
public struct Output {
public string tag;
public long v;
}
public static Output handler(Input __koru_input) {
var field = __koru_input.field;
switch (field) {
case 0: return new Output { tag = "v", v = __koru_store_out.v };
}
throw new global::System.Exception("__store_peek_out: field index " + field + " is not a column of store 'out'");
return default;
}
}
public static class __store_announce_out_event {
public struct Input {
public long field;
}
public static dynamic handler(Input __koru_input) {
var field = __koru_input.field;
var result_2 = main_module.__store_peek_out_event.handler(new __store_peek_out_event.Input { field = (long)(field)});
var x = result_2.v;
__koru_stdout_write("" + __koru_str(x) + "\n");
return default;
}
}
public static class __store_sweepbody_players_L27_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event {
public struct Input {
public long __koru_srf_p_L27_val;
public long __koru_sdix_p_L27;
}
public static dynamic handler(Input __koru_input) {
var __koru_srf_p_L27_val = __koru_input.__koru_srf_p_L27_val;
var __koru_sdix_p_L27 = __koru_input.__koru_sdix_p_L27;
__koru_stdout_write("first " + __koru_str(__koru_srf_p_L27_val) + "\n");
return default;
}
}
public static class __store_nonebody_players_L28_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
__koru_stdout_write("lost" + "\n");
return default;
}
}
public static class __store_sweeprun_players_L27_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
{
var __koru_found = false;
{
global::System.Collections.Generic.List<long> __koru_ib;
if (__koru_store_players.__index_key.TryGetValue((long)(2), out __koru_ib)) {
long __koru_im = -1;
foreach (var __koru_bh in __koru_ib) {
var __koru_cand = __koru_store_players.__koru_row_of(__koru_bh);
if (__koru_cand >= 0 && (__koru_im < 0 || __koru_cand < __koru_im)) __koru_im = __koru_cand;
}
if (__koru_im >= 0) {
var __koru_si = __koru_im;
var __koru_srf_p_L27_val = __koru_store_players.val[__koru_si];
__koru_found = true;
main_module.__store_sweepbody_players_L27_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.handler(new main_module.__store_sweepbody_players_L27_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.Input { __koru_srf_p_L27_val = __koru_srf_p_L27_val, __koru_sdix_p_L27 = __koru_si });
}
}
}
if (!__koru_found) {
main_module.__store_nonebody_players_L28_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.handler(new main_module.__store_nonebody_players_L28_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.Input { });
}
}
return default;
}
}
public static class __store_sweepbody_players_L31_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event {
public struct Input {
public long __koru_sdix_p_L31;
}
public static dynamic handler(Input __koru_input) {
var __koru_sdix_p_L31 = __koru_input.__koru_sdix_p_L31;
main_module.__store_write_acc_event.handler(new __store_write_acc_event.Input { field = (long)(0), value = (long)(__koru_store_acc.n + 1)});
return default;
}
}
public static class __store_sweeprun_players_L31_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
{
long __koru_ik = (long)(2);
global::System.Collections.Generic.List<long> __koru_ib;
if (__koru_store_players.__index_key.TryGetValue(__koru_ik, out __koru_ib)) {
foreach (var __koru_bh in __koru_ib) {
var __koru_si = __koru_store_players.__koru_row_of(__koru_bh);
if (__koru_si < 0) continue;
main_module.__store_sweepbody_players_L31_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.handler(new main_module.__store_sweepbody_players_L31_690_342_indexed_store_bulk_maintains_index_input_19c9f7_event.Input { __koru_sdix_p_L31 = __koru_si });
}
}
}
return default;
}
}
public static class __store_insert_tags_event {
public struct Input {
public int grp;
public int val;
public long __site_line;
}
public static dynamic handler(Input __koru_input) {
var grp = __koru_input.grp;
var val = __koru_input.val;
var __site_line = __koru_input.__site_line;
if (__koru_store_tags.len >= 16) throw new global::System.Exception("std/store: store 'tags' is full (capacity 16) - declared capacity and the `| full` branch are pinned at 690_011");
long __koru_new_row = __koru_store_tags.len;
long __koru_hslot;
if (__koru_store_tags.__koru_hslot_free_len > 0) {
__koru_store_t
... [truncated - 38KB total]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 ~new click a branch to expand · @labels scroll to their anchor
new (acc, source: n: 0[i64])
flow ~new click a branch to expand · @labels scroll to their anchor
new (out, source: v: 0[i64])
flow ~watch click a branch to expand · @labels scroll to their anchor
watch (out)
flow ~for click a branch to expand · @labels scroll to their anchor
for (0..4)
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 ~stored click a branch to expand · @labels scroll to their anchor
stored (source: out.v: acc.n)
flow ~new click a branch to expand · @labels scroll to their anchor
new (tags, capacity: 16, source: grp: i32, val: i32)
flow ~store click a branch to expand · @labels scroll to their anchor
store (expr: tags, grp, source: <implicit_source>)
flow ~for click a branch to expand · @labels scroll to their anchor
for (0..10)
flow ~for click a branch to expand · @labels scroll to their anchor
for (10..16)
flow ~query click a branch to expand · @labels scroll to their anchor
query (tags)
flow ~query click a branch to expand · @labels scroll to their anchor
query (tags)
flow ~query click a branch to expand · @labels scroll to their anchor
query (tags)
Test Configuration
MUST_RUN LANGUAGES: zig js cs
Post-validation Script:
#!/bin/bash
# Emitted-code oracle: the `for ! each |> insert` on the indexed store
# must take the bulk lowering AND maintain the bucket map inside the fill
# loop — the failure mode being pinned is a batch that writes columns raw
# while leaving every row it added invisible to `__index_*`.
set -u
if [ ! -f output_emitted.zig ]; then
echo "FAIL: no output_emitted.zig"
exit 1
fi
if ! grep -q '__koru_bulk_frem' output_emitted.zig; then
echo "FAIL: bulk lowering did not fire on the indexed store"
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_grp: @import' output_emitted.zig; then
echo "FAIL: std/indexes:store(tags, grp) emitted no __index_grp map"
exit 1
fi
if ! grep -q 'AutoHashMapUnmanaged(i32' output_emitted.zig; then
echo "FAIL: the tags bucket map did not take the column's i32 key type"
exit 1
fi
if ! grep -q '__index_key.getOrPut(koru_allocator(), __koru_ik)' output_emitted.zig; then
echo "FAIL: the bulk loop does not maintain the bucket"
exit 1
fi
if ! grep -q '__koru_bp\[__koru_bl\] = ' output_emitted.zig; then
echo "FAIL: the bulk loop lost the inline member store (register tail)"
exit 1
fi
if ! grep -q '__koru_op.items.len = __koru_bl' output_emitted.zig; then
echo "FAIL: the bucket-length commit on key switch is missing"
exit 1
fi
if ! grep -q '__koru_mp != null and __koru_mk == __koru_ik' output_emitted.zig; then
echo "FAIL: the just-left bucket cache is missing"
exit 1
fi
echo "PASS: indexed store bulk-lowers with per-row bucket maintenance — memo, just-left cache, register-tail store"
exit 0