PackedIntArray at comptime

Hey folks,

I’m generating some lookup tables at comptime, and wanted to look at storing this data more compactly, thought using PackedIntArray at comptime would be a good choice.

I’m hitting an error using packed structs with a backing integer type of u10. Repro case is below:

const std = @import("std");

const LookupTable = std.PackedIntArray(u10, 256);

fn makeLookupTable() LookupTable {
    @setEvalBranchQuota(10_0000);
    var table: LookupTable = undefined;
    for (0..256) |i| {
        table.set(i, @truncate(i));
    }
    return table;
}

const lookupTable = makeLookupTable();

export fn example() void {
    _ = lookupTable.get(0);
}

This gives the following error using 0.11 (and trunk): error: comptime dereference requires 'packed_int_array.PackedIntArrayEndian(u10,.Little,256)' to have a well-defined layout, but it does not.

Changing the type to u9 makes this case compile fine. Any tips on why using u10 is not “well-defined” during comptime? Thanks!

(Interestingly u10, u11 and u12 all fail this way, but u1-u9 and u13-u16 are fine!)

Looks like bug #19452

Thanks, I’ll report an issue then, good to know that I’m not misunderstanding some expected behaviour…

Update: reported at std.PackedIntArray fails for some int types at comptime · Issue #19627 · ziglang/zig · GitHub