001 pure proc annotation

✓ Passing This code compiles and runs correctly.

Code

// Layer 3 demonstration: ~[pure] annotation on a proc lifts the
// assume-impure default. The proc gets is_pure=true and (since it
// has no calls) is_transitively_pure=true.

const std = @import("std");

~event compute { x: i32 }
| result i32

~[pure] proc compute|zig {
    return .{ .result = x * 2 };
}

~event main {}

~compute(x: 21)
| result _ |> _
input.kz

Test Configuration

MUST_RUN

Post-validation Script:

#!/bin/bash
# Verify: ~[pure] proc gets is_pure=true and is_transitively_pure=true.
# Layer 3 demonstration: annotation lifts the default impure assumption.

if [ ! -f "backend.zig" ]; then
    echo "✗ backend.zig not found"
    exit 1
fi

# AST literal moved from backend.zig to program_ast.zig (split landed 2026-05-20).
# Concatenate both so grep -n / sed -n by line number still work.
cat backend.zig program_ast.zig 2>/dev/null > _combined_emit.zig

PROC_LINE=$(grep -n 'proc_decl = ProcDecl' _combined_emit.zig | while read line; do
    linenum=$(echo "$line" | cut -d: -f1)
    if sed -n "$((linenum)),$((linenum + 5))p" _combined_emit.zig | grep -q '"compute"'; then
        echo "$linenum"
        break
    fi
done)

if [ -z "$PROC_LINE" ]; then
    echo "✗ Could not find compute proc"
    exit 1
fi

PROC=$(sed -n "$((PROC_LINE)),$((PROC_LINE + 15))p" _combined_emit.zig)

if echo "$PROC" | grep -q 'is_pure = true'; then
    echo "✓ compute proc: is_pure = true (annotation lifted default)"
else
    echo "✗ FAIL: compute should be is_pure = true (has ~[pure] annotation)"
    exit 1
fi

if echo "$PROC" | grep -q 'is_transitively_pure = true'; then
    echo "✓ compute proc: is_transitively_pure = true (no calls, so trivially transitive)"
else
    echo "✗ FAIL: compute should be is_transitively_pure = true"
    exit 1
fi

echo ""
echo "✓ ~[pure] annotation correctly propagates to is_pure=true and is_transitively_pure=true"
exit 0