hexops / mach

zig game engine & graphics toolkit
https://machengine.org
Other
3.4k stars 161 forks source link

core: autodoc segfaults the build if enabled, after Zig 2024.1.0-mach update #1145

Open slimsag opened 10 months ago

slimsag commented 10 months ago

We had to disable autodoc generation because it segfaults the build after the Zig 2024.1.0-mach update #1135

(lldb) run
Process 94093 launched: '/Users/slimsag/zig/0.12.0-dev.2063+804cee3b9/files/zig' (arm64)
Generating documentation... Process 94093 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x15d)
    frame #0: 0x00000001000e2038 zig`Module.File.getSource + 36
zig`Module.File.getSource:
->  0x1000e2038 <+36>: ldrb   w8, [x1, #0x15d]
    0x1000e203c <+40>: tbz    w8, #0x0, 0x1000e2058     ; <+68>
    0x1000e2040 <+44>: ldp    x8, x9, [x23, #0x30]
    0x1000e2044 <+48>: strh   wzr, [x19, #0x30]
Target 0: (zig) stopped.
(lldb) up
frame #1: 0x00000001000e2330 zig`Autodoc.getTLDocComment + 64
zig`Autodoc.getTLDocComment:
->  0x1000e2330 <+64>: ldrh   w8, [sp, #0x50]
    0x1000e2334 <+68>: cbz    w8, 0x1000e2340           ; <+80>
    0x1000e2338 <+72>: strh   w8, [x19, #0x10]
    0x1000e233c <+76>: b      0x1000e2520               ; <+560>
(lldb)
frame #2: 0x00000001000ef5d0 zig`Autodoc.walkInstruction + 25888
zig`Autodoc.walkInstruction:
->  0x1000ef5d0 <+25888>: ldrh   w8, [sp, #0x328]
    0x1000ef5d4 <+25892>: cbnz   w8, 0x1000f0c2c           ; <+31612>
    0x1000ef5d8 <+25896>: ldr    x8, [sp, #0x318]
    0x1000ef5dc <+25900>: ldr    x9, [sp, #0x320]
(lldb)
frame #3: 0x0000000100237dc0 zig`Autodoc.walkRef + 152
zig`Autodoc.walkRef:
->  0x100237dc0 <+152>: ldp    q0, q1, [sp, #0x90]
    0x100237dc4 <+156>: stp    q0, q1, [x19, #0x80]
    0x100237dc8 <+160>: ldp    q0, q1, [sp, #0xb0]
    0x100237dcc <+164>: stp    q0, q1, [x19, #0xa0]
(lldb)
frame #4: 0x00000001000ef79c zig`Autodoc.walkInstruction + 26348
zig`Autodoc.walkInstruction:
->  0x1000ef79c <+26348>: ldr    q0, [sp, #0x7eb0]
    0x1000ef7a0 <+26352>: ldr    q1, [sp, #0x7ec0]
    0x1000ef7a4 <+26356>: stp    q0, q1, [x19, #0x80]
    0x1000ef7a8 <+26360>: ldr    q0, [sp, #0x7ed0]
(lldb)
frame #5: 0x000000010023d194 zig`Autodoc.analyzeAllDecls + 2588
zig`Autodoc.analyzeAllDecls:
->  0x10023d194 <+2588>: ldrh   w0, [sp, #0x260]
    0x10023d198 <+2592>: cbnz   w0, 0x10023d854           ; <+4316>
    0x10023d19c <+2596>: ldp    q0, q1, [sp, #0x230]
    0x10023d1a0 <+2600>: stp    q0, q1, [sp, #0x2f0]
(lldb)
frame #6: 0x00000001000f280c zig`Autodoc.walkInstruction + 38748
zig`Autodoc.walkInstruction:
->  0x1000f280c <+38748>: add    x9, sp, #0x9, lsl #12     ; =0x9000
    0x1000f2810 <+38752>: add    x9, x9, #0xbd8
    0x1000f2814 <+38756>: ldrh   w8, [x22, #0x610]
    0x1000f2818 <+38760>: cbnz   w8, 0x1000f085c           ; <+30636>
(lldb)
frame #7: 0x00000001000e7968 zig`Autodoc.generateZirData + 4356
zig`Autodoc.generateZirData:
->  0x1000e7968 <+4356>: ldrh   w21, [x27, #0xdd8]
    0x1000e796c <+4360>: cbnz   w21, 0x1000e7b58          ; <+4852>
    0x1000e7970 <+4364>: ldr    x8, [sp, #0x108]
    0x1000e7974 <+4368>: ldr    w8, [x8, #0x118]
(lldb)
frame #8: 0x00000001000f70d0 zig`Compilation.flush + 2012
zig`Compilation.flush:
->  0x1000f70d0 <+2012>: tst    w0, #0xffff
    0x1000f70d4 <+2016>: b.eq   0x1000f7110               ; <+2076>
    0x1000f70d8 <+2020>: mov    x20, x0
    0x1000f70dc <+2024>: ldr    x1, [sp, #0x900]
(lldb)
frame #9: 0x00000001000fa958 zig`Compilation.update + 12720
zig`Compilation.update:
->  0x1000fa958 <+12720>: tst    w0, #0xffff
    0x1000fa95c <+12724>: b.eq   0x1000fab90               ; <+13288>
    0x1000fa960 <+12728>: mov    x25, x0
    0x1000fa964 <+12732>: mov    x0, x27
(lldb)
frame #10: 0x000000010010a59c zig`main.updateModule + 280
zig`main.updateModule:
->  0x10010a59c <+280>: mov    x21, x0
    0x10010a5a0 <+284>: and    w23, w0, #0xffff
    0x10010a5a4 <+288>: add    x0, sp, #0x8
    0x10010a5a8 <+292>: bl     0x1000d551c               ; Progress.Node.end
(lldb)
frame #11: 0x0000000100127d68 zig`main.buildOutputType + 113300
zig`main.buildOutputType:
->  0x100127d68 <+113300>: ands   w8, w0, #0xffff
    0x100127d6c <+113304>: b.eq   0x100127ec8               ; <+113652>
    0x100127d70 <+113308>: cmp    w8, #0x76
    0x100127d74 <+113312>: b.ne   0x100127edc               ; <+113672>
(lldb)
frame #12: 0x000000010001eed4 zig`main.main + 6100
zig`main.main:
->  0x10001eed4 <+6100>: mov    x20, x0
    0x10001eed8 <+6104>: ldr    x1, [sp, #0x190]
    0x10001eedc <+6108>: cbz    x1, 0x10001dc64           ; <+1380>
    0x10001eee0 <+6112>: ldp    x21, x2, [x1]
(lldb)
frame #13: 0x000000010001d6ac zig`main + 96
zig`main:
->  0x10001d6ac <+96>:  tst    w0, #0xffff
    0x10001d6b0 <+100>: b.ne   0x10001d6c4               ; <+120>
    0x10001d6b4 <+104>: mov    w0, #0x0
    0x10001d6b8 <+108>: ldp    x29, x30, [sp, #0x20]
(lldb)
frame #14: 0x000000018c7590e0 dyld`start + 2360
dyld`start:
->  0x18c7590e0 <+2360>: mov    x20, x0
    0x18c7590e4 <+2364>: ldr    x8, [x19, #0x8]
    0x18c7590e8 <+2368>: ldr    w0, [x8, #0x44]
    0x18c7590ec <+2372>: mov    x1, #0x0
(lldb)
error: Already at the top of the stack.
(lldb)
error: Already at the top of the stack.
(lldb)
error: Already at the top of the stack.
(lldb) q
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n]
ianprime0509 commented 10 months ago

This is the stack trace I get with a debug build of Zig 0.12.0-dev.2063+804cee3b9:

``` thread 573250 panic: attempt to unwrap error: ModuleNotFound /var/home/ian/src/zig-worktrees/mach/src/Module.zig:3906:9: 0x1b170e3 in importFile (zig) return error.ModuleNotFound; ^ /var/home/ian/src/zig-worktrees/mach/src/Autodoc.zig:1061:76: 0x17cdedf in walkInstruction (zig) const new_file = self.comp_module.importFile(file, path) catch unreachable; ^ /var/home/ian/src/zig-worktrees/mach/src/Autodoc.zig:5728:36: 0x1b19939 in walkRef (zig) return self.walkInstruction( ^ /var/home/ian/src/zig-worktrees/mach/src/Autodoc.zig:2849:32: 0x17e1ab5 in walkInstruction (zig) return self.walkRef( ^ /var/home/ian/src/zig-worktrees/mach/src/Autodoc.zig:4261:49: 0x1e74046 in analyzeDecl (zig) const walk_result = try self.walkInstruction( ^ /var/home/ian/src/zig-worktrees/mach/src/Autodoc.zig:4142:29: 0x1b29ee5 in analyzeAllDecls (zig) try self.analyzeDecl( ^ /var/home/ian/src/zig-worktrees/mach/src/Autodoc.zig:3850:59: 0x17ecfaf in walkInstruction (zig) extra_index = try self.analyzeAllDecls( ^ /var/home/ian/src/zig-worktrees/mach/src/Autodoc.zig:332:33: 0x17c7375 in generateZirData (zig) _ = try self.walkInstruction( ^ /var/home/ian/src/zig-worktrees/mach/src/Autodoc.zig:91:32: 0x17f82be in generate (zig) try autodoc.generateZirData(output_dir); ^ /var/home/ian/src/zig-worktrees/mach/src/Compilation.zig:2414:33: 0x17f879c in maybeGenerateAutodocs (zig) try Autodoc.generate(mod, dir); ^ /var/home/ian/src/zig-worktrees/mach/src/Compilation.zig:2347:34: 0x17f8bf0 in flush (zig) try maybeGenerateAutodocs(comp, prog_node); ^ /var/home/ian/src/zig-worktrees/mach/src/Compilation.zig:2311:22: 0x17fc951 in update (zig) try flush(comp, arena, main_progress_node); ^ /var/home/ian/src/zig-worktrees/mach/src/main.zig:4462:24: 0x182a92c in updateModule (zig) try comp.update(main_progress_node); ^ /var/home/ian/src/zig-worktrees/mach/src/main.zig:3331:17: 0x1848ba7 in buildOutputType (zig) updateModule(comp, color) catch |err| switch (err) { ^ /var/home/ian/src/zig-worktrees/mach/src/main.zig:283:31: 0x1641539 in mainArgs (zig) return buildOutputType(gpa, arena, args, .zig_test); ^ /var/home/ian/src/zig-worktrees/mach/src/main.zig:223:20: 0x163e585 in main (zig) return mainArgs(gpa, arena, args); ^ /var/home/ian/src/zig-worktrees/mach/lib/std/start.zig:585:37: 0x163e006 in main (zig) const result = root.main() catch |err| { ^ ???:?:?: 0x7fef9df24149 in ??? (libc.so.6) Unwind information for `libc.so.6:0x7fef9df24149` was not available, trace may be incomplete ???:?:?: 0x7fef9df2420a in ??? (libc.so.6) ???:?:?: 0x163dc54 in ??? (???) ``` Stack trace

I added a debug print statement right before the call to importFile, which revealed that the failing import is mach-sysgpu, which has been commented out of the latest build.zig in the commit being tested: Autodoc is attempting to import this module and incorrectly asserting its success. This issue has also been reported as https://github.com/ziglang/zig/issues/13512

xdBronch commented 8 months ago

should be fixed now with the new autodocs system