006 coordinator timing

✓ Passing This code compiles and runs correctly.

Code

// MUST_FAIL: Function calls in branch constructors must be rejected
//
// Branch constructors must be pure — no side effects. Calling
// std.fmt.allocPrint inside a branch constructor violates this rule.
// Use event chaining to compute values before constructing the branch.

~import "$std/compiler"
~import "$std/io"

const std = @import("std");

// This should fail: allocPrint is a function call in a branch constructor
~std.compiler:coordinate =
    std.compiler:coordinate.default(program_ast, allocator)
    | coordinated c |> coordinated {
        ast: c.ast,
        code: c.code,
        metrics: std.fmt.allocPrint(allocator, "done in {d}ms", .{}) catch "error"
    }
    | error e |> error { message: e.message }

~std.io:print.ln("should not compile")
input.kz

Test Configuration

Expected Behavior:

FRONTEND_COMPILE_ERROR

Expected Error:

branch constructor field 'metrics' contains a function call

Post-validation Script:

#!/bin/bash
# Post-validation: Verify timing instrumentation worked
#
# Checks that:
# 1. Timer output appears in backend.err
# 2. Timing value is reasonable (> 0ms, < 60000ms)

set -e

if [ ! -f "backend.err" ]; then
    echo "❌ FAIL: No backend.err file found"
    exit 1
fi

# Extract the timing line
TIMING_LINE=$(grep "⏱️  Compilation took" backend.err || true)

if [ -z "$TIMING_LINE" ]; then
    echo "❌ FAIL: No timing output found in backend.err"
    echo "   Expected: ⏱️  Compilation took X.XXms"
    exit 1
fi

# Extract the milliseconds value
MS=$(echo "$TIMING_LINE" | sed -n 's/.*took \([0-9.]*\)ms.*/\1/p')

if [ -z "$MS" ]; then
    echo "❌ FAIL: Could not parse timing value from: $TIMING_LINE"
    exit 1
fi

# Validate timing is reasonable (using awk for float comparison)
VALID=$(awk -v ms="$MS" 'BEGIN { print (ms > 0 && ms < 60000) ? "yes" : "no" }')

if [ "$VALID" != "yes" ]; then
    echo "❌ FAIL: Timing value out of range: ${MS}ms"
    echo "   Expected: 0 < ms < 60000"
    exit 1
fi

echo "✅ Timing instrumentation working: ${MS}ms"
exit 0