✓
Passing This code compiles and runs correctly.
Code
// PIN: `@as(i64, @intCast(x))` — the canonical Koru cast — and index-position
// `@intCast(x)` lower through `__koru_intcast`, never bare `@intCast`. Zig's
// @intCast emits an `llvm.assume` (operand-fits hint) at the cast site; inside
// a loop body the vectorizer reads the assume as an opaque call and declines
// the loop — measured 5.9ms scalar vs 1.5ms vectorized for the same
// runtime-bound fold (koru-benchmarks suites/iteration-models). The helper
// bitcasts same-width sign flips in release; Debug/ReleaseSafe keep the real
// fit-check. post.sh pins the emitted spelling, expected.txt the value.
import std/io
capture { sum: 0[i64], g: [4]i64{ 3, 1, 4, 1 } }
! as acc |> for(0..4)
! each i |> captured { sum: acc.sum + @as(i64, @intCast(acc.g[@intCast(i)])) * 3 }
| captured fin |> std/io:print.ln("{{ fin.sum:d }}")
Actual
27
Expected output
27
Flows
flow ~capture click a branch to expand · @labels scroll to their anchor
capture (source: sum: 0[i64], g: [4]i64{ 3, 1, 4, 1 })
Test Configuration
MUST_RUN
Post-validation Script:
#!/bin/bash
# Pin: both cast spellings must lower through __koru_intcast — bare @intCast
# inside a loop body carries an llvm.assume that declines vectorization.
# The helper itself must also be emitted into the preamble.
set -e
grep -q "fn __koru_intcast" output_emitted.zig || {
echo "FAIL: __koru_intcast helper not emitted in preamble"
exit 1
}
grep -q "__koru_intcast(i64," output_emitted.zig || {
echo "FAIL: @as(i64, @intCast(...)) did not lower through __koru_intcast"
exit 1
}
grep -q "__koru_intcast(usize," output_emitted.zig || {
echo "FAIL: index-position @intCast did not lower through __koru_intcast"
exit 1
}