ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.26k stars 2.57k forks source link

Modifying `std.builtin.CallingConvention` is currently impossible due to the way Sema interprets the values #21842

Open alexrp opened 1 month ago

alexrp commented 1 month ago

Right now, modifying std.builtin.CallingConvention by adding, removing, or renaming tags results in compiler crashes like:

/home/alexrp/Source/zig/src/Value.zig:4550:67: 0x32a8693 in interpret__anon_555950 (zig)
            if (union_obj.field_types.len != @"union".fields.len) return error.TypeMismatch;
                                                                  ^
/home/alexrp/Source/zig/src/Sema.zig:2650:31: 0x32a836f in analyzeValueAsCallconv (zig)
        error.TypeMismatch => @panic("std.builtin is corrupt"),
                              ^
/home/alexrp/Source/zig/src/Sema.zig:26695:51: 0x2de3717 in zirFuncFancy (zig)
    } else if (extra.data.bits.has_section_ref) blk: {
                                                  ^
/home/alexrp/Source/zig/src/Sema.zig:1109:67: 0x29a1144 in analyzeBodyInner (zig)
            .func_fancy                   => try sema.zirFuncFancy(block, inst),
                                                                  ^
/home/alexrp/Source/zig/src/Sema.zig:954:30: 0x2536a57 in analyzeInlineBody (zig)
    if (sema.analyzeBodyInner(block, body)) |_| {
                             ^
/home/alexrp/Source/zig/src/Sema.zig:987:39: 0x20fcb6e in resolveInlineBody (zig)
    return (try sema.analyzeInlineBody(block, body, break_target)) orelse .unreachable_value;
                                      ^
/home/alexrp/Source/zig/src/Zcu/PerThread.zig:1227:50: 0x20f9df6 in semaCau (zig)
    const result_ref = try sema.resolveInlineBody(&block, decl_bodies.value_body, inst_info.inst);
                                                 ^
/home/alexrp/Source/zig/src/Zcu/PerThread.zig:692:22: 0x1e4dc8d in ensureCauAnalyzedInner (zig)
    return pt.semaCau(cau_index) catch |err| switch (err) {
                     ^
/home/alexrp/Source/zig/src/Zcu/PerThread.zig:578:90: 0x1c1dc43 in ensureCauAnalyzed (zig)
    const sema_result: SemaCauResult, const analysis_fail = if (pt.ensureCauAnalyzedInner(cau_index, cau_outdated)) |result|
                                                                                         ^
/home/alexrp/Source/zig/src/Sema.zig:32787:32: 0x20f7684 in ensureNavResolved (zig)

                               ^
/home/alexrp/Source/zig/src/Sema.zig:32817:31: 0x2ead33f in analyzeNavRefInner (zig)

                              ^
/home/alexrp/Source/zig/src/Sema.zig:32729:44: 0x2eac7a1 in analyzeNavVal (zig)
        } else {
                                           ^
/home/alexrp/Source/zig/src/Sema.zig:28559:48: 0x3299dc3 in fieldCallBind (zig)
                        if (field_name == concrete_ty.structFieldName(i, zcu).unwrap().?) {
                                               ^
/home/alexrp/Source/zig/src/Sema.zig:7005:46: 0x2dd64ee in zirCall__anon_500630 (zig)
            break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);
                                             ^
/home/alexrp/Source/zig/src/Sema.zig:1074:62: 0x29a06ba in analyzeBodyInner (zig)
            .field_call                   => try sema.zirCall(block, inst, .field),
                                                             ^
/home/alexrp/Source/zig/src/Sema.zig:1649:81: 0x29ad4fa in analyzeBodyInner (zig)
                    const break_result: ?BreakResult = if (sema.analyzeBodyInner(&child_block, inline_body)) |_| r: {
                                                                                ^
/home/alexrp/Source/zig/src/Sema.zig:954:30: 0x2536a57 in analyzeInlineBody (zig)
    if (sema.analyzeBodyInner(block, body)) |_| {
                             ^
/home/alexrp/Source/zig/src/Sema.zig:1742:58: 0x29ae438 in analyzeBodyInner (zig)
                const result = try sema.analyzeInlineBody(block, inline_body, inst) orelse break;
                                                         ^
/home/alexrp/Source/zig/src/Sema.zig:1649:81: 0x29ad4fa in analyzeBodyInner (zig)
                    const break_result: ?BreakResult = if (sema.analyzeBodyInner(&child_block, inline_body)) |_| r: {
                                                                                ^
/home/alexrp/Source/zig/src/Sema.zig:954:30: 0x2536a57 in analyzeInlineBody (zig)
    if (sema.analyzeBodyInner(block, body)) |_| {
                             ^
/home/alexrp/Source/zig/src/Sema.zig:987:39: 0x20fcb6e in resolveInlineBody (zig)
    return (try sema.analyzeInlineBody(block, body, break_target)) orelse .unreachable_value;
                                      ^
/home/alexrp/Source/zig/src/Zcu/PerThread.zig:1227:50: 0x20f9df6 in semaCau (zig)
    const result_ref = try sema.resolveInlineBody(&block, decl_bodies.value_body, inst_info.inst);
                                                 ^
/home/alexrp/Source/zig/src/Zcu/PerThread.zig:692:22: 0x1e4dc8d in ensureCauAnalyzedInner (zig)
    return pt.semaCau(cau_index) catch |err| switch (err) {
                     ^
/home/alexrp/Source/zig/src/Zcu/PerThread.zig:578:90: 0x1c1dc43 in ensureCauAnalyzed (zig)
    const sema_result: SemaCauResult, const analysis_fail = if (pt.ensureCauAnalyzedInner(cau_index, cau_outdated)) |result|
                                                                                         ^
/home/alexrp/Source/zig/src/Compilation.zig:3663:33: 0x1e3e2c3 in processOneJob (zig)
            pt.ensureCauAnalyzed(cau_index) catch |err| switch (err) {
                                ^
/home/alexrp/Source/zig/src/Compilation.zig:3603:30: 0x1c1885c in performAllTheWorkInner (zig)
            try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job, main_progress_node);
                             ^
/home/alexrp/Source/zig/src/Compilation.zig:3463:36: 0x1a810d0 in performAllTheWork (zig)
    try comp.performAllTheWorkInner(main_progress_node);
                                   ^
/home/alexrp/Source/zig/src/Compilation.zig:2232:31: 0x1a7c6e4 in update (zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
/home/alexrp/Source/zig/src/Compilation.zig:6115:28: 0x2088556 in updateSubCompilation (zig)
        try sub_comp.update(sub_node);
                           ^
/home/alexrp/Source/zig/src/Compilation.zig:6254:34: 0x20c8366 in buildOutputFromZig (zig)
    try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node);
                                 ^
/home/alexrp/Source/zig/src/Compilation.zig:4496:28: 0x24ba4f9 in buildRt (zig)
    comp.buildOutputFromZig(
                           ^
/home/alexrp/Source/zig/lib/std/Thread/WaitGroup.zig:66:13: 0x207315c in run (zig)
            @call(.auto, func, args_inner);
            ^
/home/alexrp/Source/zig/lib/std/Thread.zig:486:13: 0x2931431 in callFn__anon_393778 (zig)
            @call(.auto, f, args);
            ^
/home/alexrp/Source/zig/lib/std/Thread.zig:755:30: 0x24ba402 in entryFn (zig)
                return callFn(f, args_ptr.*);
alexrp commented 1 month ago

For context, the changes I plan to make are: