Help: zig 0.16.0 compiler hung in infinite loop without any info

Hi,

I am new to zig, currently stumble upon issue with zig 0.16.0.

I encountered if the code path has white(true), it can make the zig 0.16.0 compiler hang forever.

// code example (ai generated)
const std = @import("std");

fn comptimeLoop() u32 {
    @setEvalBranchQuota(1_000_000_000);
    var i: u32 = 0;
    while (true) {
        i +%= 1;
    }
    return i;
}

test "compiler hangs at comptime" {
    const result = comptime comptimeLoop();
    try std.testing.expect(result > 0);
}

or a simple test:

test "runtime infinite loop hangs test runner" {
    while (true) {}
}

.

Is it expected for the latest zig compiler?

It’s trying to run this loop 10^9 times, so it makes sense it’s taking forever. Did you try this with a managable number like 1000?

Tests arent run in the compiler. zig test builds a test executable then runs it, so its not the compiler hanging in that case

1 Like