Zig 0.12.0 fails to compile my project

I have a small and rather simple project (https://github.com/GigaGrunch/trecker) which I’m trying to upgrade from 0.11.0 to 0.12.0. It has a branch (zig-0.12.0) where I already fixed all errors the compiler gave me. Now, it doesn’t really give me anything, but still fails. Does anyone have any pointers for me? This is the entire message:

Output
➜  trecker zig build
install
└─ install trecker
   └─ zig build-exe trecker Debug native failure
error: the following command exited with error code 5:
<...>\zig-windows-x86_64-0.12.0\zig.exe build-exe -ODebug -Mroot=<...>\trecker\src\main.zig --cache-dir <...>\trecker\zig-cache --global-cache-dir <...>\zig --name trecker --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install trecker transitive failure
   └─ zig build-exe trecker Debug native failure
error: the following build command failed with exit code 1:
<...>\trecker\zig-cache\o\a61932efe6ef5cde600d6e0eb330f9b1\build.exe <...>\zig-windows-x86_64-0.12.0\zig.exe <...>\trecker <...>\trecker\zig-cache <...>\zig --seed 0xd9bdf076 -Z1d60cd1b1018597b

Oh, that’s a nasty error. I also had this when updating my zig version a few weeks ago: Compiler fails to report compiler errors after update, assertion failure in debug builds. · Issue #19514 · ziglang/zig · GitHub

My solution was to just go through the code and comment out blocks of code with if(false) {...} starting in the main function until the compiler decided to give me proper error messages. Then I fixed those errors and gradually commented more code back in.

3 Likes

Thank’s for the reply! While it doesn’t sound like a good solution for bigger projects, I think it shouldn’t take too long for this one :smiley:
In that case though, I should probably document it and report an issue.
I’ll report back here first if it works out.

@IntegratedQuantum Also thanks for the if (false) tip! That’s much smoother than regular comments because you don’t have to deal with new compiler errors about unused variables.

The problem seems to be my usage of std.mem.sort. I actually wanted to have 2 arrays and sort them by the values of one of them. I didn’t know how to do that so I used one array of tuples instead.

std.mem.sort(struct { *Project, f64 }, project_hours, {}, moreHours);
fn moreHours(context: void, lhs: struct { *Project, f64 }, rhs: struct { *Project, f64 }) bool {
    _ = context;
    return lhs[1] > rhs[1];
}

After correcting some trivial var to const errors:

> zig build-exe src/main.zig
'zig build-exe src/main.zig' terminated by signal SIGSEGV (Address boundary error)

:boom: the compiler crashed
Debugging, without zig debug symbols, does not help.

lldb zig build-exe src/main.zig
(lldb) target create "zig"
Current executable set to 'zig' (x86_64).
(lldb) settings set -- target.run-args  "build-exe" "src/main.zig"
(lldb) run
Process 373164 launched: '/home/din/bin/zig' (x86_64)
Process 373164 stopped
* thread #1, name = 'zig', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #0: 0x00000000097ab8ea zig`___lldb_unnamed_symbol167997 + 58
zig`___lldb_unnamed_symbol167997:
->  0x97ab8ea <+58>: movzbl (%rcx,%r9), %edx
    0x97ab8ef <+63>: movl   (%rax,%r9,4), %r14d
    0x97ab8f3 <+67>: movslq %r14d, %r9
    0x97ab8f6 <+70>: leal   -0x1(%rdx), %r10d
(lldb) bt
* thread #1, name = 'zig', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
  * frame #0: 0x00000000097ab8ea zig`___lldb_unnamed_symbol167997 + 58
    frame #1: 0x0000000009737498 zig`___lldb_unnamed_symbol167636 + 168
    frame #2: 0x00000000097af52c zig`___lldb_unnamed_symbol168022 + 204
    frame #3: 0x00000000097d3563 zig`___lldb_unnamed_symbol168148 + 563
    frame #4: 0x000000000980f8ba zig`___lldb_unnamed_symbol168267 + 4090
    frame #5: 0x0000000009be13de zig`___lldb_unnamed_symbol171512 + 574
    frame #6: 0x000000000980ed52 zig`___lldb_unnamed_symbol168267 + 1170
    frame #7: 0x00000000097fabd8 zig`___lldb_unnamed_symbol168165 + 600
    frame #8: 0x0000000009870316 zig`___lldb_unnamed_symbol168653 + 1046
    frame #9: 0x0000000009868886 zig`___lldb_unnamed_symbol168629 + 3014
    frame #10: 0x00000000098656d2 zig`___lldb_unnamed_symbol168624 + 2258
    frame #11: 0x00000000097d712f zig`___lldb_unnamed_symbol168154 + 14079
    frame #12: 0x000000000987c619 zig`___lldb_unnamed_symbol168692 + 4185
    frame #13: 0x000000000987b3f6 zig`___lldb_unnamed_symbol168690 + 22
    frame #14: 0x000000000987afd6 zig`___lldb_unnamed_symbol168687 + 614
    frame #15: 0x0000000009c5f4c7 zig`___lldb_unnamed_symbol171853 + 1351
    frame #16: 0x0000000009c5ea36 zig`___lldb_unnamed_symbol171852 + 358
    frame #17: 0x00000000097f502c zig`___lldb_unnamed_symbol168154 + 136700
    frame #18: 0x0000000009c5e017 zig`___lldb_unnamed_symbol171850 + 903
    frame #19: 0x00000000097f5892 zig`___lldb_unnamed_symbol168154 + 138850
    frame #20: 0x0000000009c5fe67 zig`___lldb_unnamed_symbol171855 + 231
    frame #21: 0x00000000097d41a8 zig`___lldb_unnamed_symbol168154 + 1912
    frame #22: 0x0000000009c60caf zig`___lldb_unnamed_symbol171859 + 15
    frame #23: 0x0000000009c5e400 zig`___lldb_unnamed_symbol171850 + 1904
    frame #24: 0x00000000097f5892 zig`___lldb_unnamed_symbol168154 + 138850
    frame #25: 0x0000000009c5fe67 zig`___lldb_unnamed_symbol171855 + 231
    frame #26: 0x00000000097d41a8 zig`___lldb_unnamed_symbol168154 + 1912
    frame #27: 0x0000000009c60caf zig`___lldb_unnamed_symbol171859 + 15
    frame #28: 0x0000000009c5e400 zig`___lldb_unnamed_symbol171850 + 1904
    frame #29: 0x00000000097f5892 zig`___lldb_unnamed_symbol168154 + 138850
    frame #30: 0x0000000009c5fe67 zig`___lldb_unnamed_symbol171855 + 231
    frame #31: 0x00000000097d41a8 zig`___lldb_unnamed_symbol168154 + 1912
    frame #32: 0x0000000009c60caf zig`___lldb_unnamed_symbol171859 + 15
    frame #33: 0x0000000009c5e400 zig`___lldb_unnamed_symbol171850 + 1904
    frame #34: 0x00000000097f5892 zig`___lldb_unnamed_symbol168154 + 138850
    frame #35: 0x0000000009c5fe67 zig`___lldb_unnamed_symbol171855 + 231
    frame #36: 0x00000000097d41a8 zig`___lldb_unnamed_symbol168154 + 1912
    frame #37: 0x000000000987c619 zig`___lldb_unnamed_symbol168692 + 4185
    frame #38: 0x000000000987b3f6 zig`___lldb_unnamed_symbol168690 + 22
    frame #39: 0x000000000987afd6 zig`___lldb_unnamed_symbol168687 + 614
    frame #40: 0x0000000009c5f4c7 zig`___lldb_unnamed_symbol171853 + 1351
    frame #41: 0x0000000009c00715 zig`___lldb_unnamed_symbol171597 + 37
    frame #42: 0x00000000097db9e3 zig`___lldb_unnamed_symbol168154 + 32691
    frame #43: 0x0000000009c5fe67 zig`___lldb_unnamed_symbol171855 + 231
    frame #44: 0x00000000097d41a8 zig`___lldb_unnamed_symbol168154 + 1912
    frame #45: 0x0000000009c5fe67 zig`___lldb_unnamed_symbol171855 + 231
    frame #46: 0x0000000009ca95b8 zig`___lldb_unnamed_symbol172259 + 504
    frame #47: 0x0000000009c9fc1a zig`___lldb_unnamed_symbol172241 + 1722
    frame #48: 0x0000000009c0bad6 zig`___lldb_unnamed_symbol171614 + 9606
    frame #49: 0x00000000097dd572 zig`___lldb_unnamed_symbol168154 + 39746
    frame #50: 0x00000000098672e8 zig`___lldb_unnamed_symbol168624 + 9448
    frame #51: 0x00000000097d6b32 zig`___lldb_unnamed_symbol168154 + 12546
    frame #52: 0x00000000098672e8 zig`___lldb_unnamed_symbol168624 + 9448
    frame #53: 0x00000000097d6b32 zig`___lldb_unnamed_symbol168154 + 12546
    frame #54: 0x0000000009870129 zig`___lldb_unnamed_symbol168653 + 553
    frame #55: 0x000000000986615a zig`___lldb_unnamed_symbol168624 + 4954
    frame #56: 0x00000000097d712f zig`___lldb_unnamed_symbol168154 + 14079
    frame #57: 0x000000000987c619 zig`___lldb_unnamed_symbol168692 + 4185
    frame #58: 0x00000000096e109a zig`___lldb_unnamed_symbol167559 + 3002
    frame #59: 0x00000000096c987a zig`___lldb_unnamed_symbol167472 + 16954
    frame #60: 0x00000000096c46c3 zig`___lldb_unnamed_symbol167470 + 387
    frame #61: 0x00000000094be596 zig`___lldb_unnamed_symbol166143 + 70310
    frame #62: 0x00000000094a44fc zig`___lldb_unnamed_symbol166127 + 3148
    frame #63: 0x00000000094a383b zig`___lldb_unnamed_symbol166125 + 267
    frame #64: 0x000000000a0cf868 zig`___lldb_unnamed_symbol175901 + 2248
(lldb) 

I was able to solve my initial problem with the MultiArrayList and no longer have the std.mem.sort issue. I will report that bug(?) in the GitHub repo though.

Good opportunity to checkout zig reduce to minimize the code example if you’re up to it.

2 Likes

Wow, that’s an awesome tool! I didn’t know about that. Took some time to get the checker executable right, but it seems to have worked. I boiled it down to this. This crashes the compiler:

const std = @import("std");

var global_slice: []void = undefined;

pub fn main() void {
    var local_array: [0]void = undefined;

    for (global_slice) |_| {
        _ = std.mem.indexOfScalar(void, local_array[0..undefined], undefined);
    }
}

Ok, it got even smaller after I tried some manual modifications.

pub fn main() void {
    var array: [0]void = undefined;
    _ = array[0..undefined];
}

I’m not completely sure if that’s really still the same issue, but I’ll just document my journey in the GitHub issue.

And here is the GitHub issue: Compiler crashes when taking slice with undefined length · Issue #19735 · ziglang/zig · GitHub

compilation 16769 lignes zig 0.12.0 sans erreur

I compiled my project of 16769 lines with Zig 0.12.0 without any errors (except for ‘var’ and ‘const’ and a few changes in the build and acces terminal). I noticed that memory cleanup is much more responsive, at least for my application. As for compilation time, I have a powerful computer with 32GB of RAM, a Xeon processor, and SSD memory (flash), so I don’t really see much of a difference.