Skip to content

Invalid assumptions in type resolution logic cause incorrect resolution success, crashing compiler #23344

Open
@DonIsaac

Description

@DonIsaac

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

Found this crash while setting up Zig tests in Bun. You can reproduce it by checking out this PR.

const std = @import("std");
const bun = @import("root").bun;
const t = std.testing;

// un-commenting this line causes the crash
// test {
//     std.testing.refAllDecls(bun);
// }

test "idk strings or something" {
    var s = bun.String.createUTF8("hi"); // it can create `WTF::String`s too
    defer s.deref();
    try t.expectEqual(s.length(), 2);
    try t.expectEqualStrings(s.asUTF8().?, "hi");
}

When building with a ReleaseSafe build of Zig, I get this stack trace:

[1/4] Building src/*.zig for aarch64-macos-none
info: zig compiler v0.14.0
test
└─ install generated to bun-test.o
   └─ zig test bun-test Debug aarch64-macos.13.0-none failure
error: thread 55734837 panic: reached unreachable code
???:?:?: 0x10988a57b in _InternPool.LoadedStructType.RuntimeOrderIterator.next (???)
???:?:?: 0x1097f9bef in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097fbeb7 in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097f9e03 in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097fbeb7 in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097f92ff in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097f9e03 in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097fbeb7 in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097f9e03 in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097fbeb7 in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097f8717 in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x1097fb10b in _codegen.llvm.Object.lowerDebugType (???)
???:?:?: 0x109d10fb3 in _codegen.llvm.Object.updateFunc (???)
???:?:?: 0x109a8dfa3 in _link.doTask (???)
???:?:?: 0x1097e7593 in _Compilation.performAllTheWorkInner (???)
???:?:?: 0x10972bbd3 in _Compilation.update (???)
???:?:?: 0x10976f94b in _main.serve (???)
???:?:?: 0x109789dcb in _main.buildOutputType (???)
???:?:?: 0x1096dd01f in _main (???)
???:?:?: 0x19e124273 in ??? (???)
???:?:?: 0x1806ffffffffffff in ??? (???)

error: the following command terminated unexpectedly:
/Users/donisaac/Documents/bun/bun3/vendor/zig/zig test -freference-trace=24 -fllvm -fno-lld -fno-strip -fno-omit-frame-pointer -ODebug -target aarch64-macos.13.0-none -mcpu apple_m1 --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish --dep build_options --dep translated-c-headers -Mroot=/Users/donisaac/Documents/bun/bun3/src/unit_test.zig -Mzlib-internal=/Users/donisaac/Documents/bun/bun3/src/deps/zlib.posix.zig -Masync=/Users/donisaac/Documents/bun/bun3/src/async/posix_event_loop.zig -MZigGeneratedClasses=/Users/donisaac/Documents/bun/bun3/build/debug/codegen/ZigGeneratedClasses.zig -MResolvedSourceTag=/Users/donisaac/Documents/bun/bun3/build/debug/codegen/ResolvedSourceTag.zig -MErrorCode=/Users/donisaac/Documents/bun/bun3/build/debug/codegen/ErrorCode.zig -Mcompletions-bash=/Users/donisaac/Documents/bun/bun3/completions/bun.bash -Mcompletions-zsh=/Users/donisaac/Documents/bun/bun3/completions/bun.zsh -Mcompletions-fish=/Users/donisaac/Documents/bun/bun3/completions/bun.fish -Mbuild_options=/Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/local/c/da395d47caf5898cd97464e862dd658f/options.zig -ODebug -target aarch64-macos.13.0-none -mcpu apple_m1 -Mtranslated-c-headers=/Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/local/o/cb2c87e16a2efe8826ab5fa894a3fcf0/c-headers-for-zig.zig -lc++ -lc --test-runner /Users/donisaac/Documents/bun/bun3/src/main_test.zig -ffunction-sections -fdata-sections -fallow-shlib-undefined --cache-dir /Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/local --global-cache-dir /Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/global --name bun-test -fno-compiler-rt -fno-ubsan-rt --zig-lib-dir /Users/donisaac/Documents/bun/bun3/vendor/zig/lib/ --listen=-
Build Summary: 2/5 steps succeeded; 1 failed
test transitive failure
└─ install generated to bun-test.o transitive failure
   └─ zig test bun-test Debug aarch64-macos.13.0-none failure
      ├─ options cached
      └─ translate-c cached 25ms MaxRSS:35M
error: the following build command failed with exit code 1:
/Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/local/o/56600897baa72f85f47b0344254a5fd8/build /Users/donisaac/Documents/bun/bun3/vendor/zig/zig /Users/donisaac/Documents/bun/bun3/vendor/zig/lib /Users/donisaac/Documents/bun/bun3 /Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/local /Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/global --seed 0xd21820a4 -Zedd4454974fed375 test --prefix /Users/donisaac/Documents/bun/bun3/build/debug -Dobj_format=obj -Dtarget=aarch64-macos-none -Doptimize=Debug -Dcpu=apple_m1 -Denable_logs=true -Dversion=1.2.6 -Dreported_nodejs_version=22.6.0 -Dcanary=1 -Dcodegen_path=/Users/donisaac/Documents/bun/bun3/build/debug/codegen -Dcodegen_embed=false --prominent-compile-errors --summary all -Dsha=9c1d6fdd2b6f6849fe39cbaf2d0db5af8f9aaef0
FAILED: bun-test.o /Users/donisaac/Documents/bun/bun3/build/debug/bun-test.o
cd /Users/donisaac/Documents/bun/bun3 && /Users/donisaac/Documents/bun/bun3/vendor/zig/zig build test --cache-dir /Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/local --global-cache-dir /Users/donisaac/Documents/bun/bun3/build/debug/cache/zig/global --zig-lib-dir /Users/donisaac/Documents/bun/bun3/vendor/zig/lib --prefix /Users/donisaac/Documents/bun/bun3/build/debug -Dobj_format=obj -Dtarget=aarch64-macos-none -Doptimize=Debug -Dcpu=apple_m1 -Denable_logs=true -Dversion=1.2.6 -Dreported_nodejs_version=22.6.0 -Dcanary=1 -Dcodegen_path=/Users/donisaac/Documents/bun/bun3/build/debug/codegen -Dcodegen_embed=false --prominent-compile-errors --summary all -Dsha=9c1d6fdd2b6f6849fe39cbaf2d0db5af8f9aaef0

Expected Behavior

Build succeeds and tests run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions