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

Sema: assertion failed when passing fn taking anytype param as comptime param #12810

Closed
jacobly0 opened this issue Sep 11, 2022 · 1 comment
Closed
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@jacobly0
Copy link
Member

jacobly0 commented Sep 11, 2022

Zig Version

0.10.0-dev.3978+4fd4c733d

Steps to Reproduce

fn f(comptime _: fn (anytype) void) void {}
fn g(_: anytype) void {}
test {
    f(g);
}

Expected Behavior

All 1 tests passed.

Actual Behavior

thread 523 panic: reached unreachable code
Analyzing repro.zig: repro.zig:f__anon_970
    > %7 = param_comptime("", {
        %2 = block_inline({
          %3 = param_anytype("") token_offset:1:22 to :1:29
          %4 = func(ret_ty=@Zir.Inst.Ref.void_type, body={}) node_offset:1:18 to :1:35
          %5 = break_inline(%2, %4)
        }) node_offset:1:18 to :1:35
        %6 = break_inline(%7, %2)
      }) token_offset:1:15 to :1:16
      %9 = func(ret_ty=@Zir.Inst.Ref.void_type, body={
        %8 = ret_tok(@Zir.Inst.Ref.void_value) token_offset:1:43 to :1:44
      }) (lbrace=1:42,rbrace=1:43) node_offset:1:1 to :1:44
      %10 = break_inline(%1, %9)
    For full context, use the command
      zig ast-check -t repro.zig

  in repro.zig: repro.zig:test_0
    > %21 = call(nodiscard .auto, %19, [
        {%22, %23},
      ]) node_offset:4:5 to :4:9

/home/jacob/Source/zig/lib/std/debug.zig:281:14: 0x7e9293 in assert (zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/jacob/Source/zig/lib/std/hash_map.zig:995:41: 0x15ec047 in putNoClobberContext (zig)

                                        ^
/home/jacob/Source/zig/lib/std/hash_map.zig:992:44: 0x141abf8 in putNoClobber (zig)
                };
                                           ^
/home/jacob/Source/zig/src/Sema.zig:8192:47: 0x117d06c in zirParam (zig)
                try sema.inst_map.putNoClobber(sema.gpa, inst, .generic_poison);
                                              ^
/home/jacob/Source/zig/src/Sema.zig:1129:34: 0xf158d6 in analyzeBodyInner (zig)
                try sema.zirParam(block, inst, true);
                                 ^
/home/jacob/Source/zig/src/Sema.zig:626:45: 0xd701c8 in analyzeBodyBreak (zig)
    const break_inst = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                                            ^
/home/jacob/Source/zig/src/Sema.zig:591:50: 0x13847b5 in resolveBody (zig)
    const break_data = (try sema.analyzeBodyBreak(block, body)) orelse
                                                 ^
