diff options
Diffstat (limited to 'src/bun.js/node')
-rw-r--r-- | src/bun.js/node/dir_iterator.zig | 17 | ||||
-rw-r--r-- | src/bun.js/node/fs_events.zig | 2 | ||||
-rw-r--r-- | src/bun.js/node/node_fs.zig | 78 | ||||
-rw-r--r-- | src/bun.js/node/node_os.zig | 20 | ||||
-rw-r--r-- | src/bun.js/node/syscall.zig | 106 | ||||
-rw-r--r-- | src/bun.js/node/types.zig | 98 |
6 files changed, 160 insertions, 161 deletions
diff --git a/src/bun.js/node/dir_iterator.zig b/src/bun.js/node/dir_iterator.zig index dac78e5e2..968fde001 100644 --- a/src/bun.js/node/dir_iterator.zig +++ b/src/bun.js/node/dir_iterator.zig @@ -65,13 +65,13 @@ pub const Iterator = switch (builtin.os.tag) { } self.index = 0; - self.end_index = @intCast(usize, rc); + self.end_index = @as(usize, @intCast(rc)); } - const darwin_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]); + const darwin_entry = @as(*align(1) os.system.dirent, @ptrCast(&self.buf[self.index])); const next_index = self.index + darwin_entry.reclen(); self.index = next_index; - const name = @ptrCast([*]u8, &darwin_entry.d_name)[0..darwin_entry.d_namlen]; + const name = @as([*]u8, @ptrCast(&darwin_entry.d_name))[0..darwin_entry.d_namlen]; if (strings.eqlComptime(name, ".") or strings.eqlComptime(name, "..") or (darwin_entry.d_ino == 0)) { continue :start_over; @@ -122,11 +122,11 @@ pub const Iterator = switch (builtin.os.tag) { self.index = 0; self.end_index = rc; } - const linux_entry = @ptrCast(*align(1) linux.dirent64, &self.buf[self.index]); + const linux_entry = @as(*align(1) linux.dirent64, @ptrCast(&self.buf[self.index])); const next_index = self.index + linux_entry.reclen(); self.index = next_index; - const name = mem.sliceTo(@ptrCast([*:0]u8, &linux_entry.d_name), 0); + const name = mem.sliceTo(@as([*:0]u8, @ptrCast(&linux_entry.d_name)), 0); // skip . and .. entries if (strings.eqlComptime(name, ".") or strings.eqlComptime(name, "..")) { @@ -196,15 +196,14 @@ pub const Iterator = switch (builtin.os.tag) { } } - const aligned_ptr = @alignCast(@alignOf(w.FILE_BOTH_DIR_INFORMATION), &self.buf[self.index]); - const dir_info = @ptrCast(*w.FILE_BOTH_DIR_INFORMATION, aligned_ptr); + const dir_info: *w.FILE_BOTH_DIR_INFORMATION = @ptrCast(@alignCast(&self.buf[self.index])); if (dir_info.NextEntryOffset != 0) { self.index += dir_info.NextEntryOffset; } else { self.index = self.buf.len; } - const name_utf16le = @ptrCast([*]u16, &dir_info.FileName)[0 .. dir_info.FileNameLength / 2]; + const name_utf16le = @as([*]u16, @ptrCast(&dir_info.FileName))[0 .. dir_info.FileNameLength / 2]; if (mem.eql(u16, name_utf16le, &[_]u16{'.'}) or mem.eql(u16, name_utf16le, &[_]u16{ '.', '.' })) continue; @@ -260,7 +259,7 @@ pub const Iterator = switch (builtin.os.tag) { self.index = 0; self.end_index = bufused; } - const entry = @ptrCast(*align(1) w.dirent_t, &self.buf[self.index]); + const entry = @as(*align(1) w.dirent_t, @ptrCast(&self.buf[self.index])); const entry_size = @sizeOf(w.dirent_t); const name_index = self.index + entry_size; const name = mem.span(self.buf[name_index .. name_index + entry.d_namlen]); diff --git a/src/bun.js/node/fs_events.zig b/src/bun.js/node/fs_events.zig index a3fba5441..54c969d0f 100644 --- a/src/bun.js/node/fs_events.zig +++ b/src/bun.js/node/fs_events.zig @@ -254,7 +254,7 @@ pub const FSEventsLoop = struct { } pub fn wrap(this: ?*anyopaque) void { - @call(.always_inline, Callback, .{@ptrCast(*Type, @alignCast(@alignOf(Type), this.?))}); + @call(.always_inline, Callback, .{@as(*Type, @ptrCast(@alignCast(this.?)))}); } }; } diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 3f298c5c7..8fb769fac 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -368,7 +368,7 @@ pub const Arguments = struct { }; arguments.eat(); - break :brk @intCast(uid_t, uid_value.toInt32()); + break :brk @as(uid_t, @intCast(uid_value.toInt32())); }; const gid: gid_t = brk: { @@ -385,7 +385,7 @@ pub const Arguments = struct { }; arguments.eat(); - break :brk @intCast(gid_t, gid_value.toInt32()); + break :brk @as(gid_t, @intCast(gid_value.toInt32())); }; return Chown{ .path = path, .uid = uid, .gid = gid }; @@ -438,7 +438,7 @@ pub const Arguments = struct { }; arguments.eat(); - break :brk @intCast(uid_t, uid_value.toInt32()); + break :brk @as(uid_t, @intCast(uid_value.toInt32())); }; const gid: gid_t = brk: { @@ -455,7 +455,7 @@ pub const Arguments = struct { }; arguments.eat(); - break :brk @intCast(gid_t, gid_value.toInt32()); + break :brk @as(gid_t, @intCast(gid_value.toInt32())); }; return Fchown{ .fd = fd, .uid = uid, .gid = gid }; @@ -1672,7 +1672,7 @@ pub const Arguments = struct { } if (arguments.remaining[1].isNumber() or arguments.remaining[1].isBigInt()) - args.position = @intCast(ReadPosition, arguments.remaining[1].to(i52)); + args.position = @as(ReadPosition, @intCast(arguments.remaining[1].to(i52))); arguments.remaining = arguments.remaining[2..]; } else if (current.isObject()) { @@ -1798,7 +1798,7 @@ pub const Arguments = struct { mode: Mode = 0o666, file: PathOrFileDescriptor, data: StringOrBuffer, - dirfd: FileDescriptor = @intCast(FileDescriptor, std.fs.cwd().fd), + dirfd: FileDescriptor = @as(FileDescriptor, @intCast(std.fs.cwd().fd)), pub fn deinit(self: WriteFile) void { self.file.deinit(); @@ -2424,7 +2424,7 @@ pub const Arguments = struct { return CopyFile{ .src = src, .dest = dest, - .mode = @enumFromInt(Constants.Copyfile, mode), + .mode = @as(Constants.Copyfile, @enumFromInt(mode)), }; } }; @@ -2568,7 +2568,7 @@ const Return = struct { ctx.ptr(), &fields.bytesRead, &fields.buffer, - JSC.JSValue.jsNumberFromUint64(@intCast(u52, @min(std.math.maxInt(u52), this.bytes_read))), + JSC.JSValue.jsNumberFromUint64(@as(u52, @intCast(@min(std.math.maxInt(u52), this.bytes_read)))), this.buffer_val, ).asObjectRef(); } @@ -2592,7 +2592,7 @@ const Return = struct { ctx.ptr(), &fields.bytesWritten, &fields.buffer, - JSC.JSValue.jsNumberFromUint64(@intCast(u52, @min(std.math.maxInt(u52), this.bytes_written))), + JSC.JSValue.jsNumberFromUint64(@as(u52, @intCast(@min(std.math.maxInt(u52), this.bytes_written)))), if (this.buffer == .buffer) this.buffer_val else @@ -2805,7 +2805,7 @@ pub const NodeFS = struct { .err => |err| return Maybe(Return.CopyFile){ .err = err }, }; defer { - _ = std.c.ftruncate(dest_fd, @intCast(std.c.off_t, @truncate(u63, wrote))); + _ = std.c.ftruncate(dest_fd, @as(std.c.off_t, @intCast(@as(u63, @truncate(wrote))))); _ = Syscall.close(dest_fd); } @@ -2815,7 +2815,7 @@ pub const NodeFS = struct { // 16 KB is high end of what is okay to use for stack space // good thing we ask for absurdly large stack sizes var buf: [16384]u8 = undefined; - var remain = @intCast(u64, @max(stat_.size, 0)); + var remain = @as(u64, @intCast(@max(stat_.size, 0))); toplevel: while (remain > 0) { const amt = switch (Syscall.read(src_fd, buf[0..@min(buf.len, remain)])) { .result => |result| result, @@ -2913,15 +2913,15 @@ pub const NodeFS = struct { .err => |err| return Maybe(Return.CopyFile){ .err = err }, }; - var size = @intCast(usize, @max(stat_.size, 0)); + var size = @as(usize, @intCast(@max(stat_.size, 0))); defer { - _ = linux.ftruncate(dest_fd, @intCast(i64, @truncate(u63, wrote))); + _ = linux.ftruncate(dest_fd, @as(i64, @intCast(@as(u63, @truncate(wrote))))); _ = Syscall.close(dest_fd); } - var off_in_copy = @bitCast(i64, @as(u64, 0)); - var off_out_copy = @bitCast(i64, @as(u64, 0)); + var off_in_copy = @as(i64, @bitCast(@as(u64, 0))); + var off_out_copy = @as(i64, @bitCast(@as(u64, 0))); if (size == 0) { // copy until EOF @@ -3199,7 +3199,7 @@ pub const NodeFS = struct { .sync => { var buf: [bun.MAX_PATH_BYTES]u8 = undefined; const path = args.path.sliceZWithForceCopy(&buf, true); - const len = @truncate(u16, path.len); + const len = @as(u16, @truncate(path.len)); // First, attempt to create the desired directory // If that fails, then walk back up the path until we have a match @@ -3349,8 +3349,8 @@ pub const NodeFS = struct { }; } // std.c.getErrno(rc) returns SUCCESS if rc is null so we call std.c._errno() directly - const errno = @enumFromInt(std.c.E, std.c._errno().*); - return .{ .err = Syscall.Error{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(errno)), .syscall = .mkdtemp } }; + const errno = @as(std.c.E, @enumFromInt(std.c._errno().*)); + return .{ .err = Syscall.Error{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(errno))), .syscall = .mkdtemp } }; } pub fn open(this: *NodeFS, args: Arguments.Open, comptime flavor: Flavor) Maybe(Return.Open) { switch (comptime flavor) { @@ -3389,7 +3389,7 @@ pub const NodeFS = struct { }, .result => |amt| .{ .result = .{ - .bytes_read = @truncate(u52, amt), + .bytes_read = @as(u52, @truncate(amt)), }, }, }; @@ -3413,7 +3413,7 @@ pub const NodeFS = struct { }, .result => |amt| .{ .result = .{ - .bytes_read = @truncate(u52, amt), + .bytes_read = @as(u52, @truncate(amt)), }, }, }; @@ -3461,7 +3461,7 @@ pub const NodeFS = struct { }, .result => |amt| .{ .result = .{ - .bytes_written = @truncate(u52, amt), + .bytes_written = @as(u52, @truncate(amt)), }, }, }; @@ -3486,7 +3486,7 @@ pub const NodeFS = struct { .err = err, }, .result => |amt| .{ .result = .{ - .bytes_written = @truncate(u52, amt), + .bytes_written = @as(u52, @truncate(amt)), } }, }; }, @@ -3506,7 +3506,7 @@ pub const NodeFS = struct { .err = err, }, .result => |amt| .{ .result = .{ - .bytes_read = @truncate(u52, amt), + .bytes_read = @as(u52, @truncate(amt)), } }, }; }, @@ -3524,7 +3524,7 @@ pub const NodeFS = struct { .err = err, }, .result => |amt| .{ .result = .{ - .bytes_read = @truncate(u52, amt), + .bytes_read = @as(u52, @truncate(amt)), } }, }; }, @@ -3544,7 +3544,7 @@ pub const NodeFS = struct { .err = err, }, .result => |amt| .{ .result = .{ - .bytes_written = @truncate(u52, amt), + .bytes_written = @as(u52, @truncate(amt)), } }, }; }, @@ -3562,7 +3562,7 @@ pub const NodeFS = struct { .err = err, }, .result => |amt| .{ .result = .{ - .bytes_written = @truncate(u52, amt), + .bytes_written = @as(u52, @truncate(amt)), } }, }; }, @@ -3775,21 +3775,21 @@ pub const NodeFS = struct { } // For certain files, the size might be 0 but the file might still have contents. - const size = @intCast( + const size = @as( u64, - @max( + @intCast(@max( @min( stat_.size, - @intCast( + @as( @TypeOf(stat_.size), // Only used in DOMFormData - args.max_size orelse std.math.maxInt( + @intCast(args.max_size orelse std.math.maxInt( JSC.WebCore.Blob.SizeType, - ), + )), ), ), 0, - ), + )), ) + if (comptime string_type == .null_terminated) 1 else 0; var buf = std.ArrayList(u8).init(bun.default_allocator); @@ -3937,20 +3937,20 @@ pub const NodeFS = struct { // on linux, it's absolutely positioned const pos = JSC.Node.Syscall.system.lseek( fd, - @intCast(std.os.off_t, 0), + @as(std.os.off_t, @intCast(0)), std.os.linux.SEEK.CUR, ); switch (JSC.Node.Syscall.getErrno(pos)) { - .SUCCESS => break :brk @intCast(usize, pos), + .SUCCESS => break :brk @as(usize, @intCast(pos)), else => break :preallocate, } }; bun.C.preallocate_file( fd, - @intCast(std.os.off_t, offset), - @intCast(std.os.off_t, buf.len), + @as(std.os.off_t, @intCast(offset)), + @as(std.os.off_t, @intCast(buf.len)), ) catch {}; } } @@ -3973,7 +3973,7 @@ pub const NodeFS = struct { // https://github.com/oven-sh/bun/issues/2931 if ((@intFromEnum(args.flag) & std.os.O.APPEND) == 0) { - _ = ftruncateSync(.{ .fd = fd, .len = @truncate(JSC.WebCore.Blob.SizeType, written) }); + _ = ftruncateSync(.{ .fd = fd, .len = @as(JSC.WebCore.Blob.SizeType, @truncate(written)) }); } return Maybe(Return.WriteFile).success; @@ -4119,7 +4119,7 @@ pub const NodeFS = struct { while (true) { if (Maybe(Return.Rmdir).errnoSys(bun.C.darwin.removefileat(std.os.AT.FDCWD, dest, null, flags), .rmdir)) |errno| { - switch (@enumFromInt(os.E, errno.err.errno)) { + switch (@as(os.E, @enumFromInt(errno.err.errno))) { .AGAIN, .INTR => continue, .NOENT => return Maybe(Return.Rmdir).success, .MLINK => { @@ -4206,7 +4206,7 @@ pub const NodeFS = struct { } if (Maybe(Return.Rm).errnoSys(bun.C.darwin.removefileat(std.os.AT.FDCWD, dest, null, flags), .unlink)) |errno| { - switch (@enumFromInt(os.E, errno.err.errno)) { + switch (@as(os.E, @enumFromInt(errno.err.errno))) { .AGAIN, .INTR => continue, .NOENT => { if (args.force) { diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig index 483acb3e2..5710b5c21 100644 --- a/src/bun.js/node/node_os.zig +++ b/src/bun.js/node/node_os.zig @@ -207,7 +207,7 @@ pub const Os = struct { var num_cpus: c.natural_t = 0; var info: [*]local_bindings.processor_cpu_load_info = undefined; var info_size: std.c.mach_msg_type_number_t = 0; - if (local_bindings.host_processor_info(std.c.mach_host_self(), local_bindings.PROCESSOR_CPU_LOAD_INFO, &num_cpus, @ptrCast(*local_bindings.processor_info_array_t, &info), &info_size) != .SUCCESS) { + if (local_bindings.host_processor_info(std.c.mach_host_self(), local_bindings.PROCESSOR_CPU_LOAD_INFO, &num_cpus, @as(*local_bindings.processor_info_array_t, @ptrCast(&info)), &info_size) != .SUCCESS) { return error.no_processor_info; } defer _ = std.c.vm_deallocate(std.c.mach_task_self(), @intFromPtr(info), info_size); @@ -247,10 +247,10 @@ pub const Os = struct { @cInclude("unistd.h"); }); const ticks: i64 = unistd.sysconf(unistd._SC_CLK_TCK); - const multiplier = 1000 / @intCast(u64, ticks); + const multiplier = 1000 / @as(u64, @intCast(ticks)); // Set up each CPU value in the return - const values = JSC.JSValue.createEmptyArray(globalThis, @intCast(u32, num_cpus)); + const values = JSC.JSValue.createEmptyArray(globalThis, @as(u32, @intCast(num_cpus))); var cpu_index: u32 = 0; while (cpu_index < num_cpus) : (cpu_index += 1) { const times = CPUTimes{ @@ -436,8 +436,8 @@ pub const Os = struct { if (helpers.skip(iface) or helpers.isLinkLayer(iface)) continue; const interface_name = std.mem.sliceTo(iface.ifa_name, 0); - const addr = std.net.Address.initPosix(@alignCast(4, @ptrCast(*std.os.sockaddr, iface.ifa_addr))); - const netmask = std.net.Address.initPosix(@alignCast(4, @ptrCast(*std.os.sockaddr, iface.ifa_netmask))); + const addr = std.net.Address.initPosix(@alignCast(@as(*std.os.sockaddr, @ptrCast(iface.ifa_addr)))); + const netmask = std.net.Address.initPosix(@alignCast(@as(*std.os.sockaddr, @ptrCast(iface.ifa_netmask)))); var interface = JSC.JSValue.createEmptyObject(globalThis, 7); @@ -448,7 +448,7 @@ pub const Os = struct { // be converted to a CIDR suffix const maybe_suffix: ?u8 = switch (addr.any.family) { std.os.AF.INET => netmaskToCIDRSuffix(netmask.in.sa.addr), - std.os.AF.INET6 => netmaskToCIDRSuffix(@bitCast(u128, netmask.in6.sa.addr)), + std.os.AF.INET6 => netmaskToCIDRSuffix(@as(u128, @bitCast(netmask.in6.sa.addr))), else => null, }; @@ -500,9 +500,9 @@ pub const Os = struct { // This is the correct link-layer interface entry for the current interface, // cast to a link-layer socket address if (comptime Environment.isLinux) { - break @ptrCast(?*std.os.sockaddr.ll, @alignCast(4, ll_iface.ifa_addr)); + break @as(?*std.os.sockaddr.ll, @ptrCast(@alignCast(ll_iface.ifa_addr))); } else if (comptime Environment.isMac) { - break @ptrCast(?*C.sockaddr_dl, @alignCast(2, ll_iface.ifa_addr)); + break @as(?*C.sockaddr_dl, @ptrCast(@alignCast(ll_iface.ifa_addr))); } else unreachable; } else null; @@ -530,7 +530,7 @@ pub const Os = struct { // Does this entry already exist? if (ret.get(globalThis, interface_name)) |array| { // Add this interface entry to the existing array - const next_index = @intCast(u32, array.getLength(globalThis)); + const next_index = @as(u32, @intCast(array.getLength(globalThis))); array.putIndex(globalThis, next_index, interface); } else { // Add it as an array with this interface as an element @@ -750,7 +750,7 @@ test "netmaskToCIDRSuffix" { }; inline for (ipv6_tests) |t| { const addr = try std.net.Address.parseIp6(t[0], 0); - const bits = @bitCast(u128, addr.in6.sa.addr); + const bits = @as(u128, @bitCast(addr.in6.sa.addr)); try std.testing.expectEqual(@as(?u8, t[1]), netmaskToCIDRSuffix(bits)); } } diff --git a/src/bun.js/node/syscall.zig b/src/bun.js/node/syscall.zig index 5ff0b2f44..4dbb23f0d 100644 --- a/src/bun.js/node/syscall.zig +++ b/src/bun.js/node/syscall.zig @@ -182,7 +182,7 @@ pub fn mkdir(file_path: [:0]const u8, flags: JSC.Node.Mode) Maybe(void) { pub fn fcntl(fd: bun.FileDescriptor, cmd: i32, arg: usize) Maybe(usize) { const result = fcntl_symbol(fd, cmd, arg); if (Maybe(usize).errnoSys(result, .fcntl)) |err| return err; - return .{ .result = @intCast(usize, result) }; + return .{ .result = @as(usize, @intCast(result)) }; } pub fn getErrno(rc: anytype) std.os.E { @@ -191,7 +191,7 @@ pub fn getErrno(rc: anytype) std.os.E { return switch (Type) { comptime_int, usize => std.os.linux.getErrno(@as(usize, rc)), - i32, c_int, isize => std.os.linux.getErrno(@bitCast(usize, @as(isize, rc))), + i32, c_int, isize => std.os.linux.getErrno(@as(usize, @bitCast(@as(isize, rc)))), else => @compileError("Not implemented yet for type " ++ @typeName(Type)), }; } @@ -199,14 +199,14 @@ pub fn getErrno(rc: anytype) std.os.E { pub fn openat(dirfd: bun.FileDescriptor, file_path: [:0]const u8, flags: JSC.Node.Mode, perm: JSC.Node.Mode) Maybe(bun.FileDescriptor) { if (comptime Environment.isMac) { // https://opensource.apple.com/source/xnu/xnu-7195.81.3/libsyscall/wrappers/open-base.c - const rc = bun.AsyncIO.darwin.@"openat$NOCANCEL"(dirfd, file_path.ptr, @intCast(c_uint, flags), @intCast(c_int, perm)); + const rc = bun.AsyncIO.darwin.@"openat$NOCANCEL"(dirfd, file_path.ptr, @as(c_uint, @intCast(flags)), @as(c_int, @intCast(perm))); log("openat({d}, {s}) = {d}", .{ dirfd, file_path, rc }); return switch (Syscall.getErrno(rc)) { - .SUCCESS => .{ .result = @intCast(bun.FileDescriptor, rc) }, + .SUCCESS => .{ .result = @as(bun.FileDescriptor, @intCast(rc)) }, else => |err| .{ .err = .{ - .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), + .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))), .syscall = .open, }, }, @@ -214,15 +214,15 @@ pub fn openat(dirfd: bun.FileDescriptor, file_path: [:0]const u8, flags: JSC.Nod } while (true) { - const rc = Syscall.system.openat(@intCast(Syscall.system.fd_t, dirfd), file_path, flags, perm); + const rc = Syscall.system.openat(@as(Syscall.system.fd_t, @intCast(dirfd)), file_path, flags, perm); log("openat({d}, {s}) = {d}", .{ dirfd, file_path, rc }); return switch (Syscall.getErrno(rc)) { - .SUCCESS => .{ .result = @intCast(bun.FileDescriptor, rc) }, + .SUCCESS => .{ .result = @as(bun.FileDescriptor, @intCast(rc)) }, .INTR => continue, else => |err| { return Maybe(std.os.fd_t){ .err = .{ - .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), + .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))), .syscall = .open, }, }; @@ -235,7 +235,7 @@ pub fn openat(dirfd: bun.FileDescriptor, file_path: [:0]const u8, flags: JSC.Nod pub fn open(file_path: [:0]const u8, flags: JSC.Node.Mode, perm: JSC.Node.Mode) Maybe(bun.FileDescriptor) { // this is what open() does anyway. - return openat(@intCast(bun.FileDescriptor, std.fs.cwd().fd), file_path, flags, perm); + return openat(@as(bun.FileDescriptor, @intCast(std.fs.cwd().fd)), file_path, flags, perm); } /// This function will prevent stdout and stderr from being closed. @@ -289,7 +289,7 @@ pub fn write(fd: os.fd_t, bytes: []const u8) Maybe(usize) { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } else { while (true) { const rc = sys.write(fd, bytes.ptr, adjusted_len); @@ -300,7 +300,7 @@ pub fn write(fd: os.fd_t, bytes: []const u8) Maybe(usize) { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } unreachable; } @@ -316,7 +316,7 @@ fn veclen(buffers: anytype) usize { pub fn writev(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) { if (comptime Environment.isMac) { - const rc = writev_sym(fd, @ptrCast([*]std.os.iovec_const, buffers.ptr), @intCast(i32, buffers.len)); + const rc = writev_sym(fd, @as([*]std.os.iovec_const, @ptrCast(buffers.ptr)), @as(i32, @intCast(buffers.len))); if (comptime Environment.allow_assert) log("writev({d}, {d}) = {d}", .{ fd, veclen(buffers), rc }); @@ -324,10 +324,10 @@ pub fn writev(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } else { while (true) { - const rc = writev_sym(fd, @ptrCast([*]std.os.iovec_const, buffers.ptr), buffers.len); + const rc = writev_sym(fd, @as([*]std.os.iovec_const, @ptrCast(buffers.ptr)), buffers.len); if (comptime Environment.allow_assert) log("writev({d}, {d}) = {d}", .{ fd, veclen(buffers), rc }); @@ -336,7 +336,7 @@ pub fn writev(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } unreachable; } @@ -344,7 +344,7 @@ pub fn writev(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) { pub fn pwritev(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usize) { if (comptime Environment.isMac) { - const rc = pwritev_sym(fd, @ptrCast([*]std.os.iovec_const, buffers.ptr), @intCast(i32, buffers.len), position); + const rc = pwritev_sym(fd, @as([*]std.os.iovec_const, @ptrCast(buffers.ptr)), @as(i32, @intCast(buffers.len)), position); if (comptime Environment.allow_assert) log("pwritev({d}, {d}) = {d}", .{ fd, veclen(buffers), rc }); @@ -352,10 +352,10 @@ pub fn pwritev(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usiz return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } else { while (true) { - const rc = pwritev_sym(fd, @ptrCast([*]std.os.iovec_const, buffers.ptr), buffers.len, position); + const rc = pwritev_sym(fd, @as([*]std.os.iovec_const, @ptrCast(buffers.ptr)), buffers.len, position); if (comptime Environment.allow_assert) log("pwritev({d}, {d}) = {d}", .{ fd, veclen(buffers), rc }); @@ -364,7 +364,7 @@ pub fn pwritev(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usiz return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } unreachable; } @@ -372,7 +372,7 @@ pub fn pwritev(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usiz pub fn readv(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) { if (comptime Environment.isMac) { - const rc = readv_sym(fd, buffers.ptr, @intCast(i32, buffers.len)); + const rc = readv_sym(fd, buffers.ptr, @as(i32, @intCast(buffers.len))); if (comptime Environment.allow_assert) log("readv({d}, {d}) = {d}", .{ fd, veclen(buffers), rc }); @@ -380,7 +380,7 @@ pub fn readv(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } else { while (true) { const rc = readv_sym(fd, buffers.ptr, buffers.len); @@ -392,7 +392,7 @@ pub fn readv(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } unreachable; } @@ -400,7 +400,7 @@ pub fn readv(fd: os.fd_t, buffers: []std.os.iovec) Maybe(usize) { pub fn preadv(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usize) { if (comptime Environment.isMac) { - const rc = preadv_sym(fd, buffers.ptr, @intCast(i32, buffers.len), position); + const rc = preadv_sym(fd, buffers.ptr, @as(i32, @intCast(buffers.len)), position); if (comptime Environment.allow_assert) log("preadv({d}, {d}) = {d}", .{ fd, veclen(buffers), rc }); @@ -408,7 +408,7 @@ pub fn preadv(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usize return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } else { while (true) { const rc = preadv_sym(fd, buffers.ptr, buffers.len, position); @@ -420,7 +420,7 @@ pub fn preadv(fd: os.fd_t, buffers: []std.os.iovec, position: isize) Maybe(usize return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } unreachable; } @@ -465,14 +465,14 @@ const fcntl_symbol = system.fcntl; pub fn pread(fd: os.fd_t, buf: []u8, offset: i64) Maybe(usize) { const adjusted_len = @min(buf.len, max_count); - const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned + const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned while (true) { const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset); if (Maybe(usize).errnoSys(rc, .pread)) |err| { if (err.getErrno() == .INTR) continue; return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } unreachable; } @@ -485,7 +485,7 @@ else pub fn pwrite(fd: os.fd_t, bytes: []const u8, offset: i64) Maybe(usize) { const adjusted_len = @min(bytes.len, max_count); - const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned + const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned while (true) { const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset); return if (Maybe(usize).errnoSysFd(rc, .pwrite, fd)) |err| { @@ -493,7 +493,7 @@ pub fn pwrite(fd: os.fd_t, bytes: []const u8, offset: i64) Maybe(usize) { .INTR => continue, else => return err, } - } else Maybe(usize){ .result = @intCast(usize, rc) }; + } else Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } unreachable; @@ -510,7 +510,7 @@ pub fn read(fd: os.fd_t, buf: []u8) Maybe(usize) { if (Maybe(usize).errnoSys(rc, .read)) |err| { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } else { while (true) { const rc = sys.read(fd, buf.ptr, adjusted_len); @@ -520,7 +520,7 @@ pub fn read(fd: os.fd_t, buf: []u8) Maybe(usize) { if (err.getErrno() == .INTR) continue; return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } } unreachable; @@ -537,7 +537,7 @@ pub fn recv(fd: os.fd_t, buf: []u8, flag: u32) Maybe(usize) { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } else { while (true) { const rc = linux.recvfrom(fd, buf.ptr, adjusted_len, flag | os.SOCK.CLOEXEC | linux.MSG.CMSG_CLOEXEC, null, null); @@ -547,7 +547,7 @@ pub fn recv(fd: os.fd_t, buf: []u8, flag: u32) Maybe(usize) { if (err.getErrno() == .INTR) continue; return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } } unreachable; @@ -559,7 +559,7 @@ pub fn send(fd: os.fd_t, buf: []const u8, flag: u32) Maybe(usize) { if (Maybe(usize).errnoSys(rc, .send)) |err| { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } else { while (true) { const rc = linux.sendto(fd, buf.ptr, buf.len, flag | os.SOCK.CLOEXEC | os.MSG.NOSIGNAL, null, 0); @@ -569,7 +569,7 @@ pub fn send(fd: os.fd_t, buf: []const u8, flag: u32) Maybe(usize) { return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } } unreachable; @@ -583,7 +583,7 @@ pub fn readlink(in: [:0]const u8, buf: []u8) Maybe(usize) { if (err.getErrno() == .INTR) continue; return err; } - return Maybe(usize){ .result = @intCast(usize, rc) }; + return Maybe(usize){ .result = @as(usize, @intCast(rc)) }; } unreachable; } @@ -741,16 +741,16 @@ fn mmap( fd: os.fd_t, offset: u64, ) Maybe([]align(mem.page_size) u8) { - const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned + const ioffset = @as(i64, @bitCast(offset)); // the OS treats this as unsigned const rc = std.c.mmap(ptr, length, prot, flags, fd, ioffset); const fail = std.c.MAP.FAILED; if (rc == fail) { return Maybe([]align(mem.page_size) u8){ - .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(std.c.getErrno(@bitCast(i64, @intFromPtr(fail))))), .syscall = .mmap }, + .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(std.c.getErrno(@as(i64, @bitCast(@intFromPtr(fail))))))), .syscall = .mmap }, }; } - return Maybe([]align(mem.page_size) u8){ .result = @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length] }; + return Maybe([]align(mem.page_size) u8){ .result = @as([*]align(mem.page_size) u8, @ptrCast(@alignCast(rc)))[0..length] }; } pub fn mmapFile(path: [:0]const u8, flags: u32, wanted_size: ?usize, offset: usize) Maybe([]align(mem.page_size) u8) { @@ -759,13 +759,13 @@ pub fn mmapFile(path: [:0]const u8, flags: u32, wanted_size: ?usize, offset: usi .err => |err| return .{ .err = err }, }; - var size = std.math.sub(usize, @intCast(usize, switch (fstat(fd)) { + var size = std.math.sub(usize, @as(usize, @intCast(switch (fstat(fd)) { .result => |result| result.size, .err => |err| { _ = close(fd); return .{ .err = err }; }, - }), offset) catch 0; + })), offset) catch 0; if (wanted_size) |size_| size = @min(size, size_); @@ -804,7 +804,7 @@ pub const Error = struct { pub const Int: type = std.math.IntFittingRange(0, max_errno_value + 5); errno: Int, - syscall: Syscall.Tag = @enumFromInt(Syscall.Tag, 0), + syscall: Syscall.Tag = @as(Syscall.Tag, @enumFromInt(0)), path: []const u8 = "", fd: i32 = -1, @@ -813,7 +813,7 @@ pub const Error = struct { } pub fn fromCode(errno: os.E, syscall: Syscall.Tag) Error { - return .{ .errno = @truncate(Int, @intFromEnum(errno)), .syscall = syscall }; + return .{ .errno = @as(Int, @truncate(@intFromEnum(errno))), .syscall = syscall }; } pub fn format(self: Error, comptime fmt: []const u8, opts: std.fmt.FormatOptions, writer: anytype) !void { @@ -824,16 +824,16 @@ pub const Error = struct { pub const retry = Error{ .errno = if (Environment.isLinux) - @intCast(Int, @intFromEnum(os.E.AGAIN)) + @as(Int, @intCast(@intFromEnum(os.E.AGAIN))) else if (Environment.isMac) - @intCast(Int, @intFromEnum(os.E.WOULDBLOCK)) + @as(Int, @intCast(@intFromEnum(os.E.WOULDBLOCK))) else - @intCast(Int, @intFromEnum(os.E.INTR)), + @as(Int, @intCast(@intFromEnum(os.E.INTR))), .syscall = .retry, }; pub inline fn getErrno(this: Error) os.E { - return @enumFromInt(os.E, this.errno); + return @as(os.E, @enumFromInt(this.errno)); } pub inline fn withPath(this: Error, path: anytype) Error { @@ -848,7 +848,7 @@ pub const Error = struct { return Error{ .errno = this.errno, .syscall = this.syscall, - .fd = @intCast(i32, fd), + .fd = @as(i32, @intCast(fd)), }; } @@ -878,7 +878,7 @@ pub const Error = struct { // errno label if (this.errno > 0 and this.errno < C.SystemErrno.max) { - const system_errno = @enumFromInt(C.SystemErrno, this.errno); + const system_errno = @as(C.SystemErrno, @enumFromInt(this.errno)); err.code = bun.String.static(@tagName(system_errno)); if (C.SystemErrno.labels.get(system_errno)) |label| { err.message = bun.String.static(label); @@ -935,9 +935,9 @@ pub fn setPipeCapacityOnLinux(fd: bun.FileDescriptor, capacity: usize) Maybe(usi } pub fn getMaxPipeSizeOnLinux() usize { - return @intCast( + return @as( usize, - bun.once(struct { + @intCast(bun.once(struct { fn once() c_int { const strings = bun.strings; const default_out_size = 512 * 1024; @@ -963,8 +963,8 @@ pub fn getMaxPipeSizeOnLinux() usize { // we set the absolute max to 8 MB because honestly that's a huge pipe // my current linux machine only goes up to 1 MB, so that's very unlikely to be hit - return @min(@truncate(c_int, max_pipe_size -| 32), 1024 * 1024 * 8); + return @min(@as(c_int, @truncate(max_pipe_size -| 32)), 1024 * 1024 * 8); } - }.once, c_int), + }.once, c_int)), ); } diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 0b19c7fcc..975a281e5 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -139,7 +139,7 @@ pub fn Maybe(comptime ResultType: type) type { pub inline fn getErrno(this: @This()) os.E { return switch (this) { .result => os.E.SUCCESS, - .err => |err| @enumFromInt(os.E, err.errno), + .err => |err| @as(os.E, @enumFromInt(err.errno)), }; } @@ -148,7 +148,7 @@ pub fn Maybe(comptime ResultType: type) type { .SUCCESS => null, else => |err| @This(){ // always truncate - .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)) }, + .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))) }, }, }; } @@ -158,7 +158,7 @@ pub fn Maybe(comptime ResultType: type) type { .SUCCESS => null, else => |err| @This(){ // always truncate - .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), .syscall = syscall }, + .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))), .syscall = syscall }, }, }; } @@ -169,9 +169,9 @@ pub fn Maybe(comptime ResultType: type) type { else => |err| @This(){ // always truncate .err = .{ - .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), + .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))), .syscall = syscall, - .fd = @intCast(i32, fd), + .fd = @as(i32, @intCast(fd)), }, }, }; @@ -182,7 +182,7 @@ pub fn Maybe(comptime ResultType: type) type { .SUCCESS => null, else => |err| @This(){ // always truncate - .err = .{ .errno = @truncate(Syscall.Error.Int, @intFromEnum(err)), .syscall = syscall, .path = bun.asByteSlice(path) }, + .err = .{ .errno = @as(Syscall.Error.Int, @truncate(@intFromEnum(err))), .syscall = syscall, .path = bun.asByteSlice(path) }, }, }; } @@ -203,7 +203,7 @@ pub const StringOrBuffer = union(Tag) { } pub export fn external_string_finalizer(_: ?*anyopaque, _: JSC.C.JSStringRef, buffer: *anyopaque, byteLength: usize) void { - bun.default_allocator.free(@ptrCast([*]const u8, buffer)[0..byteLength]); + bun.default_allocator.free(@as([*]const u8, @ptrCast(buffer))[0..byteLength]); } pub fn toJS(this: StringOrBuffer, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef { @@ -846,7 +846,7 @@ pub const VectorArrayBuffer = struct { bufferlist.ensureTotalCapacityPrecise(len) catch @panic("Failed to allocate memory for ArrayBuffer[]"); while (i < len) { - const element = val.getIndex(globalObject, @truncate(u32, i)); + const element = val.getIndex(globalObject, @as(u32, @truncate(i))); if (!element.isCell()) { JSC.throwInvalidArguments("Expected ArrayBufferView[]", .{}, globalObject, exception); @@ -906,7 +906,7 @@ pub const ArgumentsSlice = struct { } pub fn from(vm: *JSC.VirtualMachine, arguments: []const JSC.JSValueRef) ArgumentsSlice { - return init(vm, @ptrCast([*]const JSC.JSValue, arguments.ptr)[0..arguments.len]); + return init(vm, @as([*]const JSC.JSValue, @ptrCast(arguments.ptr))[0..arguments.len]); } pub fn init(vm: *JSC.VirtualMachine, arguments: []const JSC.JSValue) ArgumentsSlice { return ArgumentsSlice{ @@ -918,7 +918,7 @@ pub const ArgumentsSlice = struct { } pub inline fn len(this: *const ArgumentsSlice) u16 { - return @truncate(u16, this.remaining.len); + return @as(u16, @truncate(this.remaining.len)); } pub fn eat(this: *ArgumentsSlice) void { if (this.remaining.len == 0) { @@ -952,7 +952,7 @@ pub fn fileDescriptorFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, excepti return null; } - return @truncate(bun.FileDescriptor, fd); + return @as(bun.FileDescriptor, @truncate(fd)); } // Node.js docs: @@ -965,7 +965,7 @@ pub fn timeLikeFromJS(globalThis: *JSC.JSGlobalObject, value: JSC.JSValue, _: JS return null; } - return @truncate(TimeLike, @intFromFloat(i64, milliseconds / @as(f64, std.time.ms_per_s))); + return @as(TimeLike, @truncate(@as(i64, @intFromFloat(milliseconds / @as(f64, std.time.ms_per_s))))); } if (!value.isNumber() and !value.isString()) { @@ -977,12 +977,12 @@ pub fn timeLikeFromJS(globalThis: *JSC.JSGlobalObject, value: JSC.JSValue, _: JS return null; } - return @truncate(TimeLike, @intFromFloat(i64, seconds)); + return @as(TimeLike, @truncate(@as(i64, @intFromFloat(seconds)))); } pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, exception: JSC.C.ExceptionRef) ?Mode { const mode_int = if (value.isNumber()) - @truncate(Mode, value.to(Mode)) + @as(Mode, @truncate(value.to(Mode))) else brk: { if (value.isUndefinedOrNull()) return null; @@ -1062,7 +1062,7 @@ pub const PathOrFileDescriptor = union(Tag) { pub fn toJS(this: JSC.Node.PathOrFileDescriptor, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef { return switch (this) { .path => this.path.toJS(ctx, exception), - .fd => JSC.JSValue.jsNumberFromInt32(@intCast(i32, this.fd)).asRef(), + .fd => JSC.JSValue.jsNumberFromInt32(@as(i32, @intCast(this.fd))).asRef(), }; } }; @@ -1167,7 +1167,7 @@ pub const FileSystemFlags = enum(Mode) { pub fn fromJS(ctx: JSC.C.JSContextRef, val: JSC.JSValue, exception: JSC.C.ExceptionRef) ?FileSystemFlags { if (val.isNumber()) { const number = val.coerce(i32, ctx); - return @enumFromInt(FileSystemFlags, @intCast(Mode, @max(number, 0))); + return @as(FileSystemFlags, @enumFromInt(@as(Mode, @intCast(@max(number, 0))))); } const jsType = val.jsType(); @@ -1198,7 +1198,7 @@ pub const FileSystemFlags = enum(Mode) { inline else => |is_16bit| { const chars = if (is_16bit) str.utf16SliceAligned() else str.slice(); - if (std.ascii.isDigit(@truncate(u8, chars[0]))) { + if (std.ascii.isDigit(@as(u8, @truncate(chars[0])))) { // node allows "0o644" as a string :( if (is_16bit) { const slice = str.toSlice(bun.default_allocator); @@ -1223,7 +1223,7 @@ pub const FileSystemFlags = enum(Mode) { return null; }; - return @enumFromInt(FileSystemFlags, @intCast(Mode, flags)); + return @as(FileSystemFlags, @enumFromInt(@as(Mode, @intCast(flags)))); } return null; @@ -1235,7 +1235,7 @@ pub const Date = enum(u64) { _, pub fn toJS(this: Date, ctx: JSC.C.JSContextRef, exception: JSC.C.ExceptionRef) JSC.C.JSValueRef { - const seconds = @floatCast(f64, @floatFromInt(f64, @intFromEnum(this)) * 1000.0); + const seconds = @as(f64, @floatCast(@as(f64, @floatFromInt(@intFromEnum(this))) * 1000.0)); const unix_timestamp = JSC.JSValue.jsNumber(seconds); const array: [1]JSC.C.JSValueRef = .{unix_timestamp.asObjectRef()}; const obj = JSC.C.JSObjectMakeDate(ctx, 1, &array, exception); @@ -1272,34 +1272,34 @@ fn StatsDataType(comptime T: type) type { const ctime = stat_.ctime(); return @This(){ - .dev = @truncate(T, @intCast(i64, stat_.dev)), - .ino = @truncate(T, @intCast(i64, stat_.ino)), - .mode = @truncate(T, @intCast(i64, stat_.mode)), - .nlink = @truncate(T, @intCast(i64, stat_.nlink)), - .uid = @truncate(T, @intCast(i64, stat_.uid)), - .gid = @truncate(T, @intCast(i64, stat_.gid)), - .rdev = @truncate(T, @intCast(i64, stat_.rdev)), - .size = @truncate(T, @intCast(i64, stat_.size)), - .blksize = @truncate(T, @intCast(i64, stat_.blksize)), - .blocks = @truncate(T, @intCast(i64, stat_.blocks)), - .atime_ms = (@floatFromInt(f64, @max(atime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(atime.tv_nsec, 0))) / std.time.ns_per_ms), - .mtime_ms = (@floatFromInt(f64, @max(mtime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(mtime.tv_nsec, 0))) / std.time.ns_per_ms), - .ctime_ms = (@floatFromInt(f64, @max(ctime.tv_sec, 0)) * std.time.ms_per_s) + (@floatFromInt(f64, @intCast(usize, @max(ctime.tv_nsec, 0))) / std.time.ns_per_ms), - .atime = @enumFromInt(Date, @intCast(u64, @max(atime.tv_sec, 0))), - .mtime = @enumFromInt(Date, @intCast(u64, @max(mtime.tv_sec, 0))), - .ctime = @enumFromInt(Date, @intCast(u64, @max(ctime.tv_sec, 0))), + .dev = @as(T, @truncate(@as(i64, @intCast(stat_.dev)))), + .ino = @as(T, @truncate(@as(i64, @intCast(stat_.ino)))), + .mode = @as(T, @truncate(@as(i64, @intCast(stat_.mode)))), + .nlink = @as(T, @truncate(@as(i64, @intCast(stat_.nlink)))), + .uid = @as(T, @truncate(@as(i64, @intCast(stat_.uid)))), + .gid = @as(T, @truncate(@as(i64, @intCast(stat_.gid)))), + .rdev = @as(T, @truncate(@as(i64, @intCast(stat_.rdev)))), + .size = @as(T, @truncate(@as(i64, @intCast(stat_.size)))), + .blksize = @as(T, @truncate(@as(i64, @intCast(stat_.blksize)))), + .blocks = @as(T, @truncate(@as(i64, @intCast(stat_.blocks)))), + .atime_ms = (@as(f64, @floatFromInt(@max(atime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(atime.tv_nsec, 0))))) / std.time.ns_per_ms), + .mtime_ms = (@as(f64, @floatFromInt(@max(mtime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(mtime.tv_nsec, 0))))) / std.time.ns_per_ms), + .ctime_ms = (@as(f64, @floatFromInt(@max(ctime.tv_sec, 0))) * std.time.ms_per_s) + (@as(f64, @floatFromInt(@as(usize, @intCast(@max(ctime.tv_nsec, 0))))) / std.time.ns_per_ms), + .atime = @as(Date, @enumFromInt(@as(u64, @intCast(@max(atime.tv_sec, 0))))), + .mtime = @as(Date, @enumFromInt(@as(u64, @intCast(@max(mtime.tv_sec, 0))))), + .ctime = @as(Date, @enumFromInt(@as(u64, @intCast(@max(ctime.tv_sec, 0))))), // Linux doesn't include this info in stat // maybe it does in statx, but do you really need birthtime? If you do please file an issue. .birthtime_ms = if (Environment.isLinux) 0 else - @truncate(T, @intCast(i64, if (stat_.birthtime().tv_nsec > 0) (@intCast(usize, stat_.birthtime().tv_nsec) / std.time.ns_per_ms) else 0)), + @as(T, @truncate(@as(i64, @intCast(if (stat_.birthtime().tv_nsec > 0) (@as(usize, @intCast(stat_.birthtime().tv_nsec)) / std.time.ns_per_ms) else 0)))), .birthtime = if (Environment.isLinux) - @enumFromInt(Date, 0) + @as(Date, @enumFromInt(0)) else - @enumFromInt(Date, @intCast(u64, @max(stat_.birthtime().tv_sec, 0))), + @as(Date, @enumFromInt(@as(u64, @intCast(@max(stat_.birthtime().tv_sec, 0))))), }; } }; @@ -1375,33 +1375,33 @@ pub const Stats = union(enum) { fn modeInternal(this: *This) i32 { return switch (this.*) { - .big => @truncate(i32, this.big.mode), + .big => @as(i32, @truncate(this.big.mode)), .small => this.small.mode, }; } pub fn isBlockDevice(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISBLK(@intCast(Mode, this.modeInternal()))); + return JSC.JSValue.jsBoolean(os.S.ISBLK(@as(Mode, @intCast(this.modeInternal())))); } pub fn isCharacterDevice(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISCHR(@intCast(Mode, this.modeInternal()))); + return JSC.JSValue.jsBoolean(os.S.ISCHR(@as(Mode, @intCast(this.modeInternal())))); } pub fn isDirectory(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISDIR(@intCast(Mode, this.modeInternal()))); + return JSC.JSValue.jsBoolean(os.S.ISDIR(@as(Mode, @intCast(this.modeInternal())))); } pub fn isFIFO(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISFIFO(@intCast(Mode, this.modeInternal()))); + return JSC.JSValue.jsBoolean(os.S.ISFIFO(@as(Mode, @intCast(this.modeInternal())))); } pub fn isFile(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISREG(@intCast(Mode, this.modeInternal()))); + return JSC.JSValue.jsBoolean(os.S.ISREG(@as(Mode, @intCast(this.modeInternal())))); } pub fn isSocket(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISSOCK(@intCast(Mode, this.modeInternal()))); + return JSC.JSValue.jsBoolean(os.S.ISSOCK(@as(Mode, @intCast(this.modeInternal())))); } // Node.js says this method is only valid on the result of lstat() @@ -1410,7 +1410,7 @@ pub const Stats = union(enum) { // // See https://nodejs.org/api/fs.html#statsissymboliclink pub fn isSymbolicLink(this: *This) JSC.JSValue { - return JSC.JSValue.jsBoolean(os.S.ISLNK(@intCast(Mode, this.modeInternal()))); + return JSC.JSValue.jsBoolean(os.S.ISLNK(@as(Mode, @intCast(this.modeInternal())))); } pub fn finalize(this: *This) callconv(.C) void { @@ -2204,7 +2204,7 @@ pub const Process = struct { // However, this might be called many times in a row, so we use a pre-allocated buffer // that way we don't have to worry about garbage collector JSC.VirtualMachine.get().bundler.fs.top_level_dir = std.os.getcwd(&JSC.VirtualMachine.get().bundler.fs.top_level_dir_buf) catch { - _ = Syscall.chdir(@ptrCast([:0]const u8, JSC.VirtualMachine.get().bundler.fs.top_level_dir)); + _ = Syscall.chdir(@as([:0]const u8, @ptrCast(JSC.VirtualMachine.get().bundler.fs.top_level_dir))); return JSC.toInvalidArguments("Invalid path", .{}, globalObject.ref()); }; @@ -2220,13 +2220,13 @@ pub const Process = struct { pub fn exit(globalObject: *JSC.JSGlobalObject, code: i32) callconv(.C) void { var vm = globalObject.bunVM(); if (vm.worker) |worker| { - vm.exit_handler.exit_code = @truncate(u8, @max(code, 0)); + vm.exit_handler.exit_code = @as(u8, @truncate(@max(code, 0))); worker.terminate(); return; } vm.onExit(); - std.os.exit(@truncate(u8, @intCast(u32, @max(code, 0)))); + std.os.exit(@as(u8, @truncate(@as(u32, @intCast(@max(code, 0)))))); } pub export const Bun__version: [*:0]const u8 = "v" ++ bun.Global.package_json_version; |