ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.58k stars 2.45k forks source link

Compiler fails to report compiler errors after update, assertion failure in debug builds. #19514

Closed IntegratedQuantum closed 2 months ago

IntegratedQuantum commented 5 months ago

Zig Version

0.12.0-dev.3518+d2be725e4

Steps to Reproduce and Observed Behavior

I just tried updating Zig and I know that there were breaking changes and my code should trigger compiler errors, but sadly the compiler is just crashing instead of reporting anything. This is not the first time that I have reported issues like this #17859 #17878 and it's always so annoying because it takes a ton of time to pinpoint the actual compiler error that zig should have reported. I'd appreciate it if you could find some time and start looking into these issues.

Clone the project and get the right commit:

git clone https://github.com/PixelGuys/Cubyz.git
cd Cubyz/
git checkout 2dfbe98844d18e49b326b70b7fe8a1788069a327

Then run zig build. Using a release build you'll observe that the compiler just fails without any output:

$ zig build
install
└─ install Cubyzig
   └─ zig build-exe Cubyzig Debug native failure
error: the following command terminated unexpectedly:
/home/mint/Cubyz/compiler/zig/zig build-exe -lcubyz_deps -lasound -lX11 -lGL -ODebug -I /home/mint/.cache/zig/p/12201446153e8822c020a10199880fae5fac7eb3f1e3f7c7a9b653e58914fa3e2223/include -L /home/mint/.cache/zig/p/12201446153e8822c020a10199880fae5fac7eb3f1e3f7c7a9b653e58914fa3e2223/lib -rpath /home/mint/.cache/zig/p/12201446153e8822c020a10199880fae5fac7eb3f1e3f7c7a9b653e58914fa3e2223/lib --dep gui --dep server -Mroot=/home/mint/Desktop/untitled folder/Cubyz/src/main.zig -ODebug -Mgui=/home/mint/Desktop/untitled folder/Cubyz/src/gui/gui.zig -ODebug -Mserver=/home/mint/Desktop/untitled folder/Cubyz/src/server/server.zig -lc++ -lc --cache-dir /home/mint/Desktop/untitled folder/Cubyz/zig-cache --global-cache-dir /home/mint/.cache/zig --name Cubyzig --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install Cubyzig transitive failure
   └─ zig build-exe Cubyzig Debug native failure
error: the following build command failed with exit code 1:
/home/mint/Desktop/untitled folder/Cubyz/zig-cache/o/94fde322a28ade0546adf45e56cb3599/build /home/mint/Cubyz/compiler/zig/zig /home/mint/Desktop/untitled folder/Cubyz /home/mint/Desktop/untitled folder/Cubyz/zig-cache /home/mint/.cache/zig --seed 0x2fc844cf -Z0a71e8f0fe7c1420

Using a debug build you'll see an assertion failure:

error: thread 44052 panic: reached unreachable code
Analyzing src/items.zig: items.zig:recipeList
      %8957 = decl_ref("main") token_offset:1316:17 to :1316:21
      %8958 = dbg_stmt(1, 26)
      %8959 = field_call(.compile_time, %8957, "List", [
        {
          %8960 = decl_val("Recipe") token_offset:1316:27 to :1316:33
          %8961 = break_inline(%8959, %8960)
        },
      ]) node_offset:1316:17 to :1316:34
      %8962 = as_node(%8959, @undef) node_offset:1316:37 to :1316:46
    > %8963 = extended(variable(%8959, init=%8962))
      %8964 = break_inline(%8956, %8963)
    For full context, use the command
      zig ast-check -t src/items.zig

  in src/items.zig: items.zig:globalInit
    > %9034 = decl_ref("recipeList") token_offset:1329:2 to :1329:12

