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

Compiler crashes and gives no output #22583

Open
Didas-git opened this issue Jan 23, 2025 · 1 comment
Open

Compiler crashes and gives no output #22583

Didas-git opened this issue Jan 23, 2025 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@Didas-git
Copy link

Zig Version

0.14.0-dev.2909+f3c29dcb2

Steps to Reproduce and Observed Behavior

Create a new zig project using zig init and replace the main.zig file with the following:

const G = struct {
    const L = struct { [:0]const u8 };
    comptime list: []*L = &.{},

    pub fn get(comptime self: *G, pattern: [:0]const u8) void {
        comptime {
            var temp: L = .{pattern};
            self.list = self.list ++ @constCast(.{&temp});
        }
    }
};

pub fn main() !void {
    comptime {
        var t = G{};
        t.get("s");
    }
}

What is observed is that the compiler simply quits with code 1 and doesn't give any information on what the issue is.

We have also ran the code with a debug build and it does give us an error, im appending the output bellow.
Crash.log

Expected Behavior

I would expect to get an error message for why it fails to compile, the code is most likely not valid zig but as a new person in the zig ecosystem it's fairly hard to find out what's wrong when there is no output.

@Didas-git Didas-git added the bug Observed behavior contradicts documented or intended behavior label Jan 23, 2025
@mlugg mlugg added this to the 0.14.0 milestone Jan 23, 2025
@Didas-git
Copy link
Author

Didas-git commented Jan 23, 2025

After exploring for a while, we were able to narrow down the issue to the following:

const T = struct { []const u8 };
pub fn main() !void {
    comptime {
        var t: T = .{"s"};
        @constCast(.{&t});
    }
}

We reached the conclusion that the issue seems to come from the lack of sema being passed to latter functions, as the inner value of the tuple is a pointer when the printPtr gets called it passes down the comptime_alloc pointer without a sema as per:

~/zig/src/Value.zig:4143:34: 0x11034951b in pointerDerivationAdvanced__anon_421417 (zig)
            const sema = opt_sema.?;
                                 ^
~/zig/src/print_value.zig:318:46: 0x1112904eb in printPtr__anon_1024821 (zig)
        try ptr_val.pointerDerivationAdvanced(arena.allocator(), pt, false, null);
                                             ^
~/zig/src/print_value.zig:167:25: 0x11102629b in print__anon_662789 (zig)
            try printPtr(val, .rvalue, writer, level, pt, opt_sema);
                        ^

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
Projects
None yet
Development

No branches or pull requests

2 participants