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 crash when initializing empty tuple type #16412

Closed
ianprime0509 opened this issue Jul 15, 2023 · 0 comments · Fixed by #17380
Closed

Compiler crash when initializing empty tuple type #16412

ianprime0509 opened this issue Jul 15, 2023 · 0 comments · Fixed by #17380
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@ianprime0509
Copy link
Contributor

Zig Version

0.11.0-dev.4002+7dd1cf26f

Steps to Reproduce and Observed Behavior

In test.zig:

const S = @Type(.{ .Struct = .{
    .layout = .Auto,
    .fields = &.{},
    .decls = &.{},
    .is_tuple = true,
} });

test {
    const s: S = .{};
    _ = s;
}

Run zig test test.zig. Full crash output from a debug compiler build follows:

thread 155496 panic: InternPool.getCoerced of simple_value not implemented from anon_struct_type to struct_type
Analyzing test.zig: test.zig:test_0
      %21 = dbg_block_begin()
      %22 = dbg_stmt(2, 5)
      %23 = block_comptime({
        %24 = decl_val("S") token_offset:9:14 to :9:15
        %25 = break(%23, %24)
      }) node_offset:9:14 to :9:15
    > %28 = as_node(%23, @InternPool.Index.empty_struct) node_offset:9:18 to :9:21
      %29 = dbg_var_val(%28, "s")
      %30 = dbg_stmt(3, 5)
      %31 = ensure_result_non_error(%28) node_offset:10:9 to :10:10
      %32 = dbg_block_end()
      %33 = restore_err_ret_index(%20, %4294967212)
      %34 = break(%20, @InternPool.Index.void_value)
    For full context, use the command
      zig ast-check -t test.zig

  in test.zig: test.zig:test_0
    > %20 = block({%21..%34}) node_offset:8:6 to :8:7

/home/ian/src/zig/lib/std/debug.zig:289:22: 0x1872f52 in panicExtra__anon_190817 (zig)
    std.builtin.panic(msg, trace, ret_addr);
                     ^
/home/ian/src/zig/lib/std/debug.zig:264:15: 0x14ae1d6 in panic__anon_164106 (zig)
    panicExtra(null, null, format, args);
              ^
/home/ian/src/zig/src/InternPool.zig:4824:24: 0xfa3d1b in getCoerced (zig)
        std.debug.panic("InternPool.getCoerced of {s} not implemented from {s} to {s}", .{
                       ^
/home/ian/src/zig/src/Module.zig:6762:43: 0xc3167d in getCoerced (zig)
    return (try mod.intern_pool.getCoerced(mod.gpa, val.toIntern(), new_ty.toIntern())).toValue();
                                          ^
/home/ian/src/zig/src/Sema.zig:27585:52: 0xfd4a54 in coerceInMemory (zig)
    return sema.addConstant(try sema.mod.getCoerced(val, dst_ty));
                                                   ^
/home/ian/src/zig/src/Sema.zig:26917:39: 0xc3d51a in coerceExtra (zig)
            return sema.coerceInMemory(val, dest_ty);
                                      ^
/home/ian/src/zig/src/Sema.zig:9579:28: 0x13ea437 in analyzeAs (zig)
    return sema.coerceExtra(block, dest_ty, operand, src, .{ .is_ret = is_ret, .no_cast_to_comptime_int = no_cast_to_comptime_int }) catch |err| switch (err) {
                           ^
/home/ian/src/zig/src/Sema.zig:9544:26: 0xebb42c in zirAsNode (zig)
    return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false);
                         ^
/home/ian/src/zig/src/Sema.zig:933:64: 0xc1b6ea in analyzeBodyInner (zig)
            .as_node                      => try sema.zirAsNode(block, inst),
                                                               ^
/home/ian/src/zig/src/Sema.zig:5680:34: 0x14a2639 in resolveBlockBody (zig)
        if (sema.analyzeBodyInner(child_block, body)) |_| {
                                 ^
/home/ian/src/zig/src/Sema.zig:5663:33: 0xf99c7d in zirBlock (zig)
    return sema.resolveBlockBody(parent_block, src, &child_block, body, inst, &label.merges);
                                ^
/home/ian/src/zig/src/Sema.zig:1485:49: 0xc2d8b4 in analyzeBodyInner (zig)
                    break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
                                                ^
/home/ian/src/zig/src/Sema.zig:823:30: 0xe668c8 in analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/ian/src/zig/src/Module.zig:5626:21: 0xbfec7d in analyzeFnBody (zig)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/home/ian/src/zig/src/Module.zig:4224:40: 0xa411c9 in ensureFuncBodyAnalyzed (zig)
            var air = mod.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
                                       ^
/home/ian/src/zig/src/Compilation.zig:3146:42: 0xa3f1a9 in processOneJob (zig)
            module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
                                         ^
/home/ian/src/zig/src/Compilation.zig:3083:30: 0x8d8bde in performAllTheWork (zig)
            try processOneJob(comp, work_item, main_progress_node);
                             ^
/home/ian/src/zig/src/Compilation.zig:2031:31: 0x8d53a0 in update (zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
/home/ian/src/zig/src/main.zig:3862:24: 0x90209a in updateModule (zig)
        try comp.update(main_progress_node);
                       ^
/home/ian/src/zig/src/main.zig:3297:17: 0x7a99f6 in buildOutputType (zig)
    updateModule(comp) catch |err| switch (err) {
                ^
/home/ian/src/zig/src/main.zig:275:31: 0x759224 in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .zig_test);
                              ^
/home/ian/src/zig/src/main.zig:213:20: 0x756445 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/ian/src/zig/lib/std/start.zig:608:37: 0x755ec7 in main (zig)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7f320b649b49 in ??? (???)
???:?:?: 0x7f320b649c0a in ??? (???)
???:?:?: 0x755ae4 in ??? (???)
Aborted (core dumped)
Crash output

Expected Behavior

The test should pass, as it does when .is_tuple = false in the creation of S.

@ianprime0509 ianprime0509 added the bug Observed behavior contradicts documented or intended behavior label Jul 15, 2023
@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Jul 22, 2023
@andrewrk andrewrk added this to the 0.11.1 milestone Jul 22, 2023
ianprime0509 added a commit to ianprime0509/zig that referenced this issue Oct 3, 2023
Vexu pushed a commit that referenced this issue Oct 3, 2023
@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0 Jan 29, 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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants