?
Unknown Status unknown.
Code
// Profiler under nested label loops: every loop transition lands in the
// Chrome trace. Loop shape mirrors 205_nested_labels.
const std = @import("std");
~[profile]import std/profiler
// Outer counter event (counts outer iterations)
~tor outer { x: i32, max_inner: i32 }
| next-outer { x: i32, max_inner: i32 }
| done-outer
~proc outer|zig {
std.debug.print("Outer: {}\n", .{x});
if (x < 3) {
return .{ .next_outer = .{ .x = x, .max_inner = max_inner } };
} else {
return .{ .done_outer = .{} };
}
}
// Inner counter event (counts inner iterations)
~tor inner { x: i32, y: i32, max_inner: i32 }
| next-inner { x: i32, y: i32, max_inner: i32 }
| done-inner { x: i32, max_inner: i32 }
~proc inner|zig {
std.debug.print(" Inner: {}, {}\n", .{x, y});
if (y < max_inner) {
return .{ .next_inner = .{ .x = x, .y = y + 1, .max_inner = max_inner } };
} else {
return .{ .done_inner = .{ .x = x + 1, .max_inner = max_inner } };
}
}
// Start event
~tor start {}
~proc start|zig {
std.debug.print("Starting nested loops...\n", .{});
}
// Flow with nested labels
~start() |> #outer_loop outer(x: 1, max_inner: 2)
| next-outer o |> #inner_loop inner(o.x, y: 1, o.max_inner)
| next-inner i |> @inner_loop(i.x, i.y, i.max_inner)
| done-inner d |> @outer_loop(d.x, d.max_inner)
| done-outer |> _
Flows
flow ~start click a branch to expand · @labels scroll to their anchor
start
Test Configuration
MUST_RUN
Compiler Flags:
--profilePost-validation Script:
#!/bin/bash
# Validates the Chrome trace under nested label loops: the program's loop
# transitions are captured, the JSON is closed, and the profiler is invisible
# to itself.
PROFILE_FILE="/tmp/koru_profile.json"
if [ ! -f "$PROFILE_FILE" ]; then
echo "ERROR: no trace at $PROFILE_FILE"
exit 1
fi
if ! grep -q '"traceEvents"' "$PROFILE_FILE"; then
echo "ERROR: missing traceEvents"
cat "$PROFILE_FILE"
exit 1
fi
if ! grep -q '"input:start"' "$PROFILE_FILE"; then
echo "ERROR: input:start transition missing"
cat "$PROFILE_FILE"
exit 1
fi
if ! grep -q '"input:outer"' "$PROFILE_FILE"; then
echo "ERROR: input:outer transition missing"
cat "$PROFILE_FILE"
exit 1
fi
if ! grep -q '"input:inner"' "$PROFILE_FILE"; then
echo "ERROR: input:inner transition missing"
cat "$PROFILE_FILE"
exit 1
fi
# Loop iterations: 3 outer x 2 inner should produce well over 5 transitions
EVENT_COUNT=$(grep -c '"name":' "$PROFILE_FILE")
if [ "$EVENT_COUNT" -lt 5 ]; then
echo "ERROR: Expected at least 5 events, found $EVENT_COUNT"
cat "$PROFILE_FILE"
exit 1
fi
if ! grep -q '^]}$' "$PROFILE_FILE"; then
echo "ERROR: JSON not closed"
cat "$PROFILE_FILE"
exit 1
fi
if grep -qE 'write-event|write-header|write-footer' "$PROFILE_FILE"; then
echo "ERROR: profiler observed itself"
cat "$PROFILE_FILE"
exit 1
fi
echo "✓ Profile generated at $PROFILE_FILE with $EVENT_COUNT events"
exit 0