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 segfault analyzing array_init_ref when comptime-only argument is runtime-only #22868

Open
Jarred-Sumner opened this issue Feb 12, 2025 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@Jarred-Sumner
Copy link
Contributor

Zig Version

0.14.0-dev.3002+1f2fff682

Steps to Reproduce and Observed Behavior

  1. Download oven-sh/bun
  2. Checkout 70ba93873877126373380ba83c68176fc7bbea19
  3. Put your copy of zig's executable in vendor/zig/zig
  4. run zig build check
Analyzing src/cli/init_command.zig
      %2629 = validate_ref_ty(%2628) token_offset:565:54 to :565:55
      %2630 = validate_array_init_ref_ty(%2628, , 1) node_offset:565:55 to :565:66
      %2631 = array_init_elem_type(%2630, 0)
      %2632 = dbg_stmt(293, 60)
      %2633 = field_val(%2622, "name") node_offset:565:57 to :565:65
    > %2634 = array_init_ref(%2630{%2633}) node_offset:565:55 to :565:66
      %2635 = break_inline(%2628, %2634)
    For full context, use the command
      zig ast-check -t src/cli/init_command.zig

  in src/cli/init_command.zig
    > %2628 = field_call(.auto, %2626, "hasAnyPropertyNamed", [
        {%2629..%2635},
      ]) node_offset:565:29 to :565:67
  in src/cli/init_command.zig
    > %2637 = block({%2627..%2636}) node_offset:565:25 to :565:27
  in src/cli/init_command.zig
    > %2620 = condbr(%2619, {%2622..%2647}, {%2648}) node_offset:564:21 to :564:24
  in src/cli/init_command.zig
    > %2621 = block({%2619, %2620}) node_offset:564:21 to :564:24
  in src/cli/init_command.zig
    > %2617 = loop({%2618..%2651}) node_offset:564:21 to :564:24
  in src/cli/init_command.zig
    > %2609 = condbr(%2608, {%2611..%2653}, {%2654}) node_offset:563:17 to :563:19
  in src/cli/init_command.zig
    > %2610 = block({%2602..%2609}) node_offset:563:17 to :563:19
  in src/cli/init_command.zig
    > %2600 = block({%2601..%2660}) node_offset:562:40 to :562:40
  in src/cli/init_command.zig
    > %2533 = block({%2534..%3105}) node_offset:553:9 to :553:9
  in src/cli.zig
    > %9624 = try(%9618, {%9625..%9627}) node_offset:1801:36 to :1801:77
  in src/cli.zig
    > %9570 = switch_block(%9565,
        %9571 => {%9572..%9584},
        %9585 => {%9586..%9598},
        %9599 => {%9600..%9612},
        %9613 => {%9614..%9630},
        %9631 => {%9632..%9675},
        %9676 => {%9677..%9707},
        %9708 => {%9709..%9754},
        %9755 => {%9756..%9801},
        %9802 => {%9803..%9848},
        %9849 => {%9850..%9895},
        %9896 => {%9897..%9942},
        %9943 => {%9944..%9989},
        %9990 => {%9991..%10036},
        %10037 => {%10038..%10095},
        %10096 => {%10097..%10166},
        %10167 => {%10168..%10213},
        %10214 => {%10215..%10260},
        %10261 => {%10262..%10307},
        %10308 => {%10309..%10354},
        %10355 => {%10356..%10401},
        %10402 => {%10403..%11088},
        %11089 => {%11090..%11674},
        %11675 => {%11676..%11800},
        %11801 => {%11802..%11850},
        %11851 => {%11852..%11897},
        %11898 => {%11899..%12388},
        %12389 => {%12390..%12432}) node_offset:1797:9 to :1797:15
  in src/cli.zig
    > %255 = is_non_err(%251) node_offset:70:9 to :70:44
  in src/cli.zig
    > %257 = block({%249..%256}) node_offset:70:9 to :70:44

Unable to dump stack trace: AccessDenied

error: the following command terminated unexpectedly:
// ...
Build Summary: 2/4 steps succeeded; 1 failed
check transitive failure
└─ zig build-obj bun-debug Debug native-native.13.0 failure
error: the following build command failed with exit code 1:
/Users/jarred/Code/bun/.zig-cache/o/402939dc2fb74416589e4f3666841165/build /Users/jarred/Code/bun/vendor/zig/zig-debug vendor/zig/lib /Users/jarred/Code/bun /Users/jarred/Code/bun/.zig-cache /Users/jarred/.cache/zig --seed 0x196b1861 -Zdb406110e471a632 check

Note that hasAnyPropertyNamed has this definition:

pub fn hasAnyPropertyNamed(expr: *const Expr, comptime names: []const string) bool

names is supposed to be comptime-known, but we're passing it a runtime-only value here:

 const needs_dependencies = brk: {
                if (fields.object.get("dependencies")) |deps| {
                    for (dependencies, 0..) |*dep, i| {
                        if (deps.hasAnyPropertyNamed(&.{dep.name})) {
                            needed_dependencies.set(i, false);
                        }
                    }
                }

                break :brk needed_dependencies.count() > 0;
            };

And the array itself is defined incorrectly because it's missing the &

Expected Behavior

It should print some error messages telling me what went wrong

@Jarred-Sumner Jarred-Sumner added the bug Observed behavior contradicts documented or intended behavior label Feb 12, 2025
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

1 participant