✓
Passing This code compiles and runs correctly.
Code
// DRAIN SWEEP — a rule whose entire `! row` body is `take(s[e])` with a
// discarded `| item` payload removes every row the invoked sweep visits.
// The per-row take reads every column into the item payload and swap-writes
// every column of the last row into the freed slot — work that exists for
// the payload's sake and to keep survivors live. A drain has neither, so
// the invoked sweep lowers to the clear unit's canonical reset: a
// generation bump over every issued slot (`0..hslot_next`), then len,
// freelist and the fresh cursor drop to zero and `ident` re-arms — no
// column traffic. Refilled rows take slots in fresh order rather than
// sequential take's LIFO pop order — observable only in handle bit
// values; the slot SET reissued is identical.
//
// `pool` qualifies: bare take on the bound row, discard item arm, no
// guard, no owned columns, no `! removed` observer.
// `guarded` declines: a `when` clause makes the walk selective — it keeps
// the removal-tolerant `while` that re-checks the index swap-remove just
// refilled.
// `ipool` qualifies WITH an index: take reseats nothing in the bucket
// map (dead handles resolve to no live row), so a teardown leaves the
// index exactly as sequential take would — and the pin proves it by
// routing a lookup over the drained store and again after a refill.
//
// Inserts sit above the rule declarations so the reactive per-insert fire
// (`__site_line > rule line`) stays out of the picture — the sweeps run
// only when the named rules are invoked.
import std/io
import std/store
import std/indexes
std/store:new(pool, capacity: 64) { hp: i64 }
std/store:new(guarded, capacity: 64) { hp: i64 }
std/store:new(ipool, capacity: 64) { tag: i64, hp: i64 }
std/indexes:store(ipool, tag)
std/store:insert(pool) { hp: 5 }
| row _ |> _
| full |> _
std/store:insert(pool) { hp: 50 }
| row _ |> _
| full |> _
std/store:insert(pool) { hp: 8 }
| row _ |> _
| full |> _
std/store:insert(guarded) { hp: 5 }
| row _ |> _
| full |> _
std/store:insert(guarded) { hp: 50 }
| row _ |> _
| full |> _
std/store:insert(guarded) { hp: 8 }
| row _ |> _
| full |> _
std/store:insert(ipool) { tag: 1, hp: 5 }
| row _ |> _
| full |> _
std/store:insert(ipool) { tag: 2, hp: 50 }
| row _ |> _
| full |> _
tor drain-pool {}
drain-pool = std/store:rule(pool)
! row e |> std/store:take(pool[e])
| item _ |> _
tor sweep-guarded {}
sweep-guarded = std/store:rule(guarded)
! row e when e.hp <= 10 |> std/store:take(guarded[e])
| item _ |> _
tor drain-ipool {}
drain-ipool = std/store:rule(ipool)
! row e |> std/store:take(ipool[e])
| item _ |> _
drain-pool()
sweep-guarded()
drain-ipool()
std/io:print.ln("pool {{ pool.len:d }}")
std/io:print.ln("guarded {{ guarded.len:d }}")
std/io:print.ln("ipool {{ ipool.len:d }}")
// a routed lookup over the drained store answers none — the bucket's
// dead members skip, never resolve
std/store:query(ipool)
! first p when p.tag == 1 |> std/io:print.ln("stale {{ p.hp:d }}")
| none |> std/io:print.ln("ipool drained")
// a standing rule still stands: drain lowered the sweep, not the enters —
// this insert (site line past the rule's) fires the take body and the
// new row dies instantly, so the routed lookup still answers none
std/store:insert(ipool) { tag: 2, hp: 99 }
| row _ |> _
| full |> _
std/io:print.ln("after-refill {{ ipool.len:d }}")
std/store:query(ipool)
! first p when p.tag == 2 |> std/io:print.ln("stale {{ p.hp:d }}")
| none |> std/io:print.ln("rule still stands")
Actual
pool 0
guarded 1
ipool 0
ipool drained
after-refill 0
rule still stands
Expected output
✓ Zig✓ JavaScript✓ C#pool 0
guarded 1
ipool 0
ipool drained
after-refill 0
rule still stands
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 'pool' created (SoA cell + insert/query/write/take/stripe units); fields hp: i64
// std/store: plural store 'guarded' created (SoA cell + insert/query/write/take/stripe units); fields hp: i64
// std/store: plural store 'ipool' created (SoA cell + insert/query/write/take/stripe units); fields tag: i64, hp: i64
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:37 ~input:__store_insertf_pool()
pub fn flow0() void {
const result_0 = main_module.__store_insertf_pool_event.handler(.{ .hp = 5, .__site_line = 37 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:38 | row _auto_6 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:39 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:40 ~input:__store_insertf_pool()
pub fn flow1() void {
const result_0 = main_module.__store_insertf_pool_event.handler(.{ .hp = 50, .__site_line = 40 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:41 | row _auto_7 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:42 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:43 ~input:__store_insertf_pool()
pub fn flow2() void {
const result_0 = main_module.__store_insertf_pool_event.handler(.{ .hp = 8, .__site_line = 43 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:44 | row _auto_8 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:45 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:47 ~input:__store_insertf_guarded()
pub fn flow3() void {
const result_0 = main_module.__store_insertf_guarded_event.handler(.{ .hp = 5, .__site_line = 47 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:48 | row _auto_9 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:49 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:50 ~input:__store_insertf_guarded()
pub fn flow4() void {
const result_0 = main_module.__store_insertf_guarded_event.handler(.{ .hp = 50, .__site_line = 50 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:51 | row _auto_10 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:52 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:53 ~input:__store_insertf_guarded()
pub fn flow5() void {
const result_0 = main_module.__store_insertf_guarded_event.handler(.{ .hp = 8, .__site_line = 53 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:54 | row _auto_11 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:55 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:57 ~input:__store_insertf_ipool()
pub fn flow6() void {
const result_0 = main_module.__store_insertf_ipool_event.handler(.{ .tag = 1, .hp = 5, .__site_line = 57 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:58 | row _auto_12 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:59 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:60 ~input:__store_insertf_ipool()
pub fn flow7() void {
const result_0 = main_module.__store_insertf_ipool_event.handler(.{ .tag = 2, .hp = 50, .__site_line = 60 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:61 | row _auto_13 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:62 | full |>
.full => {
},
}
}
pub const drain_pool_event = struct {
pub const Input = struct {
};
pub const Output = void;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:65
_ = &__koru_event_input;
const result = main_module.__store_qsweep_pool_L65_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.handler(.{ });
_ = &result;
}
};
pub const sweep_guarded_event = struct {
pub const Input = struct {
};
pub const Output = void;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:70
_ = &__koru_event_input;
const result = main_module.__store_qsweep_guarded_L70_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.handler(.{ });
_ = &result;
}
};
pub const drain_ipool_event = struct {
pub const Input = struct {
};
pub const Output = void;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:75
_ = &__koru_event_input;
const result = main_module.__store_qsweep_ipool_L75_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.handler(.{ });
_ = &result;
}
};
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:79 ~input:drain_pool()
pub fn flow8() void {
_ = main_module.drain_pool_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:80 ~input:sweep_guarded()
pub fn flow9() void {
_ = main_module.sweep_guarded_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:81 ~input:drain_ipool()
pub fn flow10() void {
_ = main_module.drain_ipool_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:83 ~std.io:print.impl()
pub fn flow11() void {
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("pool {d}\n", .{__koru_store_pool.len});
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:84 ~std.io:print.impl()
pub fn flow12() void {
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("guarded {d}\n", .{__koru_store_guarded.len});
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:85 ~std.io:print.impl()
pub fn flow13() void {
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("ipool {d}\n", .{__koru_store_ipool.len});
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:89 ~input:__store_sweeprun_ipool_L90_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c()
pub fn flow14() void {
_ = main_module.__store_sweeprun_ipool_L90_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:96 ~input:__store_insertf_ipool()
pub fn flow15() void {
const result_0 = main_module.__store_insertf_ipool_event.handler(.{ .tag = 2, .hp = 99, .__site_line = 96 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:97 | row _auto_14 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:98 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:99 ~std.io:print.impl()
pub fn flow16() void {
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("after-refill {d}\n", .{__koru_store_ipool.len});
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_336_take_only_rule_lowers_to_drain_sweep/input.k:100 ~input:__store_sweeprun_ipool_L101_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c()
pub fn flow17() void {
_ = main_module.__store_sweeprun_ipool_L101_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_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_pool = struct {
hp: [64]i64 = undefined,
len: usize = 0,
__koru_hslot_row: [64]usize = undefined,
__koru_hslot_gen: [64]u32 = [_]u32{0} ** 64,
__koru_row_hslot: [64]usize = undefined,
__koru_hslot_free: [64]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 and flips it, drain and clear
// re-arm it by resetting the slot space. `__koru_gen0` — no gen
// bump has ever run; it implies slot == row for every minted
// slot, so resolve sheds the gen lo
... [truncated - 71KB 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 'pool' created (SoA cell + insert/query/write/take/stripe units); fields hp: i64
// std/store: plural store 'guarded' created (SoA cell + insert/query/write/take/stripe units); fields hp: i64
// std/store: plural store 'ipool' created (SoA cell + insert/query/write/take/stripe units); fields tag: i64, hp: i64
static class __koru_store_pool {
public static long[] hp = new long[64];
public static dynamic __koru_read_hp(long __h) { long __r = __koru_resolve(__h); return hp[(int)__r]; }
public static long len = 0;
public static long[] __koru_hslot_row = new long[64];
public static long[] __koru_hslot_gen = new long[64];
public static long[] __koru_row_hslot = new long[64];
public static long[] __koru_hslot_free = new long[64];
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: 'pool[...]' 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 'pool' - 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 'pool' - 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: 'pool[...]' 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_guarded {
public static long[] hp = new long[64];
public static dynamic __koru_read_hp(long __h) { long __r = __koru_resolve(__h); return hp[(int)__r]; }
public static long len = 0;
public static long[] __koru_hslot_row = new long[64];
public static long[] __koru_hslot_gen = new long[64];
public static long[] __koru_row_hslot = new long[64];
public static long[] __koru_hslot_free = new long[64];
public static long __koru_hslot_free_len = 0;
public static long __koru_hslot_next = 0;
public static long __koru_brand = 2;
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: 'guarded[...]' 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 'guarded' - 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 'guarded' - 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: 'guarded[...]' 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_ipool {
public static long[] tag = new long[64];
public static dynamic __koru_read_tag(long __h) { long __r = __koru_resolve(__h); return tag[(int)__r]; }
public static long[] hp = new long[64];
public static dynamic __koru_read_hp(long __h) { long __r = __koru_resolve(__h); return hp[(int)__r]; }
public static global::System.Collections.Generic.Dictionary<long, global::System.Collections.Generic.List<long>> __index_tag = 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[64];
public static long[] __koru_hslot_gen = new long[64];
public static long[] __koru_row_hslot = new long[64];
public static long[] __koru_hslot_free = new long[64];
public static long __koru_hslot_free_len = 0;
public static long __koru_hslot_next = 0;
public static long __koru_brand = 3;
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: 'ipool[...]' 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 'ipool' - 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 'ipool' - 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: 'ipool[...]' 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 drain_pool_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
{
long __koru_dn = __koru_store_pool.len;
if (__koru_dn > 0) {
for (long __koru_i = 0; __koru_i < __koru_store_pool.__koru_hslot_next; __koru_i++) {
__koru_store_pool.__koru_hslot_gen[__koru_i] = (__koru_store_pool.__koru_hslot_gen[__koru_i] + 1) % 2097152;
}
__koru_store_pool.__koru_gen0 = false;
__koru_store_pool.len = 0;
__koru_store_pool.__koru_hslot_free_len = 0;
__koru_store_pool.__koru_hslot_next = 0;
__koru_store_pool.__koru_ident = true;
}
}
return default;
}
}
public static class sweep_guarded_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
{
long __koru_i = 0;
while (__koru_i < __koru_store_guarded.len) {
long __koru_len_before = __koru_store_guarded.len;
main_module.__store_qrow_guarded_L70_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.handler(new main_module.__store_qrow_guarded_L70_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.Input { row = __koru_i });
if (__koru_store_guarded.len >= __koru_len_before) __koru_i += 1;
}
}
return default;
}
}
public static class drain_ipool_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
{
long __koru_dn = __koru_store_ipool.len;
if (__koru_dn > 0) {
for (long __koru_i = 0; __koru_i < __koru_store_ipool.__koru_hslot_next; __koru_i++) {
__koru_store_ipool.__koru_hslot_gen[__koru_i] = (__koru_store_ipool.__koru_hslot_gen[__koru_i] + 1) % 2097152;
}
__koru_store_ipool.__koru_gen0 = false;
__koru_store_ipool.len = 0;
__koru_store_ipool.__koru_hslot_free_len = 0;
__koru_store_ipool.__koru_hslot_next = 0;
__koru_store_ipool.__koru_ident = true;
}
}
return default;
}
}
public static class __store_insertf_pool_event {
public struct Input {
public long hp;
public long __site_line;
}
public struct Output {
public string tag;
public long row;
public dynamic full;
}
public static Output handler(Input __koru_input) {
var hp = __koru_input.hp;
var __site_line = __koru_input.__site_line;
if (__koru_store_pool.len >= 64) return new Output { tag = "full", full = new { } };
if (__koru_store_pool.len >= 64) throw new global::System.Exception("std/store: store 'pool' is full (capacity 64) - declared capacity and the `| full` branch are pinned at 690_011");
long __koru_new_row = __koru_store_pool.len;
long __koru_hslot;
if (__koru_store_pool.__koru_hslot_free_len > 0) {
__koru_store_pool.__koru_hslot_free_len -= 1;
__koru_hslot = __koru_store_pool.__koru_hslot_free[__koru_store_pool.__koru_hslot_free_len];
} else {
__koru_hslot = __koru_store_pool.__koru_hslot_next;
__koru_store_pool.__koru_hslot_next += 1;
}
if (!__koru_store_pool.__koru_ident) {
__koru_store_pool.__koru_hslot_row[__koru_hslot] = __koru_new_row;
__koru_store_pool.__koru_row_hslot[__koru_new_row] = __koru_hslot;
}
__koru_store_pool.hp[__koru_new_row] = hp;
__koru_store_pool.len += 1;
if (__site_line > 65) {
main_module.__store_qrow_pool_L65_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.handler(new main_module.__store_qrow_pool_L65_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.Input { row = __koru_new_row });
}
return new Output { tag = "row", row = __koru_store_pool.__koru_handle_of(__koru_new_row) };
return default;
}
}
public static class __store_apply_pool_event {
public struct Input {
public long row;
public long field;
public long value_0;
}
public struct Output {
public string tag;
public long hp;
}
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 __koru_r = row;
switch (field) {
case 0: { __koru_store_pool.hp[__koru_r] = value_0; return new Output { tag = "hp", hp = value_0 }; }
}
throw new global::System.Exception("__store_apply_pool: field index " + field + " is not a column of store 'pool'");
return default;
}
}
public static class __store_qrow_pool_L65_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event {
public struct Input {
public long row;
}
public static dynamic handler(Input __koru_input) {
var row = __koru_input.row;
var __koru_r = row;
main_module.__store_qbody_pool_L65_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.handler(new main_module.__store_qbody_pool_L65_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event.Input { __koru_qrow = __koru_store_pool.__koru_handle_of(__koru_r) });
return default;
}
}
public static class __store_qbody_pool_L65_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event {
public struct Input {
public long __koru_qrow;
}
public static dynamic handler(Input __koru_input) {
var __koru_qrow = __koru_input.__koru_qrow;
var result_0 = main_module.__store_take_pool_event.handler(new __store_take_pool_event.Input { row = (long)(__koru_qrow)});
if (result_0.tag == "item") {
var _auto_16 = result_0.item;
}
if (result_0.tag == "empty") {
var _auto_17 = result_0.empty;
throw new global::System.Exception("__store_take_pool: unhandled panic branch 'empty' fired at runtime");
}
return default;
}
}
public static class __store_qsweep_pool_L65_690_336_take_only_rule_lowers_to_drain_sweep_input_42e0c_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
long __koru_dn = __koru_store_pool.len;
if (__koru_dn > 0) {
for (long __koru_i = 0; __koru_i < __koru_store_pool.__koru_hslot_next; __koru_i++) {
__koru_store_pool.__koru_hslot_gen[__koru_i] = (__koru_store_pool.__koru_hslot_gen[__koru_i] + 1) % 2097152;
}
__koru_store_pool.__koru_gen0 = false;
__koru_store_pool.len = 0;
__koru_store_pool.__koru_hslot_free_len = 0;
__koru_store_pool.__koru_hslot_next = 0;
__koru_store_pool.__koru_ident = true;
}
return default;
}
}
public static class __store_take_pool_event {
public struct Input {
public long row;
}
public struct Output {
public string tag;
public dynamic item;
public dynamic empty;
}
public static Output handler(Input __koru_input) {
var row = __koru_input.row;
__koru_store_pool.__koru_materialize();
long __koru_r = __koru_store_pool.__koru_row_of(row);
if (__koru_r < 0) return new Output { tag = "empty", empty = new { } };
long __koru_gone_slot = __koru_store_pool.__koru_row_hslot[__koru_r];
var __koru_out_hp = __koru_store_pool.hp[__koru_r];
var __koru_last = __koru_store_pool.len - 1;
if (__koru_r != __koru_last) {
__koru_store_pool.hp[__koru_r] = __koru_store_pool.hp[__koru_last];
var __koru_mv_slot = __koru_store_pool.__koru_row_hslot[__koru_last];
__koru_store_pool.__koru_hslot_row[__koru_mv_slot] = __koru_r;
__koru_store_pool.__koru_row_hslot[__koru_r] = __koru_mv_slot;
}
__koru_store_pool.__koru_hslot_row[__koru_gone_slot] = -1;
__koru_store_pool.len = __koru_last;
__koru_store_pool.__koru_hslot_gen[__koru_gone_slot] = ((__koru_store_pool.__koru_hslot_gen[__koru_gone_slot] + 1) & 4294967295L);
__koru_store_pool.__koru_hslot_free[__koru_store_pool.__koru_hslot_free_len] = __koru_gone_slot;
__koru_store_pool.__koru_hslot_free_len += 1;
__koru_store_pool.__koru_gen0 = false;
return new Output { tag = "item", item = new { hp = __koru_out_hp } };
return default;
}
}
public static class __store_insertf_guarded_event {
public struct Input {
public long hp;
public long __site_line;
}
public struct Output {
public string tag;
public long row;
public dynamic full;
}
public static Output handler(Input __koru_input) {
var hp = __koru_input.hp;
var __site_line = __koru_input.__site_line;
if (__koru_store_guarded.len >= 64) return new Output { tag = "full", full = new { } };
if (__koru_store_guarded.len >= 64) throw new global::System.Exception("std/store: store 'guarded' is full (capacity 64) - declared capacity and the `| full` branch are pinned at 690_011");
long __koru_new_row = __koru_store_guarded.len;
long __koru_hslot;
if (__koru_store_guarded.__koru_hslot_free_len > 0) {
__koru_store_guarded.__koru_hslot_free_len -= 1;
__koru_hslot = __kor
... [truncated - 45KB total]Flows
flow ~new click a branch to expand · @labels scroll to their anchor
new (pool, capacity: 64, source: hp: i64)
flow ~new click a branch to expand · @labels scroll to their anchor
new (guarded, capacity: 64, source: hp: i64)
flow ~new click a branch to expand · @labels scroll to their anchor
new (ipool, capacity: 64, source: tag: i64, hp: i64)
flow ~store click a branch to expand · @labels scroll to their anchor
store (expr: ipool, tag, source: <implicit_source>)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (pool, source: hp: 5)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (pool, source: hp: 50)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (pool, source: hp: 8)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (guarded, source: hp: 5)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (guarded, source: hp: 50)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (guarded, source: hp: 8)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (ipool, source: tag: 1, hp: 5)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (ipool, source: tag: 2, hp: 50)
subflow ~drain-pool click a branch to expand · @labels scroll to their anchor
rule (pool)
subflow ~sweep-guarded click a branch to expand · @labels scroll to their anchor
rule (guarded)
subflow ~drain-ipool click a branch to expand · @labels scroll to their anchor
rule (ipool)
flow ~drain-pool click a branch to expand · @labels scroll to their anchor
drain-pool
flow ~sweep-guarded click a branch to expand · @labels scroll to their anchor
sweep-guarded
flow ~drain-ipool click a branch to expand · @labels scroll to their anchor
drain-ipool
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "pool {{ pool.len:d }}")
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "guarded {{ guarded.len:d }}")
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "ipool {{ ipool.len:d }}")
flow ~query click a branch to expand · @labels scroll to their anchor
query (ipool)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (ipool, source: tag: 2, hp: 99)
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "after-refill {{ ipool.len:d }}")
flow ~query click a branch to expand · @labels scroll to their anchor
query (ipool)
Test Configuration
MUST_RUN LANGUAGES: zig cs
Post-validation Script:
#!/bin/bash
# Emitted-shape oracle for the drain lowering. `pool`'s rule body is a
# bare `take(pool[e])` with a discard `| item`, so its invoked sweep is
# the clear unit's canonical reset: every issued slot's generation
# bumps once (`0..hslot_next` covers live rows and slots freed by
# earlier takes), then len, the freelist and the fresh cursor drop to
# zero and `ident` re-arms — no per-row resolve, no column reads, no
# freelist materialization. The observable difference vs a per-row
# take walk is refill pop order: reset reissues slots in fresh order,
# the same slot SET either way. `guarded` carries a `when` clause, so
# its sweep keeps the removal-tolerant `while` that re-checks the index
# swap-remove just refilled.
set -u
if [ ! -f output_emitted.zig ]; then
echo "FAIL: no output_emitted.zig"
exit 1
fi
# --- pool lowered to the drain reset ---
if ! grep -q 'const __koru_dn = __koru_store_pool\.len' output_emitted.zig; then
echo "FAIL: pool's sweep did not lower to the drain reset"
exit 1
fi
POOL_SWEEP=$(awk '/qsweep_pool/,/^ };$/' output_emitted.zig)
if ! printf '%s' "$POOL_SWEEP" | grep -q '__koru_hslot_gen\[__koru_i\] +%= 1'; then
echo "FAIL: drain lost the issued-slot generation bump"
exit 1
fi
if ! printf '%s' "$POOL_SWEEP" | grep -q '__koru_hslot_next = 0'; then
echo "FAIL: drain did not reset the fresh-slot cursor"
exit 1
fi
if ! printf '%s' "$POOL_SWEEP" | grep -q '__koru_hslot_free_len = 0'; then
echo "FAIL: drain did not drop the freelist"
exit 1
fi
if ! printf '%s' "$POOL_SWEEP" | grep -q '__koru_ident = true'; then
echo "FAIL: drain did not re-arm the identity map"
exit 1
fi
if printf '%s' "$POOL_SWEEP" | grep -q '__koru_store_pool\.hp\['; then
echo "FAIL: drain still moves column data — the payload it discards"
exit 1
fi
if printf '%s' "$POOL_SWEEP" | grep -q '__koru_len_before'; then
echo "FAIL: pool kept the per-row tolerant loop — drain did not fire"
exit 1
fi
# --- ipool lowered too: an index decl does not disqualify ---
IPOOL_SWEEP=$(awk '/qsweep_ipool/,/^ };$/' output_emitted.zig)
if ! printf '%s' "$IPOOL_SWEEP" | grep -q 'const __koru_dn = __koru_store_ipool\.len'; then
echo "FAIL: indexed store's take-only rule did not lower to the drain reset"
exit 1
fi
if printf '%s' "$IPOOL_SWEEP" | grep -q '__koru_store_ipool\.\(tag\|hp\)\['; then
echo "FAIL: indexed drain still moves column data"
exit 1
fi
# --- guarded declined: removal-tolerant while kept for it ---
GUARDED_SWEEP=$(awk '/qsweep_guarded/,/^ };$/' output_emitted.zig)
if ! printf '%s' "$GUARDED_SWEEP" | grep -q '__koru_len_before'; then
echo "FAIL: guarded sweep lost its removal-tolerant while"
exit 1
fi
# --- JS lane: same lowering, JS spelling ---
if [ -f output_emitted.js ]; then
if ! grep -q 'const __koru_dn = __koru_store_pool\.len' output_emitted.js; then
echo "FAIL: JS lane did not lower pool's sweep to the drain"
exit 1
fi
if ! grep -q '% 2097152' output_emitted.js; then
echo "FAIL: JS drain lost the 2^21-wrapping generation bump"
exit 1
fi
if ! grep -q '__koru_hslot_next = 0' output_emitted.js; then
echo "FAIL: JS drain did not reset the fresh-slot cursor"
exit 1
fi
fi
echo "PASS: take-only rule lowers to the reset drain; guarded rule keeps tolerant sweep"
exit 0