/home/mint/zig/lib/std/debug.zig:403:14: 0x9e33b3c in assert (zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/mint/zig/src/type.zig:444:15: 0xa138813 in fromInterned (zig)
        assert(i != .none);
              ^
/home/mint/zig/src/type.zig:2720:58: 0xa4154aa in comptimeOnlyAdvanced (zig)
                                if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(mod, opt_sema)) {
                                                         ^
/home/mint/zig/src/type.zig:2628:69: 0xa414a43 in comptimeOnlyAdvanced (zig)
                        else => return child_ty.comptimeOnlyAdvanced(mod, opt_sema),
                                                                    ^
/home/mint/zig/src/type.zig:2628:69: 0xa414a43 in comptimeOnlyAdvanced (zig)
                        else => return child_ty.comptimeOnlyAdvanced(mod, opt_sema),
                                                                    ^
/home/mint/zig/src/type.zig:2720:89: 0xa4154de in comptimeOnlyAdvanced (zig)
                                if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(mod, opt_sema)) {
                                                                                        ^
/home/mint/zig/src/type.zig:2628:69: 0xa414a43 in comptimeOnlyAdvanced (zig)
                        else => return child_ty.comptimeOnlyAdvanced(mod, opt_sema),
                                                                    ^
/home/mint/zig/src/type.zig:2720:89: 0xa4154de in comptimeOnlyAdvanced (zig)
                                if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(mod, opt_sema)) {
                                                                                        ^
/home/mint/zig/src/Sema.zig:38304:35: 0xa144c30 in typeRequiresComptime (zig)
    return ty.comptimeOnlyAdvanced(sema.mod, sema);
                                  ^
/home/mint/zig/src/Sema.zig:26375:39: 0xb040e3a in validateVarType (zig)
    if (!try sema.typeRequiresComptime(var_ty)) return;
                                      ^
/home/mint/zig/src/Sema.zig:25698:29: 0xac30e57 in zirVarExtended (zig)
    try sema.validateVarType(block, ty_src, var_ty, small.is_extern);
                            ^
/home/mint/zig/src/Sema.zig:1215:67: 0xa6d10cb in analyzeBodyInner (zig)
                    .variable           => try sema.zirVarExtended(       block, extended),
                                                                  ^
/home/mint/zig/src/Sema.zig:911:30: 0xa400677 in analyzeInlineBody (zig)
    if (sema.analyzeBodyInner(block, body)) |_| {
                             ^
/home/mint/zig/src/Sema.zig:937:39: 0xa14fdae in resolveInlineBody (zig)
    return (try sema.analyzeInlineBody(block, body, break_target)) orelse .unreachable_value;
                                      ^
/home/mint/zig/src/Module.zig:3638:50: 0xa14d056 in semaDecl (zig)
    const result_ref = try sema.resolveInlineBody(&block_scope, decl_bodies.value_body, decl_inst);
                                                 ^
/home/mint/zig/src/Module.zig:3016:32: 0x9f2c3a1 in ensureDeclAnalyzed (zig)
        break :blk mod.semaDecl(decl_index) catch |err| switch (err) {
                               ^
/home/mint/zig/src/Sema.zig:32536:27: 0xad18109 in ensureDeclAnalyzed (zig)
    mod.ensureDeclAnalyzed(decl_index) catch |err| {
                          ^
/home/mint/zig/src/Sema.zig:32581:32: 0xad202aa in analyzeDeclRefInner (zig)
    try sema.ensureDeclAnalyzed(decl_index);
                               ^
/home/mint/zig/src/Sema.zig:32572:36: 0xa7f5fce in analyzeDeclRef (zig)
    return sema.analyzeDeclRefInner(decl_index, true);
                                   ^
/home/mint/zig/src/Sema.zig:6721:31: 0xabbfccd in zirDeclRef (zig)
    return sema.analyzeDeclRef(decl_index);
                              ^
/home/mint/zig/src/Sema.zig:1023:65: 0xa6ca84b in analyzeBodyInner (zig)
            .decl_ref                     => try sema.zirDeclRef(block, inst),
                                                                ^
/home/mint/zig/src/Sema.zig:893:26: 0xa6c8f21 in analyzeFnBody (zig)
    sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                         ^
/home/mint/zig/src/Module.zig:4609:23: 0xa3c0186 in analyzeFnBody (zig)
    sema.analyzeFnBody(&inner_block, fn_info.body) catch |err| switch (err) {
                      ^
/home/mint/zig/src/Module.zig:3144:32: 0xa129198 in ensureFuncBodyAnalyzed (zig)
    var air = zcu.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
                               ^
/home/mint/zig/src/Compilation.zig:3419:42: 0xa126ea2 in processOneJob (zig)
            module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
                                         ^
/home/mint/zig/src/Compilation.zig:3359:30: 0x9f5835a in performAllTheWork (zig)
            try processOneJob(comp, work_item, main_progress_node);
                             ^
/home/mint/zig/src/Compilation.zig:2132:31: 0x9f53892 in update (zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
/home/mint/zig/src/main.zig:4105:36: 0x9fce71c in serve (zig)
                    try comp.update(main_progress_node);
                                   ^
/home/mint/zig/src/main.zig:3371:22: 0x9fecf86 in buildOutputType (zig)
            try serve(
                     ^
/home/mint/zig/src/main.zig:260:31: 0x9e35d61 in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .{ .build = .Exe });
                              ^
/home/mint/zig/src/main.zig:206:20: 0x9e32d05 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/mint/zig/lib/std/start.zig:511:37: 0x9e3279e in main (zig)
            const result = root.main() catch |err| {
                                    ^
../sysdeps/nptl/libc_start_call_main.h:58:16: 0x7feed9dd5d8f in __libc_start_call_main (../sysdeps/x86/libc-start.c)
../csu/libc-start.c:392:3: 0x7feed9dd5e3f in __libc_start_main_impl (../sysdeps/x86/libc-start.c)
???:?:?: 0x4f94ea4 in ??? (???)
???:?:?: 0x0 in ??? (???)

Expected Behavior

The compiler shouldn't crash, instead it should display a compiler error.

Vexu commented 5 months ago

Probably related #18264, #18929

IntegratedQuantum commented 2 months ago

This works fine as of 0.13.0 and it reports the correct errors.