Repository navigation
Description
Current behavior
A valid program can:
- pass
with check - print the correct intermediate values in a
printfvariant - but abort with exit code
134underwith run/with testwhen those same correct values are checked withassert(...)
There is no compiler diagnostic.
Why this is a bug
The spec says:
with run <file>andwith testare normal toolchain commands in §18.5 (docs/with-specification.md, around lines 6980-6988).assert(condition: bool)"Panics if false" instd.testing(docs/with-specification.md, around lines 7258-7268).
In the print-based variant below, the program computes:
sum=10relu=0,0,0,2,5
So the assert-based variant should exit successfully. An abort with exit 134 and no diagnostic is not valid behavior.
Repro
Project layout:
with.tomldemo_pair_1.wdemo_pair_1_print.wlib/demo/core.wlib/demo/errors.wlib/demo/ir.wlib/demo/ir_text.wlib/demo/cpu_interp.wlib/demo/device.wlib/demo/memory.wlib/demo/view.wlib/demo/program.wlib/demo/stream.w
The lib/demo/*.w files are a neutralized demo.* package reproducing a small CPU interpreter/runtime stack; there is no reference to Crux in the module names or imports.
demo_pair_1.w:
use demo.core
use demo.device
use demo.memory
use demo.program
use demo.stream
use demo.view
fn write_i32(mem: *mut Memory, index: i32, value: i32):
let ptr = memory_ptr(mem) as *mut i32
unsafe:
*(ptr + index as i64) = value
fn read_i32(mem: *mut Memory, index: i32) -> i32:
let ptr = memory_ptr(mem) as *mut i32
unsafe: *(ptr + index as i64)
fn reduce_then_relu:
let count: i32 = 4
let n = count as Size
let a_mem = alloc(default_device(), n * 4usize).unwrap()
let out_mem = alloc(default_device(), 4usize).unwrap()
write_i32(a_mem, 0, 1)
write_i32(a_mem, 1, 2)
write_i32(a_mem, 2, 3)
write_i32(a_mem, 3, 4)
write_i32(out_mem, 0, 0)
var src = program_source("main")
src.ir_text = "param a in [N] i32\nparam out inout [] i32\n%0 = const i32 0\n%1 = const i32 4\nloop 0 %0 %1 1\nblock_begin 1\n%4 = load out []\n%5 = load a [@0]\n%6 = add %4 %5\nstore out [] %6\nblock_end 1\nreturn\n"
let prog = compile(default_device(), src).unwrap()
let entries: Vec[BindEntry] = Vec.new()
entries.push(bind("a", view_contiguous(a_mem, shape1(n), .Int32)))
entries.push(bind("out", view_contiguous(out_mem, shape_scalar(), .Int32)))
let stream = stream_create(default_device())
let event = dispatch(stream, prog, bindings_from(entries)).unwrap()
assert(event_is_done(event))
assert(read_i32(out_mem, 0) == 10)
event_destroy(event)
stream_destroy(stream)
program_destroy(prog)
free(a_mem)
free(out_mem)
let count2: i32 = 5
let n2 = count2 as Size
let bytes2 = n2 * 4usize
let a2 = alloc(default_device(), bytes2).unwrap()
let out2 = alloc(default_device(), bytes2).unwrap()
write_i32(a2, 0, -3)
write_i32(a2, 1, -1)
write_i32(a2, 2, 0)
write_i32(a2, 3, 2)
write_i32(a2, 4, 5)
var src2 = program_source("main")
src2.ir_text = "param a in [N] i32\nparam out out [N] i32\n%0 = const i32 0\n%1 = const i32 5\n%2 = const i32 0\nparallel 0 %0 %1 1\nblock_begin 1\n%5 = load a [@0]\n%6 = lt %5 %2\n%7 = select %6 %2 %5\nstore out [@0] %7\nblock_end 1\nreturn\n"
let prog2 = compile(default_device(), src2).unwrap()
let entries2: Vec[BindEntry] = Vec.new()
entries2.push(bind("a", view_contiguous(a2, shape1(n2), .Int32)))
entries2.push(bind("out", view_contiguous(out2, shape1(n2), .Int32)))
let stream2 = stream_create(default_device())
let event2 = dispatch(stream2, prog2, bindings_from(entries2)).unwrap()
assert(event_is_done(event2))
assert(read_i32(out2, 0) == 0)
assert(read_i32(out2, 1) == 0)
assert(read_i32(out2, 2) == 0)
assert(read_i32(out2, 3) == 2)
assert(read_i32(out2, 4) == 5)
event_destroy(event2)
stream_destroy(stream2)
program_destroy(prog2)
free(a2)
free(out2)
fn main:
reduce_then_relu()
demo_pair_1_print.w is the same shape, but it prints the computed values instead of asserting them:
use c_import("stdio.h")
// same imports and helpers as above
// same two dispatches as above
// print the first result and the five relu outputs with printf instead of asserting them
Observed results:
$ with check demo_pair_1.w
ok
$ with run demo_pair_1.w
# no diagnostic
# exit 134
$ with test demo_pair_1.w
# no diagnostic
# exit 134
$ with run demo_pair_1_print.w
sum=10
relu=0,0,0,2,5
# exit 0Expected behavior
Because the printed values are correct, the assert-based variant should also exit 0.
If an assertion is actually false, the runtime should report that assertion failure clearly. It should not silently abort with exit 134.
Activity
Fix imported discriminator enum codegen
test(windows): un-skip 4 stale #802 behavior tests