Repository navigation
Conversation
|
Updated 3:35 PM PT - Oct 14th, 2025
❌ @nektro, your commit 8b9b4fb has some failures in 🧪 To try this PR locally: bunx bun-pr 23480That installs a local version of the PR into your bun-23480 --bun |
WalkthroughIntroduces a const buffer type for libuv (uv_buf_t_const), updates extern signatures (uv_write, uv_fs_write), and adjusts callers across Windows IPC, pipe writers, Node fs, and web blob writing. Refactors PlatformIOVec creation and writev signatures to const variants, and updates buffer initializations to .init(...) patterns. Changes
Possibly related PRs
Suggested reviewers
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
src/bun.js/webcore/blob/write_file.zig (1)
593-597: Remove @constcast and use uv_buf init helper for clarityNow that uv_buf is const, @constcast is unnecessary. Prefer the init helper for consistency with other call sites.
- this.uv_bufs[0].base = @constCast(remain.ptr); - this.uv_bufs[0].len = @truncate(remain.len); + this.uv_bufs[0] = uv.uv_buf_t_const.init(remain);As per coding guidelines
src/sys_uv.zig (1)
321-324: Fix compile-time assert to match const write typepwritev works with PlatformIOVecConst; the assert still checks the mutable type. Update to reflect the const variant.
Apply this diff:
- comptime bun.assert(bun.PlatformIOVec == uv.uv_buf_t); + comptime bun.assert(bun.PlatformIOVecConst == uv.uv_buf_t_const);src/deps/libuv.zig (2)
740-752: Fix const slice return type (compile-time/type-safety issue)uv_buf_t_const.slice returns []u8 but base is [*]const u8. This discards constness and likely won’t compile. Return []const u8.
Apply this diff:
pub const uv_buf_t_const = extern struct { len: ULONG, base: [*]const u8, pub fn init(input: []const u8) uv_buf_t_const { bun.assert(input.len <= @as(usize, std.math.maxInt(ULONG))); return .{ .len = @truncate(input.len), .base = input.ptr }; } - pub fn slice(this: *const @This()) []u8 { + pub fn slice(this: *const @This()) []const u8 { return this.base[0..this.len]; } };
1277-1295: Unify uv_write buffer passing; drop unnecessary castsThe callback branch correctly uses input[0..1]. The no-callback branch still uses @ptrCast. Prefer input[0..1] for both.
Apply this diff:
- const rc = uv_write(req, stream, @ptrCast(input), 1, null); + const rc = uv_write(req, stream, input[0..1], 1, null);Optional follow-up (outside these lines): consider updating StreamMixin.write to accept *uv_buf_t_const and use input[0..1] to avoid @ptrCast, keeping types consistent with the new extern.
Also applies to: 1297-1302
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (7)
src/bun.js/ipc.zig(2 hunks)src/bun.js/node/node_fs.zig(2 hunks)src/bun.js/webcore/blob/write_file.zig(1 hunks)src/bun.zig(1 hunks)src/deps/libuv.zig(5 hunks)src/io/PipeWriter.zig(6 hunks)src/sys_uv.zig(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)
**/*.zig: Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Wrap the Bun____toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue
Files:
src/bun.js/ipc.zigsrc/bun.js/webcore/blob/write_file.zigsrc/io/PipeWriter.zigsrc/sys_uv.zigsrc/bun.js/node/node_fs.zigsrc/deps/libuv.zigsrc/bun.zig
src/bun.js/**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/zig-javascriptcore-classes.mdc)
src/bun.js/**/*.zig: In Zig binding structs, expose generated bindings via pub const js = JSC.Codegen.JS and re-export toJS/fromJS/fromJSDirect
Constructors and prototype methods should return bun.JSError!JSC.JSValue to integrate Zig error handling with JS exceptions
Use parameter name globalObject (not ctx) and accept (*JSC.JSGlobalObject, *JSC.CallFrame) in binding methods/constructors
Implement getters as get(this, globalObject) returning JSC.JSValue and matching the .classes.ts interface
Provide deinit() for resource cleanup and finalize() that calls deinit(); use bun.destroy(this) or appropriate destroy pattern
Access JS call data via CallFrame (argument(i), argumentCount(), thisValue()) and throw errors with globalObject.throw(...)
For properties marked cache: true, use the generated Zig accessors (NameSetCached/GetCached) to work with GC-owned values
In finalize() for objects holding JS references, release them using .deref() before destroy
Files:
src/bun.js/ipc.zigsrc/bun.js/webcore/blob/write_file.zigsrc/bun.js/node/node_fs.zig
src/**/*.zig
📄 CodeRabbit inference engine (CLAUDE.md)
In Zig code, manage memory carefully and use defer for cleanup of allocations/resources
src/**/*.zig: Use the # prefix to declare private fields in Zig structs (e.g., struct { #foo: u32 })
Prefer decl literals when initializing values in Zig (e.g., const decl: Decl = .{ .binding = 0, .value = 0 })
Place @import directives at the bottom of Zig files
Use @import("bun") instead of @import("root").bunWhen adding debug logs in Zig, create a scoped logger and log via Bun APIs:
const log = bun.Output.scoped(.${SCOPE}, .hidden);thenlog("...", .{})
Files:
src/bun.js/ipc.zigsrc/bun.js/webcore/blob/write_file.zigsrc/io/PipeWriter.zigsrc/sys_uv.zigsrc/bun.js/node/node_fs.zigsrc/deps/libuv.zigsrc/bun.zig
🔇 Additional comments (15)
src/bun.js/webcore/blob/write_file.zig (1)
347-347: Windows const-buffer type change LGTMSwitch to [1]uv.uv_buf_t_const matches the new const write path. No further issues here.
src/bun.js/node/node_fs.zig (1)
211-211: Single-buffer write init usage is goodUsing inferred
.init(buf)aligns with the const uv buffer refactor and keeps the call concise.src/bun.zig (1)
257-260: Const IOV adoption looks correct
- PlatformIOVecConst → uv_buf_t_const on Windows is right.
- platformIOVecCreate/ConstCreate use direct ptr with truncated len; no constCast; aligns with libuv const semantics.
Also applies to: 261-263, 265-267
src/bun.js/ipc.zig (2)
399-407: Switch to uv_buf_t_const is appropriatewrite_buffer now uses the const variant with an empty init; matches the updated libuv API.
812-821: Buffer init via .init(write_req_slice) is correctUsing uv_buf_t_const.init(...) with a dup’d slice ensures stable memory until completion.
src/sys_uv.zig (4)
365-366: Use of .init for single-buffer read is fineCorrectly initializes a one-element uv buffer; consistent with the new pattern.
374-376: pwrite single-buffer init is correctOne-element const IOV via .init(buf) matches the new API.
378-381: write single-buffer init is correctUses const IOV and delegates to writev; consistent with pwrite/writev changes.
369-371: writev callers updated to use const IOVs Verified the inlinewritewrapper passes a[]const bun.PlatformIOVecConstvia&bufs.src/io/PipeWriter.zig (3)
943-944: Use uv_buf_t_const for write_bufferType swap and .init("") default are correct and consistent with upstream libuv changes.
1061-1072: Initialize const buffers with .init(buffer)Both fs and pipe paths use uv_buf_t_const.init(...); matches the const write semantics.
1406-1418: Streaming writer: const buffer init is correctcurrent_payload/outgoing ensure stable memory; initializing uv_buf_t_const with .init(bytes) is safe here.
src/deps/libuv.zig (3)
731-739: uv_buf_t helpers look correctLength truncation and slice exposure for mutable buffers are correct. No issues.
1273-1276: write_buffer constness change is correctSwitching write_buffer to uv_buf_t_const aligns with const write paths.
2238-2238: Extern uv_write now takes const buffers — goodSignature matches the new const semantics and is ABI-compatible with libuv’s uv_buf_t.
Please also update remaining call sites to pass slices (bufs[0..1]) where applicable for consistency.
| pub const uv_buf_t_const = extern struct { | ||
| len: ULONG, | ||
| base: [*]const u8, |
There was a problem hiding this comment.
According to the C standard, this type isn't guaranteed to have the same representation as uv_buf_t. So by declaring uv_write as taking [*]const uv_buf_t_const, we are declaring it with an incompatible signature that doesn't match how it is defined in C.
Maybe it happens to work in practice; I think it's better not to risk it.
|
Closing as stale: this PR predates the Rust rewrite. Every If the underlying change is still wanted, it will need to be redone against the current Rust/C++ tree. Apologies for the churn, and thank you for the contribution. |
addresses a TODO