038 interpreter nested loop benchmark

✗ Failing This test is currently failing.

Failed: backend-exec

Error Details

install

Failure Output

Showing last 10 of 26 lines
error: the following command failed with 1 compilation errors:
/opt/homebrew/Cellar/zig/0.15.2_1/bin/zig build-exe -ODebug --dep koru_parser --dep koru_ast=ast --dep koru_errors=errors --dep ast --dep flow_parser --dep liquid -Mroot=/Users/larsde/src/koru/tests/regression/400_RUNTIME_FEATURES/430_RUNTIME/430_038_interpreter_nested_loop_benchmark/output_emitted.zig -ODebug --dep ast --dep lexer --dep errors --dep type_registry --dep expression_parser --dep union_collector --dep module_resolver -Mkoru_parser=/usr/local/lib/koru/src/parser.zig -ODebug --dep errors -Mast=/usr/local/lib/koru/src/ast.zig -ODebug -Merrors=/usr/local/lib/koru/src/errors.zig -ODebug --dep ast --dep lexer --dep errors --dep expression_parser -Mflow_parser=/usr/local/lib/koru/src/flow_parser.zig -ODebug -Mliquid=/usr/local/lib/koru/src/liquid.zig -ODebug -Mlexer=/usr/local/lib/koru/src/lexer.zig -ODebug --dep ast --dep log -Mtype_registry=/usr/local/lib/koru/src/type_registry.zig -ODebug --dep lexer --dep ast -Mexpression_parser=/usr/local/lib/koru/src/expression_parser.zig -ODebug --dep ast -Munion_collector=/usr/local/lib/koru/src/union_collector.zig -ODebug --dep config --dep log -Mmodule_resolver=/usr/local/lib/koru/src/module_resolver.zig -ODebug -Mlog=/usr/local/lib/koru/src/log.zig -ODebug --dep log -Mconfig=/usr/local/lib/koru/src/config.zig --cache-dir .zig-cache --global-cache-dir /Users/larsde/.cache/zig --name output --zig-lib-dir /opt/homebrew/Cellar/zig/0.15.2_1/lib/zig/ --listen=-

Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
+- install output transitive failure
   +- compile exe output Debug native 1 errors

error: the following build command failed with exit code 1:
.zig-cache/o/ab7734ce170e335c623eadd760da5c97/build /opt/homebrew/Cellar/zig/0.15.2_1/bin/zig /opt/homebrew/Cellar/zig/0.15.2_1/lib/zig /Users/larsde/src/koru/tests/regression/400_RUNTIME_FEATURES/430_RUNTIME/430_038_interpreter_nested_loop_benchmark .zig-cache /Users/larsde/.cache/zig --seed 0xd6614d03 -Zbe26c46549fd6874

Code

// HONEST APPLES-TO-APPLES BENCHMARK
//
// Python:   for _ in range(1000): for i in range(100): add("0", str(i))
// Koru:     ~for(0..1000) | each _ |> for(0..100) | each i |> add(...)
//
// Same syntax as compiled Koru. Same parser. Just interpreted.

~import "$std/runtime"
~import "$std/interpreter"
~import "$std/io"

const std = @import("std");

// Global accumulator - updated by add()
var global_sum: i64 = 0;

// add() updates global accumulator - same work as Python
~pub event add { a: []const u8, b: []const u8 }
| sum []const u8

~proc add {
    const a_int = std.fmt.parseInt(i64, a, 10) catch 0;
    const b_int = std.fmt.parseInt(i64, b, 10) catch 0;
    global_sum += a_int + b_int;
    return .{ .sum = "0" };  // Result not used, just like Python
}

// Get the accumulated sum for verification
pub fn getSum() i64 {
    return global_sum;
}

pub fn resetSum() void {
    global_sum = 0;
}

// Register events
~std.runtime:register(scope: "bench") {
    for
    add
}

// Same pattern as 230_012_for_binding_in_nested_range
const BENCH_FLOW =
    \\~for(0..1000)
    \\| each _ |> for(0..100)
    \\    | each i |> add(a: "0", b: i)
    \\| done |> _
;

pub fn main() void {
    std.debug.print("\n", .{});
    std.debug.print("============================================================\n", .{});
    std.debug.print("HONEST APPLES-TO-APPLES BENCHMARK\n", .{});
    std.debug.print("Task: for(0..1000) | each |> for(0..100) | each |> add()\n", .{});
    std.debug.print("      = 100,000 add dispatches\n", .{});
    std.debug.print("============================================================\n\n", .{});

    const start = std.time.nanoTimestamp();

    const result = koru_std.interpreter.run_event.handler(.{
        .source = BENCH_FLOW,
        .dispatcher = &dispatch_bench,
        .cost_fn = null,
        .creates_obligations_fn = null,
        .discharges_obligations_fn = null,
        .discharge_event_fn = null,
        .budget = null,
        .handle_pool = null,
    });

    const end = std.time.nanoTimestamp();
    const total_ns = end - start;
    const total_ms = @divTrunc(total_ns, 1_000_000);

    // Expected: sum(0..99) * 1000 = 4950 * 1000 = 4,950,000
    const expected: i64 = 4950000;
    const actual = getSum();

    switch (result) {
        .result => |r| {
            std.debug.print("Completed: branch={s}\n", .{r.value.branch});
            std.debug.print("Sum: {d} (expected: {d})\n", .{actual, expected});
            std.debug.print("Correct: {}\n", .{actual == expected});
            std.debug.print("Time: {d} ms\n", .{total_ms});
        },
        .exhausted => |e| {
            std.debug.print("EXHAUSTED: {s}\n", .{e.last_event});
        },
        .parse_error => |e| {
            std.debug.print("PARSE ERROR: {s} at line {d}\n", .{e.message, e.line});
        },
        .validation_error => |e| {
            std.debug.print("VALIDATION ERROR: {s}\n", .{e.message});
        },
        .dispatch_error => |e| {
            std.debug.print("DISPATCH ERROR: {s} - {s}\n", .{e.event_name, e.message});
        },
    }

    std.debug.print("\nCompare: python3 benchmark.py\n", .{});
    std.debug.print("============================================================\n", .{});
}
input.kz

Test Configuration

MUST_RUN