Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incremental compilation: reached unreachable code and accumulation of errors if @importing non-existent files #22696

Open
llogick opened this issue Jan 31, 2025 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior incremental compilation Problem occurs only when reusing compiler state.

Comments

@llogick
Copy link
Contributor

llogick commented Jan 31, 2025

Zig Version

0.14.0-dev.3020+c104e8644 DEBUG build

Steps to Reproduce and Observed Behavior

Start out with a zig init project
Add a "check" step for the exe
build with zig build -fincremental --watch check
Add an @import to a non existent file in src/main.zig, eg const argh = @import("blah.zig");
Save main.zig (compiler will report src/main.zig:x:y: error: unable to load 'src/blah.zig': FileNotFound)
Modify the @import string, eg delete the 'g' -> const argh = @import("blah.zi");
Save main.zig

zig build -fincremental --watch check
Build Summary: 2/2 steps succeeded
check success
└─ zig build-exe zig-init Debug native success 2s
check
└─ zig build-exe zig-init Debug native 1 errors
src/main.zig:5:22: error: unable to load 'src/blah.zig': FileNotFound
const argh = @import("blah.zig");
                     ^~~~~~~~~~
error: 1 compilation errors
Build Summary: 0/2 steps succeeded; 1 failed
check transitive failure
└─ zig build-exe zig-init Debug native 1 errors
check
└─ zig build-exe zig-init Debug native failure
error: thread 413716 panic: reached unreachable code
/home/rad/lab/zig/build/stage4/lib/zig/std/posix.zig:1820:23: 0x6063fdf in openatZ (zig)
            .NOENT => return error.FileNotFound,
                      ^
/home/rad/lab/zig/build/stage4/lib/zig/std/fs/Dir.zig:886:16: 0x5ed8d12 in openFileZ (zig)
    const fd = try posix.openatZ(self.fd, sub_path, os_flags, 0);
               ^
/home/rad/lab/zig/build/stage4/lib/zig/std/fs/Dir.zig:833:5: 0x5d3db85 in openFile (zig)
    return self.openFileZ(&path_c, flags);
    ^
/home/rad/lab/zig/build/stage4/lib/zig/std/Build/Cache/Path.zig:62:5: 0x5dea14d in openFile (zig)
    return p.root_dir.handle.openFile(joined_path, flags);
    ^
/home/rad/lab/zig/src/Zcu/PerThread.zig:92:23: 0x66d5013 in astGenFile (zig)
    var source_file = try file.mod.root.openFile(file.sub_file_path, .{});
                      ^
/home/rad/lab/zig/build/stage4/lib/zig/std/debug.zig:518:14: 0x5d37eed in assert (zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/rad/lab/zig/build/stage4/lib/zig/std/array_hash_map.zig:966:19: 0x62ff86d in putNoClobberContext (zig)
            assert(!result.found_existing);
                  ^
/home/rad/lab/zig/build/stage4/lib/zig/std/array_hash_map.zig:962:44: 0x60d7cd1 in putNoClobber (zig)
            return self.putNoClobberContext(gpa, key, value, undefined);
                                           ^
/home/rad/lab/zig/src/Zcu/PerThread.zig:3241:42: 0x66d75f4 in reportRetryableAstGenError (zig)
        try zcu.failed_files.putNoClobber(gpa, file, err_msg);
                                         ^
/home/rad/lab/zig/src/Compilation.zig:4284:42: 0x62fb2c2 in workerAstGenFile (zig)
            pt.reportRetryableAstGenError(src, file_index, err) catch |oom| switch (oom) {
                                         ^
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:182:50: 0x62fb9ee in runFn (zig)
            @call(.auto, func, .{id.?} ++ closure.arguments);
                                                 ^
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread/Pool.zig:295:32: 0x62a9364 in worker (zig)
            run_node.data.runFn(&run_node.data, id);
                               ^
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread.zig:488:13: 0x608cc2a in callFn__anon_175265 (zig)
            @call(.auto, f, args);
            ^
/home/rad/lab/zig/build/stage4/lib/zig/std/Thread.zig:757:30: 0x5f14c24 in entryFn (zig)
                return callFn(f, args_ptr.*);
                             ^
???:?:?: 0x7f10e6098291 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7f10e6098291` was not available, trace may be incomplete


error: the following command terminated unexpectedly:
/home/rad/lab/zig/build/stage5/bin/zig build-exe -ODebug -Mroot=/home/rad/lab/zta/misc/zig-init/src/main.zig -fno-emit-bin --cache-dir /home/rad/lab/zta/misc/zig-init/.zig-cache --global-cache-dir /home/rad/.cache/zig --name zig-init --zig-lib-dir /home/rad/lab/zig/build/stage5/lib/zig/ -fincremental --listen=- 

A (Zig) Release build will just continue to report (even if you comment out the import statement)

check
└─ zig build-exe zig-init Debug native 1 errors
error: unable to load 'src/blah.zig': FileNotFound
error: 1 compilation errors
Build Summary: 0/2 steps succeeded; 1 failed

Modifying the import statement causes accumulation of errors to nonexistent files

check transitive failure
└─ zig build-exe zig-init Debug native 2 errors
check
└─ zig build-exe zig-init Debug native 3 errors
error: unable to load 'src/blah.zig': FileNotFound
error: unable to load 'src/bleh.zig': FileNotFound
src/main.zig:5:22: error: unable to load 'src/hmm.zig': FileNotFound
const argh = @import("hmm.zig");
                     ^~~~~~~~~
error: 3 compilation errors
Build Summary: 0/2 steps succeeded; 1 failed
check transitive failure
└─ zig build-exe zig-init Debug native 3 errors
check
└─ zig build-exe zig-init Debug native 3 errors
error: unable to load 'src/blah.zig': FileNotFound
error: unable to load 'src/bleh.zig': FileNotFound
error: unable to load 'src/hmm.zig': FileNotFound
error: 3 compilation errors

Expected Behavior

@llogick llogick added the bug Observed behavior contradicts documented or intended behavior label Jan 31, 2025
@mlugg mlugg added the incremental compilation Problem occurs only when reusing compiler state. label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior incremental compilation Problem occurs only when reusing compiler state.
Projects
None yet
Development

No branches or pull requests

2 participants