bun icon indicating copy to clipboard operation
bun copied to clipboard

Upgrade to latest Zig

Open Jarred-Sumner opened this issue 2 years ago • 7 comments
trafficstars

This is blocked on https://github.com/ziglang/zig/pull/13017.

Posting this PR here so others can follow progress

Jarred-Sumner avatar Dec 13 '22 20:12 Jarred-Sumner

Just FYI

From: https://ziglang.org/news/goodbye-cpp/

Furthermore, this change represents the removal of the -fstage1 flag, which allowed users of Zig to opt out of the new compiler and use the old one. This was the only way to take advantage of async functions, an experimental language feature that is not yet implemented in the new compiler.

I recommend users of -fstage1 to stick with 0.10.0, and then upgrade to 0.10.1 when it is released, and then finally upgrade to 0.11.0, which will have async function support. Note that Zig follows Semantic Versioning and so everything described in this blog post will not be included in the 0.10.1 release, which will only contain bug fixes cherry-picked from master branch.

Zig 0.11.0 Github milestone = https://github.com/ziglang/zig/milestone/17

...Aiming for two weeks after LLVM 16.0.0 release...Due by May 29, 2023

vjpr avatar Dec 15 '22 14:12 vjpr

andrewrk — Today at 20:19 current development focus: ...

  • fixing bugs in the compiler such as the one preventing Bun from updating to latest master branch due to the compiler crashing

...

https://discord.com/channels/605571803288698900/785499283368706060/1053028467517698048

vjpr avatar Dec 15 '22 20:12 vjpr

Rebased against main after @Vexu's changes

Once https://github.com/ziglang/zig/pull/14004 is merged, I'll give it another try

Jarred-Sumner avatar Dec 20 '22 02:12 Jarred-Sumner

Current status: stuck on a confusing compiler error. It seems to think that a function that doesn't use try needs to return an error union type

image
error: expected error union type, found '?*bun.js.javascript_core_c_api.generic'
        return js.JSValueMakeUndefined(ctx);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    readFileAsBytes: src/bun.js/api/bun.zig:801:20
    Class: src/bun.js/api/bun.zig:1129:23
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

/home/jarred/zig/0.11.0-dev.926+266e2e9a3/files/lib/std/mem.zig:3644:9: error: expected []T or *[_]T, passed error{OutOfMemory}![]i32
        @compileError("expected []T or *[_]T, passed " ++ @typeName(sliceType));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jarred/zig/0.11.0-dev.926+266e2e9a3/files/lib/std/mem.zig:3651:59: note: called from here
pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {

Jarred-Sumner avatar Dec 23 '22 00:12 Jarred-Sumner

it was an errdefer

Next up, sliceAsBytes lacks a log that includes the function:

Semantic Analysis [20313] asU16... /home/jarred/zig/0.11.0-dev.926+266e2e9a3/files/lib/std/mem.zig:3645:9: error: expected []T or *[_]T, passed error{OutOfMemory}![]i32
        @compileError("expected []T or *[_]T, passed " ++ @typeName(sliceType));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jarred/zig/0.11.0-dev.926+266e2e9a3/files/lib/std/mem.zig:3652:59: note: called from here
pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
                                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
thread 3301463 panic: Zig compiler bug: attempted to destroy declaration with an attached error
Unable to dump stack trace: debug info stripped
fish: Job 1, '/home/jarred/zig/0.11.0-dev.926…' terminated by signal SIGABRT (Abort)

Jarred-Sumner avatar Dec 23 '22 00:12 Jarred-Sumner

this:

src/io/io_linux.zig:789:32: error: incompatible types: 'error{ConnectionAborted,E2BIG,EACCES,EADDRINUSE,EADDRNOTAVAIL,EADV,EAFNOSUPPORT,EAGAIN,EALREADY,EBADE,EBADF,EBADFD,EBADMSG,EBADR,EBADRQC,EBADSLT,EBFONT,EBUSY,ECANCELED,ECHILD,ECHRNG,ECOMM,ECONNABORTED,ECONNREFUSED,ECONNRESET,EDEADLK,EDEADLOCK,EDESTADDRREQ,EDOM,EDOTDOT,EDQUOT,EEXIST,EFAULT,EFBIG,EHOSTDOWN,EHOSTUNREACH,EHWPOISON,EIDRM,EILSEQ,EINPROGRESS,EINTR,EINVAL,EIO,EISCONN,EISDIR,EISNAM,EKEYEXPIRED,EKEYREJECTED,EKEYREVOKED,EL2HLT,EL2NSYNC,EL3HLT,EL3RST,ELIBACC,ELIBBAD,ELIBEXEC,ELIBMAX,ELIBSCN,ELNRNG,ELOOP,EMEDIUMTYPE,EMFILE,EMLINK,EMSGSIZE,EMULTIHOP,ENAMETOOLONG,ENAVAIL,ENETDOWN,ENETRESET,ENETUNREACH,ENFILE,ENOANO,ENOBUFS,ENOCSI,ENODATA,ENODEV,ENOENT,ENOEXEC,ENOKEY,ENOLCK,ENOLINK,ENOMEDIUM,ENOMEM,ENOMSG,ENONET,ENOPKG,ENOPROTOOPT,ENOSPC,ENOSR,ENOSTR,ENOSYS,ENOTBLK,ENOTCONN,ENOTDIR,ENOTEMPTY,ENOTNAM,ENOTRECOVERABLE,ENOTSOCK,ENOTSUP,ENOTTY,ENOTUNIQ,ENXIO,EOVERFLOW,EOWNERDEAD,EPERM,EPFNOSUPPORT,EPIPE,EPROTO,EPROTONOSUPPORT,EPROTOTYPE,ERANGE,EREMCHG,EREMOTE,EREMOTEIO,ERESTART,ERFKILL,EROFS,ESHUTDOWN,ESOCKTNOSUPPORT,ESPIPE,ESRCH,ESRMNT,ESTALE,ESTRPIPE,ETIME,ETIMEDOUT,ETOOMANYREFS,ETXTBSY,EUCLEAN,EUNATCH,EUSERS,EWOULDBLOCK,EXDEV,EXFULL,FileDescriptorInvalid,FileDescriptorNotASocket,OperationNotSupported,PermissionDenied,ProcessFdQuotaExceeded,ProtocolFailure,SocketNotListening,SystemFdQuotaExceeded,SystemResources,Unexpected,WouldBlock}' and 'i32'
                const result = if (completion.result < 0) switch (-completion.result) {

Jarred-Sumner avatar Dec 23 '22 01:12 Jarred-Sumner

I added a few commits to my branch and was able to successfully compile zig build obj.

Vexu avatar Dec 23 '22 08:12 Vexu

Current status:

  • A test failure in the transpiler regarding macros needs to be fixed
  • https://github.com/ziglang/zig/issues/14059
  • https://github.com/ziglang/zig/pull/13017

Peak RAM usage compiling a release build of bun

zig v0.10: 32 GB zig v0.11: 8 GB

Jarred-Sumner avatar Dec 26 '22 23:12 Jarred-Sumner

I'm going to merge once the test failure in the tranpiler is fixed

Jarred-Sumner avatar Dec 26 '22 23:12 Jarred-Sumner