Skip to content

Zig compiler panic when logging type info #11513

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

Closed
bayo-code opened this issue Apr 24, 2022 · 3 comments
Closed

Zig compiler panic when logging type info #11513

bayo-code opened this issue Apr 24, 2022 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@bayo-code
Copy link

Zig Version

0.10.0-dev.1735+289ba5dfc

Steps to Reproduce

In a new zig-bin project, I just put this code in the main.zig file.

const std = @import("std");

fn add(a: anytype, b: @TypeOf(a)) @TypeOf(a) {
    const T = @TypeOf(a);
    const info = @typeInfo(T);
    std.log.debug("Type of a: {}", .{info});
    return a + b;
}

pub fn main() void {
    std.log.debug("{}", .{add(3, 10)});
}

Expected Behavior

The program compiles or generates a compile error

Actual Behavior

The zig compiler crashed with the following message:

when analyzing /home/adebayo/bin/zig-linux-x86_64-0.10.0-dev.1735+289ba5dfc/lib/std/log.zig:133:38 in compiler source at /workspace/src/stage1/ir.cpp:5626: thread 8284 panic: assertion failed. This is a bug in the Zig compiler.
Unable to dump stack trace: debug info stripped
zig_bin...The following command terminated unexpectedly:
/home/adebayo/bin/zig-linux-x86_64-0.10.0-dev.1735+289ba5dfc/zig build-exe /home/adebayo/Documents/zig_bin/src/main.zig --verbose-cimport --cache-dir /home/adebayo/Documents/zig_bin/zig-cache --global-cache-dir /home/adebayo/.cache/zig --name zig_bin --enable-cache 
error: the following build command failed with exit code 6:
/home/adebayo/Documents/zig_bin/zig-cache/o/c512bb2b4d41212c56952179a7f21024/build /home/adebayo/bin/zig-linux-x86_64-0.10.0-dev.1735+289ba5dfc/zig /home/adebayo/Documents/zig_bin /home/adebayo/Documents/zig_bin/zig-cache /home/adebayo/.cache/zig run
@bayo-code bayo-code added the bug Observed behavior contradicts documented or intended behavior label Apr 24, 2022
@bayo-code
Copy link
Author

I don't have debug info because I downloaded a nightly version from ziglang.org.

I expect someone with debug information to be able to reproduce this error and produce better stack traces

@Vexu Vexu added the stage1 The process of building from source via WebAssembly and the C backend. label Apr 28, 2022
@Vexu Vexu added this to the 0.12.0 milestone Apr 28, 2022
@alichraghi
Copy link
Contributor

alichraghi commented May 21, 2022

stage2 backtrace 0.10.0-dev.2307+d165b75ed

Click to expand!
/home/ali/dev/zig/stage2/lib/zig/std/atomic/Atomic.zig:153:34: error: unable to resolve comptime value
            return @atomicRmw(T, &self.value, op, value, ordering);
                                 ^
/home/ali/dev/zig/stage2/lib/zig/std/atomic/Atomic.zig:188:32: note: called from here
                return self.rmw(.Or, value, ordering);
                               ^
/home/ali/dev/zig/stage2/lib/zig/std/atomic/Atomic.zig:225:41: note: called from here
                    .Set => self.fetchOr(mask, ordering),
                                        ^
/home/ali/dev/zig/stage2/lib/zig/std/atomic/Atomic.zig:203:30: note: called from here
                return bitRmw(self, .Set, bit, ordering);
                             ^
/home/ali/dev/zig/stage2/lib/zig/std/Thread/Mutex.zig:144:37: note: called from here
            return self.state.bitSet(locked_bit, .Acquire) == 0;
                                    ^
/home/ali/dev/zig/stage2/lib/zig/std/Thread/Mutex.zig:133:27: note: called from here
        if (!self.lockFast("tryCompareAndSwap")) {
                          ^
/home/ali/dev/zig/stage2/lib/zig/std/Thread/Mutex.zig:45:19: note: called from here
    self.impl.lock();
                  ^
/home/ali/dev/zig/stage2/lib/zig/std/log.zig:168:36: note: called from here
    std.debug.getStderrMutex().lock();
                                   ^
/home/ali/dev/zig/stage2/lib/zig/std/log.zig:146:23: note: called from here
            defaultLog(message_level, scope, format, args);
                      ^
/home/ali/dev/zig/stage2/lib/zig/std/log.zig:219:16: note: called from here
            log(.debug, scope, format, args);
               ^
t.zig:6:18: note: called from here
    std.log.debug("Type of a: {}", .{info});
                 ^
t.zig:11:30: note: called from here
    std.log.debug("{}", .{add(3, 10)});

@Vexu
Copy link
Member

Vexu commented Mar 28, 2024

This errors as expected in the self hosted compiler.

@Vexu Vexu closed this as completed Mar 28, 2024
@Vexu Vexu modified the milestones: 0.15.0, 0.12.0 Mar 28, 2024
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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

3 participants