/home/jacob/Source/zig/src/Sema.zig:6608:53: 0x159e568 in instantiateGenericCall (zig)
        const new_func_inst = child_sema.resolveBody(&child_block, fn_info.param_body, fn_info.param_body_inst) catch |err| {
                                                    ^
/home/jacob/Source/zig/src/Sema.zig:5803:40: 0x138912c in analyzeCall (zig)
        if (sema.instantiateGenericCall(
                                       ^
/home/jacob/Source/zig/src/Sema.zig:5595:28: 0x10d1c02 in zirCall (zig)
    return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src);
                           ^
/home/jacob/Source/zig/src/Sema.zig:725:62: 0xf07e89 in analyzeBodyInner (zig)
            .call                         => try sema.zirCall(block, inst),
                                                             ^
/home/jacob/Source/zig/src/Sema.zig:609:30: 0xf063f8 in analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/jacob/Source/zig/src/Module.zig:5570:21: 0xd59093 in analyzeFnBody (zig)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/home/jacob/Source/zig/src/Module.zig:4271:40: 0xb545b4 in ensureFuncBodyAnalyzed (zig)
            var air = mod.analyzeFnBody(func, sema_arena) catch |err| switch (err) {
                                       ^
/home/jacob/Source/zig/src/Compilation.zig:2982:42: 0xb52b12 in processOneJob (zig)
            module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
                                         ^
/home/jacob/Source/zig/src/Compilation.zig:2920:30: 0xa4695e in performAllTheWork (zig)
            try processOneJob(comp, work_item);
                             ^
/home/jacob/Source/zig/src/Compilation.zig:2260:31: 0xa43255 in update (zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
/home/jacob/Source/zig/src/main.zig:3360:20: 0xa6d2f6 in updateModule (zig)
    try comp.update();
                   ^
/home/jacob/Source/zig/src/main.zig:3034:17: 0x80c081 in buildOutputType (zig)
    updateModule(gpa, comp, hook) catch |err| switch (err) {
                ^
/home/jacob/Source/zig/src/main.zig:236:31: 0x7e6d3b in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .zig_test);
                              ^
/home/jacob/Source/zig/src/main.zig:174:20: 0x7e6180 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/jacob/Source/zig/lib/std/start.zig:578:37: 0x7e86a9 in main (zig)
            const result = root.main() catch |err| {
                                    ^
Aborted

Workaround

try sema.inst_map.put(sema.gpa, inst, .generic_poison);

But, I don't know if this is just hiding a deeper issue.

@jacobly0 jacobly0 added the bug Observed behavior contradicts documented or intended behavior label Sep 11, 2022
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Sep 11, 2022
@Vexu Vexu added this to the 0.10.0 milestone Sep 11, 2022
@kkHAIKE
Copy link
Contributor

kkHAIKE commented Sep 24, 2022

prev hashmap.put callstack

frame #0: 0x0000000100fd6fbd zig`Sema.zirParam at Sema.zig:8236:5
    frame #1: 0x0000000100d55aaf zig`Sema.analyzeBodyInner at Sema.zig:1131:34
    frame #2: 0x0000000100bb8bba zig`Sema.analyzeBodyBreak at Sema.zig:628:45
    frame #3: 0x0000000100bb5139 zig`Module.semaDecl at Module.zig:4570:50
    frame #4: 0x00000001009c2668 zig`Module.ensureDeclAnalyzed at Module.zig:4205:38
    frame #5: 0x000000010123f0ac zig`Sema.ensureDeclAnalyzed at Sema.zig:26066:32
    frame #6: 0x0000000100fe53f7 zig`Sema.analyzeDeclRef at Sema.zig:26108:32
    frame #7: 0x000000010120e908 zig`Sema.analyzeDeclVal at Sema.zig:26036:45
    frame #8: 0x0000000100f2dfeb zig`Sema.zirDeclVal at Sema.zig:5419:31
    frame #9: 0x0000000100d488a8 zig`Sema.analyzeBodyInner at Sema.zig:737:65
    frame #10: 0x0000000100d464ca zig`Sema.analyzeBody at Sema.zig:611:30
    frame #11: 0x0000000100ba096f zig`Module.analyzeFnBody at Module.zig:5590:21
    frame #12: 0x00000001009c14f9 zig`Module.ensureFuncBodyAnalyzed at Module.zig:4291:40
    frame #13: 0x00000001009bf8f8 zig`Compilation.processOneJob at Compilation.zig:3047:42
    frame #14: 0x00000001008c03b3 zig`Compilation.performAllTheWork at Compilation.zig:2985:30
    frame #15: 0x00000001008bcdfb zig`Compilation.update at Compilation.zig:2325:31
    frame #16: 0x00000001008e8008 zig`main.updateModule at main.zig:3376:20
    frame #17: 0x000000010067df99 zig`main.buildOutputType at main.zig:3061:17
    frame #18: 0x0000000100602367 zig`main.mainArgs at main.zig:234:31
    frame #19: 0x0000000100601804 zig`main at stage1.zig:48:24
    frame #20: 0x00007fff63f4b3d5 libdyld.dylib`start + 1
    frame #21: 0x00007fff63f4b3d5 libdyld.dylib`start + 1

first time from 'zirDeclVal', the second time from 'zirCall'

@jacobly0 jacobly0 changed the title [Sema] assertion failed when passing fn taking anytype param as comptime param Sema: assertion failed when passing fn taking anytype param as comptime param Sep 27, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.10.1 Oct 12, 2022
@Vexu Vexu closed this as completed in 6da070c Dec 20, 2022
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

No branches or pull requests

4 participants