diff --git a/.github/workflows/zig-fmt.yml b/.github/workflows/zig-fmt.yml index 1f1c95e364109e..d6f54cf40da744 100644 --- a/.github/workflows/zig-fmt.yml +++ b/.github/workflows/zig-fmt.yml @@ -1,7 +1,7 @@ name: zig-fmt env: - ZIG_VERSION: 0.11.0-dev.4006+bf827d0b5 + ZIG_VERSION: 0.12.0-dev.161+6a5463951 on: pull_request: diff --git a/.gitignore b/.gitignore index 5d4da2f8871604..abdc39118cba8d 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,5 @@ src/js/out/tmp src/js/out/DebugPath.h make-dev-stats.csv + +.uuid \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7599ea818006c9..e90225aad7b821 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ARG TRIPLET=${ARCH}-linux-gnu ARG BUILDARCH=amd64 ARG WEBKIT_TAG=2023-aug3-5 ARG ZIG_TAG=jul1 -ARG ZIG_VERSION="0.11.0-dev.4006+bf827d0b5" +ARG ZIG_VERSION="0.12.0-dev.161+6a5463951" ARG WEBKIT_BASENAME="bun-webkit-linux-$BUILDARCH" ARG ZIG_FOLDERNAME=zig-linux-${BUILD_MACHINE_ARCH}-${ZIG_VERSION} diff --git a/build.zig b/build.zig index efb308971020d9..58397d90b60b49 100644 --- a/build.zig +++ b/build.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const pathRel = std.fs.path.relative; const Wyhash = @import("./src/wyhash.zig").Wyhash; var is_debug_build = false; fn moduleSource(comptime out: []const u8) FileSource { @@ -96,6 +97,7 @@ const BunBuildOptions = struct { } }; +// relative to the prefix var output_dir: []const u8 = ""; fn panicIfNotFound(comptime filepath: []const u8) []const u8 { var file = std.fs.cwd().openFile(filepath, .{ .optimize = .read_only }) catch |err| { @@ -172,13 +174,12 @@ pub fn build(b: *Build) !void { var triplet = triplet_buf[0 .. osname.len + cpuArchName.len + 1]; if (b.option([]const u8, "output-dir", "target to install to") orelse std.os.getenv("OUTPUT_DIR")) |output_dir_| { - output_dir = b.pathFromRoot(output_dir_); + output_dir = try pathRel(b.allocator, b.install_prefix, output_dir_); } else { const output_dir_base = try std.fmt.bufPrint(&output_dir_buf, "{s}{s}", .{ bin_label, triplet }); - output_dir = b.pathFromRoot(output_dir_base); + output_dir = try pathRel(b.allocator, b.install_prefix, output_dir_base); } - std.fs.cwd().makePath(output_dir) catch {}; is_debug_build = optimize == OptimizeMode.Debug; const bun_executable_name = if (optimize == std.builtin.OptimizeMode.Debug) "bun-debug" else "bun"; const root_src = if (target.getOsTag() == std.Target.Os.Tag.freestanding) @@ -186,12 +187,12 @@ pub fn build(b: *Build) !void { else "root.zig"; - const min_version: std.SemanticVersion = if (target.getOsTag() != .freestanding and !target.isWindows()) + const min_version: std.SemanticVersion = if (target.getOsTag() != .freestanding) target.getOsVersionMin().semver else .{ .major = 0, .minor = 0, .patch = 0 }; - const max_version: std.SemanticVersion = if (target.getOsTag() != .freestanding and !target.isWindows()) + const max_version: std.SemanticVersion = if (target.getOsTag() != .freestanding) target.getOsVersionMax().semver else .{ .major = 0, .minor = 0, .patch = 0 }; @@ -202,6 +203,7 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative(root_src), .target = target, .optimize = optimize, + .main_pkg_path = .{ .cwd_relative = b.pathFromRoot(".") }, }); var default_build_options: BunBuildOptions = brk: { @@ -239,8 +241,6 @@ pub fn build(b: *Build) !void { }; { - obj.setMainPkgPath(b.pathFromRoot(".")); - try addInternalPackages( b, obj, @@ -271,9 +271,15 @@ pub fn build(b: *Build) !void { std.io.getStdErr().writer().print("Output: {s}/{s}\n\n", .{ output_dir, bun_executable_name }) catch unreachable; defer obj_step.dependOn(&obj.step); - obj.emit_bin = .{ - .emit_to = b.fmt("{s}/{s}.o", .{ output_dir, bun_executable_name }), - }; + + var install = b.addInstallFileWithDir( + obj.getEmittedBin(), + .{ .custom = output_dir }, + b.fmt("{s}.o", .{bun_executable_name}), + ); + install.step.dependOn(&obj.step); + obj_step.dependOn(&install.step); + var actual_build_options = default_build_options; if (b.option(bool, "generate-sizes", "Generate sizes of things") orelse false) { actual_build_options.sizegen = true; @@ -290,7 +296,8 @@ pub fn build(b: *Build) !void { if (target.getCpuArch().isX86()) obj.disable_stack_probing = true; if (b.option(bool, "for-editor", "Do not emit bin, just check for errors") orelse false) { - obj.emit_bin = .no_emit; + // obj.emit_bin = .no_emit; + obj.generated_bin = null; } if (target.getOsTag() == .linux) { @@ -308,9 +315,10 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative("src/bindgen.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); defer headers_step.dependOn(&headers_obj.step); - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); var headers_build_options = default_build_options; headers_build_options.bindgen = true; headers_obj.addOptions("build_options", default_build_options.step(b)); @@ -318,21 +326,22 @@ pub fn build(b: *Build) !void { } { - const wasm = b.step("bun-wasm", "Build WASM"); - var wasm_step = b.addStaticLibrary(.{ + const wasm_step = b.step("bun-wasm", "Build WASM"); + var wasm = b.addStaticLibrary(.{ .name = "bun-wasm", .root_source_file = FileSource.relative("root_wasm.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); - defer wasm.dependOn(&wasm_step.step); - wasm_step.strip = false; + defer wasm_step.dependOn(&wasm.step); + wasm.strip = false; // wasm_step.link_function_sections = true; // wasm_step.link_emit_relocs = true; // wasm_step.single_threaded = true; - try configureObjectStep(b, wasm_step, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, wasm, wasm_step, @TypeOf(target), target); var build_opts = default_build_options; - wasm_step.addOptions("build_options", build_opts.step(b)); + wasm.addOptions("build_options", build_opts.step(b)); } { @@ -342,9 +351,10 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative("misctools/http_bench.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); defer headers_step.dependOn(&headers_obj.step); - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); headers_obj.addOptions("build_options", default_build_options.step(b)); } @@ -355,9 +365,10 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative("misctools/machbench.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); defer headers_step.dependOn(&headers_obj.step); - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); headers_obj.addOptions("build_options", default_build_options.step(b)); } @@ -368,9 +379,10 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative("misctools/fetch.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); defer headers_step.dependOn(&headers_obj.step); - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); headers_obj.addOptions("build_options", default_build_options.step(b)); } @@ -381,9 +393,10 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative("src/bench/string-handling.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); defer headers_step.dependOn(&headers_obj.step); - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); headers_obj.addOptions("build_options", default_build_options.step(b)); } @@ -394,9 +407,10 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative("src/sha.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); defer headers_step.dependOn(&headers_obj.step); - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); headers_obj.addOptions("build_options", default_build_options.step(b)); } @@ -407,9 +421,10 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative("src/sourcemap/vlq_bench.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); defer headers_step.dependOn(&headers_obj.step); - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); headers_obj.addOptions("build_options", default_build_options.step(b)); } @@ -420,9 +435,10 @@ pub fn build(b: *Build) !void { .root_source_file = FileSource.relative("misctools/tgz.zig"), .target = target, .optimize = optimize, + .main_pkg_path = obj.main_pkg_path, }); defer headers_step.dependOn(&headers_obj.step); - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); headers_obj.addOptions("build_options", default_build_options.step(b)); } @@ -436,16 +452,23 @@ pub fn build(b: *Build) !void { var headers_obj: *CompileStep = b.addTest(.{ .root_source_file = FileSource.relative(test_file orelse "src/main.zig"), .target = target, + .main_pkg_path = obj.main_pkg_path, }); headers_obj.filter = test_filter; if (test_bin_) |test_bin| { headers_obj.name = std.fs.path.basename(test_bin); - if (std.fs.path.dirname(test_bin)) |dir| headers_obj.emit_bin = .{ - .emit_to = b.fmt("{s}/{s}", .{ dir, headers_obj.name }), - }; + if (std.fs.path.dirname(test_bin)) |dir| { + var install = b.addInstallFileWithDir( + headers_obj.getEmittedBin(), + .{ .custom = try std.fs.path.relative(b.allocator, output_dir, dir) }, + headers_obj.name, + ); + install.step.dependOn(&headers_obj.step); + headers_step.dependOn(&install.step); + } } - try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?); + try configureObjectStep(b, headers_obj, headers_step, @TypeOf(target), target); headers_step.dependOn(&headers_obj.step); headers_obj.addOptions("build_options", default_build_options.step(b)); @@ -456,9 +479,7 @@ pub fn build(b: *Build) !void { pub var original_make_fn: ?*const fn (step: *std.build.Step) anyerror!void = null; -pub fn configureObjectStep(b: *std.build.Builder, obj: *CompileStep, comptime Target: type, target: Target, main_pkg_path: []const u8) !void { - obj.setMainPkgPath(main_pkg_path); - +pub fn configureObjectStep(b: *std.build.Builder, obj: *CompileStep, obj_step: *std.build.Step, comptime Target: type, target: Target) !void { // obj.setTarget(target); try addInternalPackages(b, obj, std.heap.page_allocator, b.zig_exe, target); @@ -466,11 +487,16 @@ pub fn configureObjectStep(b: *std.build.Builder, obj: *CompileStep, comptime Ta // obj.setBuildMode(optimize); obj.bundle_compiler_rt = false; - if (obj.emit_bin == .default) - obj.emit_bin = .{ - .emit_to = b.fmt("{s}/{s}.o", .{ output_dir, obj.name }), - }; + if (obj.emit_directory == null) { + var install = b.addInstallFileWithDir( + obj.getEmittedBin(), + .{ .custom = output_dir }, + b.fmt("{s}.o", .{obj.name}), + ); + install.step.dependOn(&obj.step); + obj_step.dependOn(&install.step); + } if (target.getOsTag() != .freestanding) obj.linkLibC(); if (target.getOsTag() != .freestanding) obj.bundle_compiler_rt = false; diff --git a/docs/project/development.md b/docs/project/development.md index c635595b348bca..ad3f0df0cfb55b 100644 --- a/docs/project/development.md +++ b/docs/project/development.md @@ -112,7 +112,7 @@ Zig can be installed either with our npm package [`@oven/zig`](https://www.npmjs ```bash $ bun install -g @oven/zig -$ zigup 0.11.0-dev.4006+bf827d0b5 +$ zigup 0.12.0-dev.161+6a5463951 ``` {% callout %} diff --git a/src/analytics/analytics_schema.zig b/src/analytics/analytics_schema.zig index fbcc26fb0a112b..3a22ed2b32a7ef 100644 --- a/src/analytics/analytics_schema.zig +++ b/src/analytics/analytics_schema.zig @@ -346,8 +346,8 @@ pub const analytics = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -361,8 +361,8 @@ pub const analytics = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -411,8 +411,8 @@ pub const analytics = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; diff --git a/src/api/schema.zig b/src/api/schema.zig index ae63af87a3a8de..f3141a1b5551f6 100644 --- a/src/api/schema.zig +++ b/src/api/schema.zig @@ -373,8 +373,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -391,8 +391,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -418,8 +418,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -648,8 +648,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -799,8 +799,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -820,8 +820,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -838,8 +838,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -856,8 +856,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -1124,8 +1124,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -1139,8 +1139,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -1246,8 +1246,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -1953,8 +1953,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -2185,8 +2185,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -2200,8 +2200,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -2271,8 +2271,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -2478,8 +2478,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -2511,8 +2511,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -2529,8 +2529,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -3147,8 +3147,8 @@ pub const Api = struct { _, - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; diff --git a/src/ast/base.zig b/src/ast/base.zig index ab96dab3d8ca25..fb70e4565f16e6 100644 --- a/src/ast/base.zig +++ b/src/ast/base.zig @@ -285,8 +285,8 @@ pub const Ref = packed struct(u64) { return self.tag == .invalid; } - pub fn jsonStringify(self: *const Ref, options: anytype, writer: anytype) !void { - return try std.json.stringify([2]u32{ self.sourceIndex(), self.innerIndex() }, options, writer); + pub fn jsonStringify(self: *const Ref, writer: anytype) !void { + return try writer.write([2]u32{ self.sourceIndex(), self.innerIndex() }); } }; diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index af1a55ce6fdb71..f5c3793ed40052 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -594,8 +594,8 @@ pub const JSBundler = struct { external: bool = false, pub fn deinit(this: *@This()) void { - bun.default_allocator.destroy(this.path); - bun.default_allocator.destroy(this.namespace); + bun.default_allocator.free(this.path); + bun.default_allocator.free(this.namespace); } }, no_match: void, @@ -747,7 +747,7 @@ pub const JSBundler = struct { pub fn deinit(this: *Value) void { switch (this.*) { .success => |success| { - bun.default_allocator.destroy(success.source_code); + bun.default_allocator.free(success.source_code); }, .err => |*err| { err.deinit(bun.default_allocator); diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 5da6c1f40cc8a3..592fd6540bbd5e 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -499,10 +499,10 @@ pub const Listener = struct { pub fn deinit(this: UnixOrHost) void { switch (this) { .unix => |u| { - bun.default_allocator.destroy(@as([*]u8, @ptrFromInt(@intFromPtr(u.ptr)))); + bun.default_allocator.free(u); }, .host => |h| { - bun.default_allocator.destroy(@as([*]u8, @ptrFromInt(@intFromPtr(h.host.ptr)))); + bun.default_allocator.free(h.host); }, } } @@ -833,7 +833,7 @@ pub const Listener = struct { this.connection.deinit(); if (this.protos) |protos| { this.protos = null; - bun.default_allocator.destroy(protos); + bun.default_allocator.free(protos); } bun.default_allocator.destroy(this); } diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index e96135a5e1d544..64a85d6a451fd5 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -5131,7 +5131,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp this.cached_protocol.deref(); if (this.config.hostname) |host| { - bun.default_allocator.destroy(host); + bun.default_allocator.free(host[0 .. std.mem.len(host) + 1]); } if (this.config.base_url.href.len > 0) { diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 062bd52a228797..03cdab205ce4ab 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -2558,7 +2558,7 @@ pub const VirtualMachine = struct { } else if (kind.isObject() or kind.isArray()) { var bun_str = bun.String.empty; defer bun_str.deref(); - value.jsonStringify(this.global, 2, &bun_str); + value.jsonStringify(this.global, 2, &bun_str); //2 try writer.print(comptime Output.prettyFmt(" {s}: {any}\n", allow_ansi_color), .{ field, bun_str }); add_extra_line = true; } diff --git a/src/bun.js/node/fs_events.zig b/src/bun.js/node/fs_events.zig index 70b41fc335529d..ce158a037ac592 100644 --- a/src/bun.js/node/fs_events.zig +++ b/src/bun.js/node/fs_events.zig @@ -488,7 +488,7 @@ pub const FSEventsLoop = struct { CS.FSEventStreamScheduleWithRunLoop(ref, this.loop, CF.RunLoopDefaultMode.*); if (CS.FSEventStreamStart(ref) == 0) { //clean in case of failure - bun.default_allocator.destroy(paths); + bun.default_allocator.free(paths); CF.Release(cf_paths); CS.FSEventStreamInvalidate(ref); CS.FSEventStreamRelease(ref); diff --git a/src/bun.js/node/path_watcher.zig b/src/bun.js/node/path_watcher.zig index 1d81661e9bd87f..1f1b9d1a12fd39 100644 --- a/src/bun.js/node/path_watcher.zig +++ b/src/bun.js/node/path_watcher.zig @@ -85,7 +85,7 @@ pub const PathWatcherManager = struct { return info.*; } const cloned_path = try bun.default_allocator.dupeZ(u8, path); - errdefer bun.default_allocator.destroy(cloned_path); + errdefer bun.default_allocator.free(cloned_path); if (std.fs.openIterableDirAbsoluteZ(cloned_path, .{ .access_sub_paths = true, @@ -657,7 +657,7 @@ pub const PathWatcherManager = struct { while (it.next()) |*entry| { const path = entry.value_ptr.*; std.os.close(path.fd); - bun.default_allocator.destroy(path.path); + bun.default_allocator.free(path.path); } this.file_paths.deinit(); diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index de3f185d5c500f..0d3ff663e88e9e 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -1131,12 +1131,12 @@ pub const Expect = struct { if (value.isAnyInt()) { const _value = value.toInt64(); pass = @mod(_value, 2) == 0; - if (_value == -0) { // negative zero is even + if (_value == -0.0) { // negative zero is even pass = true; } } else if (value.isBigInt() or value.isBigInt32()) { const _value = value.toInt64(); - pass = switch (_value == -0) { // negative zero is even + pass = switch (_value == -0.0) { // negative zero is even true => true, else => _value & 1 == 0, }; diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index c794ab59b11586..c5e893a5aee85e 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -2361,7 +2361,7 @@ pub const Blob = struct { } pub fn doFCopyFile(this: *CopyFile) anyerror!void { - switch (JSC.Node.Syscall.fcopyfile(this.source_fd, this.destination_fd, os.system.COPYFILE.DATA)) { + switch (JSC.Node.Syscall.fcopyfile(this.source_fd, this.destination_fd, os.system.COPYFILE_DATA)) { .err => |errno| { this.system_error = errno.toSystemError(); diff --git a/src/bundler.zig b/src/bundler.zig index 4e8d92e3cb2f17..734555ef56103d 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -653,9 +653,7 @@ pub const Bundler = struct { pub noinline fn dumpEnvironmentVariables(bundler: *const Bundler) void { @setCold(true); const opts = std.json.StringifyOptions{ - .whitespace = std.json.StringifyOptions.Whitespace{ - .separator = true, - }, + .whitespace = .indent_2, }; Output.flush(); std.json.stringify(bundler.env.map.*, opts, Output.writer()) catch unreachable; diff --git a/src/copy_file.zig b/src/copy_file.zig index 4fbac7855ce038..cbf81e54993989 100644 --- a/src/copy_file.zig +++ b/src/copy_file.zig @@ -24,7 +24,7 @@ const CopyFileError = error{SystemResources} || CopyFileRangeError || os.SendFil // No metadata is transferred over. pub fn copyFile(fd_in: os.fd_t, fd_out: os.fd_t) CopyFileError!void { if (comptime bun.Environment.isMac) { - const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE.DATA); + const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA); switch (os.errno(rc)) { .SUCCESS => return, .INVAL => unreachable, diff --git a/src/css_scanner.zig b/src/css_scanner.zig index e464a6d9fb360f..db5e6ee0d8dbcf 100644 --- a/src/css_scanner.zig +++ b/src/css_scanner.zig @@ -346,7 +346,7 @@ pub const Scanner = struct { comptime WriterType: type, writer: WriterType, writeChunk: (fn (ctx: WriterType, Chunk) anyerror!void), - ) !void { + ) anyerror!void { scanner.has_newline_before = scanner.end == 0; scanner.has_delimiter_before = false; scanner.step(); @@ -899,7 +899,7 @@ pub fn NewWriter( writer: *Writer, log: *logger.Log, allocator: std.mem.Allocator, - ) !void { + ) anyerror!void { std.debug.assert(writer.source.contents.len > 0); var scanner = Scanner.init( @@ -937,7 +937,7 @@ pub fn NewWriter( writer: *Writer, log: *logger.Log, allocator: std.mem.Allocator, - ) !void { + ) anyerror!void { std.debug.assert(writer.source.contents.len > 0); var scanner = Scanner.init( @@ -950,7 +950,7 @@ pub fn NewWriter( try scanner.next(.keep, @TypeOf(writer), writer, commitChunk); } - fn writeString(writer: *Writer, str: string, quote: Chunk.TextContent.Quote) !void { + fn writeString(writer: *Writer, str: string, quote: Chunk.TextContent.Quote) anyerror!void { switch (quote) { .none => { try writer.ctx.writeAll(str); @@ -974,7 +974,7 @@ pub fn NewWriter( } } - fn writeURL(writer: *Writer, url_str: string, text: Chunk.TextContent) !void { + fn writeURL(writer: *Writer, url_str: string, text: Chunk.TextContent) anyerror!void { switch (text.quote) { .none => { try writer.ctx.writeAll("url("); @@ -1001,7 +1001,7 @@ pub fn NewWriter( } } - pub fn scanChunk(writer: *Writer, chunk: Chunk) !void { + pub fn scanChunk(writer: *Writer, chunk: Chunk) anyerror!void { switch (chunk.content) { .t_url => {}, .t_import => |import| { @@ -1042,15 +1042,15 @@ pub fn NewWriter( } } - pub fn commitChunk(writer: *Writer, chunk: Chunk) !void { + pub fn commitChunk(writer: *Writer, chunk: Chunk) anyerror!void { return try writeChunk(writer, chunk, false); } - pub fn writeBundledChunk(writer: *Writer, chunk: Chunk) !void { + pub fn writeBundledChunk(writer: *Writer, chunk: Chunk) anyerror!void { return try writeChunk(writer, chunk, true); } - pub fn writeChunk(writer: *Writer, chunk: Chunk, comptime omit_imports: bool) !void { + pub fn writeChunk(writer: *Writer, chunk: Chunk, comptime omit_imports: bool) anyerror!void { switch (chunk.content) { .t_url => |url| { const url_str = try writer.linker.resolveCSS( @@ -1259,7 +1259,7 @@ pub fn NewBundler( return logger.Source.initFile(file, this.allocator); } - pub fn addCSSImport(this: *CSSBundler, absolute_path: string) !void { + pub fn addCSSImport(this: *CSSBundler, absolute_path: string) anyerror!void { const hash = Watcher.getHash(absolute_path); if (this.queued.items.len > 0 and std.mem.indexOfScalar(u32, this.queued.items, hash) != null) { return; @@ -1281,7 +1281,7 @@ pub fn NewBundler( try this.bundle_queue.append(hash); } - pub fn writeAll(this: *CSSBundler, buf: anytype) !void { + pub fn writeAll(this: *CSSBundler, buf: anytype) anyerror!void { _ = try this.writer.writeAll(buf); } diff --git a/src/env_loader.zig b/src/env_loader.zig index 088ec2d0cb3c19..0da98579395929 100644 --- a/src/env_loader.zig +++ b/src/env_loader.zig @@ -869,25 +869,25 @@ pub const Map = struct { try this.map.put(key, value); } - pub fn jsonStringify(self: *const @This(), options: anytype, writer: anytype) !void { + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { var iterator = self.map.iterator(); - _ = try writer.writeAll("{"); + _ = try writer.write("{"); while (iterator.next()) |entry| { - _ = try writer.writeAll("\n "); + _ = try writer.write("\n "); - std.json.stringify(entry.key_ptr.*, options, writer) catch unreachable; + writer.write(entry.key_ptr.*) catch unreachable; - _ = try writer.writeAll(": "); + _ = try writer.write(": "); - std.json.stringify(entry.value_ptr.*, options, writer) catch unreachable; + writer.write(entry.value_ptr.*) catch unreachable; if (iterator.index <= self.map.count() - 1) { - _ = try writer.writeAll(", "); + _ = try writer.write(", "); } } - try writer.writeAll("\n}"); + try writer.write("\n}"); } pub inline fn get( diff --git a/src/fs.zig b/src/fs.zig index 51d3fb4b7fe608..3c35d068bf54df 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1578,8 +1578,8 @@ pub const Path = struct { this.is_symlink = true; } - pub fn jsonStringify(self: *const @This(), options: anytype, writer: anytype) !void { - return try std.json.stringify(self.text, options, writer); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(self.text); } pub fn generateKey(p: *Path, allocator: std.mem.Allocator) !string { diff --git a/src/import_record.zig b/src/import_record.zig index 8fd29e805fcc82..3044c9b47e2d9c 100644 --- a/src/import_record.zig +++ b/src/import_record.zig @@ -62,8 +62,8 @@ pub const ImportKind = enum(u8) { }; } - pub fn jsonStringify(self: @This(), options: anytype, writer: anytype) !void { - return try std.json.stringify(@tagName(self), options, writer); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } pub fn isFromCSS(k: ImportKind) bool { diff --git a/src/js_ast.zig b/src/js_ast.zig index aeccdd1f345977..673b93bf3b26b3 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -262,8 +262,8 @@ pub const ImportItemStatus = enum(u2) { // The printer will replace this import with "undefined" missing, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -271,8 +271,8 @@ pub const AssignTarget = enum(u2) { none = 0, replace = 1, // "a = b" update = 2, // "a += b" - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -348,8 +348,8 @@ pub const Binding = struct { loc: logger.Loc, }; - pub fn jsonStringify(self: *const @This(), options: anytype, writer: anytype) !void { - return try std.json.stringify(Serializable{ .type = std.meta.activeTag(self.data), .object = "binding", .value = self.data, .loc = self.loc }, options, writer); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(Serializable{ .type = std.meta.activeTag(self.data), .object = "binding", .value = self.data, .loc = self.loc }); } pub fn ToExpr(comptime expr_type: type, comptime func_type: anytype) type { @@ -437,8 +437,8 @@ pub const Binding = struct { b_object, b_missing, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -844,8 +844,8 @@ pub const G = struct { declare, class_static_block, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; }; @@ -1152,8 +1152,8 @@ pub const Symbol = struct { // This annotates all other symbols that don't have special behavior. other, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } pub inline fn isPrivate(kind: Symbol.Kind) bool { @@ -1371,8 +1371,8 @@ pub const OptionalChain = enum(u2) { // "(a?.b).c" => ".c" is OptionalChain null ccontinue, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -1683,8 +1683,8 @@ pub const E = struct { }; pub const Missing = struct { - pub fn jsonStringify(_: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(null, opts, o); + pub fn jsonStringify(_: *const @This(), writer: anytype) !void { + return try writer.write(null); } }; @@ -1754,8 +1754,8 @@ pub const E = struct { return @as(T, @intFromFloat(@min(@max(@trunc(self.value), 0), comptime @min(std.math.floatMax(f64), std.math.maxInt(T))))); } - pub fn jsonStringify(self: *const Number, opts: anytype, o: anytype) !void { - return try std.json.stringify(self.value, opts, o); + pub fn jsonStringify(self: *const Number, writer: anytype) !void { + return try writer.write(self.value); } pub fn toJS(this: @This()) JSC.JSValue { @@ -1768,8 +1768,8 @@ pub const E = struct { pub var empty = BigInt{ .value = "" }; - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(self.value, opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(self.value); } pub fn toJS(_: @This()) JSC.JSValue { @@ -2401,7 +2401,7 @@ pub const E = struct { } } - pub fn jsonStringify(s: *const String, options: anytype, writer: anytype) !void { + pub fn jsonStringify(s: *const String, writer: anytype) !void { var buf = [_]u8{0} ** 4096; var i: usize = 0; for (s.slice16()) |char| { @@ -2412,7 +2412,7 @@ pub const E = struct { } } - return try std.json.stringify(buf[0..i], options, writer); + return try writer.write(buf[0..i]); } }; @@ -2580,8 +2580,8 @@ pub const E = struct { return ""; } - pub fn jsonStringify(self: *const RegExp, opts: anytype, o: anytype) !void { - return try std.json.stringify(self.value, opts, o); + pub fn jsonStringify(self: *const RegExp, writer: anytype) !void { + return try writer.write(self.value); } }; @@ -2658,8 +2658,8 @@ pub const Stmt = struct { loc: logger.Loc, }; - pub fn jsonStringify(self: *const Stmt, options: anytype, writer: anytype) !void { - return try std.json.stringify(Serializable{ .type = std.meta.activeTag(self.data), .object = "stmt", .value = self.data, .loc = self.loc }, options, writer); + pub fn jsonStringify(self: *const Stmt, writer: anytype) !void { + return try writer.write(Serializable{ .type = std.meta.activeTag(self.data), .object = "stmt", .value = self.data, .loc = self.loc }); } pub fn isTypeScript(self: *Stmt) bool { @@ -2876,8 +2876,8 @@ pub const Stmt = struct { s_while, s_with, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } pub fn isExportLike(tag: Tag) bool { @@ -3367,8 +3367,8 @@ pub const Expr = struct { } } - pub fn jsonStringify(self: *const @This(), options: anytype, writer: anytype) !void { - return try std.json.stringify(Serializable{ .type = std.meta.activeTag(self.data), .object = "expr", .value = self.data, .loc = self.loc }, options, writer); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(Serializable{ .type = std.meta.activeTag(self.data), .object = "expr", .value = self.data, .loc = self.loc }); } pub fn extractNumericValues(left: Expr.Data, right: Expr.Data) ?[2]f64 { @@ -4258,8 +4258,8 @@ pub const Expr = struct { }; } - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } pub fn isArray(self: Tag) bool { @@ -5112,7 +5112,7 @@ pub const Expr = struct { pub fn toNumber(data: Expr.Data) ?f64 { return switch (data) { .e_null => 0, - .e_undefined => std.math.nan_f64, + .e_undefined => std.math.nan(f64), .e_boolean => @as(f64, if (data.e_boolean.value) 1.0 else 0.0), .e_number => data.e_number.value, else => null, @@ -5598,8 +5598,8 @@ pub const S = struct { k_var, k_let, k_const, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; }; @@ -5734,8 +5734,8 @@ pub const Op = struct { /// Right-associative bin_logical_and_assign, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } pub fn unaryAssignTarget(code: Op.Code) AssignTarget { @@ -5835,8 +5835,8 @@ pub const Op = struct { }; } - pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(self.text, opts, o); + pub fn jsonStringify(self: *const @This(), writer: anytype) !void { + return try writer.write(self.text); } pub const TableType: std.EnumArray(Op.Code, Op) = undefined; @@ -6266,8 +6266,8 @@ pub const ExportsKind = enum { return dynamic.contains(self); } - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } pub fn isESMWithDynamicFallback(self: ExportsKind) bool { @@ -6441,8 +6441,8 @@ pub const Part = struct { }; pub const SymbolUseMap = std.ArrayHashMapUnmanaged(Ref, Symbol.Use, RefHashCtx, false); - pub fn jsonStringify(self: *const Part, options: std.json.StringifyOptions, writer: anytype) !void { - return std.json.stringify(self.stmts, options, writer); + pub fn jsonStringify(self: *const Part, writer: anytype) !void { + return writer.write(self.stmts); } }; @@ -6488,8 +6488,8 @@ pub const StrictModeKind = enum(u4) { implicit_strict_mode_export, implicit_strict_mode_top_level_await, implicit_strict_mode_class, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; @@ -6676,8 +6676,8 @@ pub const Scope = struct { function_body, class_static_init, - pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void { - return try std.json.stringify(@tagName(self), opts, o); + pub fn jsonStringify(self: @This(), writer: anytype) !void { + return try writer.write(@tagName(self)); } }; diff --git a/src/js_parser.zig b/src/js_parser.zig index b116aa2e487232..68e45ace2027b9 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -2656,7 +2656,7 @@ pub const Parser = struct { } }; - pub fn scanImports(self: *Parser, scan_pass: *ScanPassResult) !void { + pub fn scanImports(self: *Parser, scan_pass: *ScanPassResult) anyerror!void { if (self.options.ts and self.options.jsx.parse) { return try self._scanImports(TSXImportScanner, scan_pass); } else if (self.options.ts) { @@ -2668,7 +2668,7 @@ pub const Parser = struct { } } - fn _scanImports(self: *Parser, comptime ParserType: type, scan_pass: *ScanPassResult) !void { + fn _scanImports(self: *Parser, comptime ParserType: type, scan_pass: *ScanPassResult) anyerror!void { var p: ParserType = undefined; try ParserType.init(self.allocator, self.log, self.source, self.define, self.lexer, self.options, &p); @@ -5169,7 +5169,7 @@ fn NewParser_( return p.callRuntime(require_args[0].loc, "__require", require_args); } - pub fn recordExport(p: *P, loc: logger.Loc, alias: string, ref: Ref) !void { + pub fn recordExport(p: *P, loc: logger.Loc, alias: string, ref: Ref) anyerror!void { if (p.named_exports.get(alias)) |name| { // Duplicate exports are an error var notes = try p.allocator.alloc(logger.Data, 1); @@ -5320,7 +5320,7 @@ fn NewParser_( additional_stmt: ?Stmt, comptime suffix: string, comptime is_internal: bool, - ) !void { + ) anyerror!void { const allocator = p.allocator; const import_record_i = p.addImportRecordByRange(.stmt, logger.Range.None, import_path); var import_record: *ImportRecord = &p.import_records.items[import_record_i]; @@ -5874,7 +5874,7 @@ fn NewParser_( return .{ .failure = expr }; } - pub fn prepareForVisitPass(p: *P) !void { + pub fn prepareForVisitPass(p: *P) anyerror!void { { var count: usize = 0; for (p.scopes_in_order.items) |item| { @@ -6306,7 +6306,7 @@ fn NewParser_( return head; } - fn pushScopeForVisitPass(p: *P, kind: js_ast.Scope.Kind, loc: logger.Loc) !void { + fn pushScopeForVisitPass(p: *P, kind: js_ast.Scope.Kind, loc: logger.Loc) anyerror!void { // Output.print("\n+Loc: {d}\n", .{loc.start}); // for (p.scopes_in_order.items[p.scopes_in_order_visitor_index..p.scopes_in_order.items.len]) |scope_order, i| { // if (scope_order) |ord| { @@ -6518,7 +6518,7 @@ fn NewParser_( return ExprBindingTuple{ .binding = bind, .expr = initializer }; } - fn forbidLexicalDecl(p: *P, loc: logger.Loc) !void { + fn forbidLexicalDecl(p: *P, loc: logger.Loc) anyerror!void { try p.log.addError(p.source, loc, "Cannot use a declaration in a single-statement context"); } @@ -9479,7 +9479,7 @@ fn NewParser_( ); } - fn skipTypeScriptInterfaceStmt(p: *P, opts: *ParseStatementOptions) !void { + fn skipTypeScriptInterfaceStmt(p: *P, opts: *ParseStatementOptions) anyerror!void { const name = p.lexer.identifier; try p.lexer.expect(.t_identifier); @@ -9750,7 +9750,7 @@ fn NewParser_( }; } - fn forbidInitializers(p: *P, decls: []G.Decl, comptime loop_type: string, is_var: bool) !void { + fn forbidInitializers(p: *P, decls: []G.Decl, comptime loop_type: string, is_var: bool) anyerror!void { switch (decls.len) { 0 => {}, 1 => { @@ -9810,7 +9810,7 @@ fn NewParser_( return ExprOrLetStmt{ .stmt_or_expr = js_ast.StmtOrExpr{ .expr = try p.parseSuffix(expr, .lowest, null, Expr.EFlags.none) } }; } - fn requireInitializers(p: *P, decls: []G.Decl) !void { + fn requireInitializers(p: *P, decls: []G.Decl) anyerror!void { for (decls) |decl| { if (decl.value == null) { switch (decl.binding.data) { @@ -10553,7 +10553,7 @@ fn NewParser_( return stmts.items; } - fn markStrictModeFeature(p: *P, feature: StrictModeFeature, r: logger.Range, detail: string) !void { + fn markStrictModeFeature(p: *P, feature: StrictModeFeature, r: logger.Range, detail: string) anyerror!void { const can_be_transformed = feature == StrictModeFeature.for_in_var_init; const text = switch (feature) { .with_statement => "With statements", @@ -10866,7 +10866,7 @@ fn NewParser_( return E.Arrow{ .args = args, .prefer_expr = true, .body = G.FnBody{ .loc = arrow_loc, .stmts = stmts } }; } - fn declareBinding(p: *P, kind: Symbol.Kind, binding: *BindingNodeIndex, opts: *ParseStatementOptions) !void { + fn declareBinding(p: *P, kind: Symbol.Kind, binding: *BindingNodeIndex, opts: *ParseStatementOptions) anyerror!void { switch (binding.data) { .b_missing => {}, .b_identifier => |bind| { @@ -13956,7 +13956,7 @@ fn NewParser_( }; } - fn appendPart(p: *P, parts: *ListManaged(js_ast.Part), stmts: []Stmt) !void { + fn appendPart(p: *P, parts: *ListManaged(js_ast.Part), stmts: []Stmt) anyerror!void { // Reuse the memory if possible // This is reusable if the last part turned out to be dead p.symbol_uses.clearRetainingCapacity(); @@ -14180,7 +14180,7 @@ fn NewParser_( } } - fn recordDeclaredSymbol(p: *P, ref: Ref) !void { + fn recordDeclaredSymbol(p: *P, ref: Ref) anyerror!void { std.debug.assert(ref.isSymbol()); try p.declared_symbols.append(p.allocator, DeclaredSymbol{ .ref = ref, @@ -17109,7 +17109,7 @@ fn NewParser_( // the value is ignored because that's what the TypeScript compiler does. } - fn visitAndAppendStmt(p: *P, stmts: *ListManaged(Stmt), stmt: *Stmt) !void { + fn visitAndAppendStmt(p: *P, stmts: *ListManaged(Stmt), stmt: *Stmt) anyerror!void { // By default any statement ends the const local prefix const was_after_after_const_local_prefix = p.current_scope.is_after_const_local_prefix; p.current_scope.is_after_const_local_prefix = true; @@ -18537,7 +18537,7 @@ fn NewParser_( } } - pub fn appendIfBodyPreservingScope(p: *P, stmts: *ListManaged(Stmt), body: Stmt) !void { + pub fn appendIfBodyPreservingScope(p: *P, stmts: *ListManaged(Stmt), body: Stmt) anyerror!void { switch (body.data) { .s_block => |block| { var keep_block = false; @@ -19551,7 +19551,7 @@ fn NewParser_( } // Try separating the list for appending, so that it's not a pointer. - fn visitStmts(p: *P, stmts: *ListManaged(Stmt), _: StmtsKind) !void { + fn visitStmts(p: *P, stmts: *ListManaged(Stmt), _: StmtsKind) anyerror!void { if (only_scan_imports_and_do_not_visit) { @compileError("only_scan_imports_and_do_not_visit must not run this."); } @@ -20049,7 +20049,7 @@ fn NewParser_( stmts.* = output; } - fn extractDeclsForBinding(binding: Binding, decls: *ListManaged(G.Decl)) !void { + fn extractDeclsForBinding(binding: Binding, decls: *ListManaged(G.Decl)) anyerror!void { switch (binding.data) { .b_property, .b_missing => {}, .b_identifier => { @@ -21239,7 +21239,7 @@ fn NewParser_( lexer: js_lexer.Lexer, opts: Parser.Options, this: *P, - ) !void { + ) anyerror!void { var scope_order = try ScopeOrderList.initCapacity(allocator, 1); var scope = try allocator.create(Scope); scope.* = Scope{ diff --git a/src/logger.zig b/src/logger.zig index 21a58243cc83d6..9ec2dc7ca7fa93 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -84,8 +84,8 @@ pub const Loc = struct { return loc.start == other.start; } - pub fn jsonStringify(self: *const Loc, options: anytype, writer: anytype) !void { - return try std.json.stringify(self.start, options, writer); + pub fn jsonStringify(self: *const Loc, writer: anytype) !void { + return try writer.write(self.start); } }; @@ -616,8 +616,8 @@ pub const Range = struct { return std.math.lossyCast(usize, self.loc.start + self.len); } - pub fn jsonStringify(self: *const Range, options: anytype, writer: anytype) !void { - return try std.json.stringify([2]i32{ self.loc.start, self.len + self.loc.start }, options, writer); + pub fn jsonStringify(self: *const Range, writer: anytype) !void { + return try writer.write([2]i32{ self.loc.start, self.len + self.loc.start }); } }; diff --git a/src/output.zig b/src/output.zig index 4feab61893b9e7..2b3f8cca527933 100644 --- a/src/output.zig +++ b/src/output.zig @@ -9,6 +9,8 @@ const StringTypes = @import("root").bun.StringTypes; const Global = @import("root").bun.Global; const ComptimeStringMap = @import("root").bun.ComptimeStringMap; const use_mimalloc = @import("root").bun.use_mimalloc; +const writeStream = std.json.writeStream; +const WriteStream = std.json.WriteStream; const SystemTimer = @import("./system_timer.zig").Timer; diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 2730daf422b179..08eca8333fc977 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -68,34 +68,34 @@ const bufs = struct { // bundling 10 copies of Three.js. It may be worthwhile for more complicated // packages but we lack a decent module resolution benchmark right now. // Potentially revisit after https://github.com/oven-sh/bun/issues/2716 - threadlocal var extension_path: [512]u8 = undefined; - threadlocal var tsconfig_match_full_buf: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var tsconfig_match_full_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; - - threadlocal var esm_subpath: [512]u8 = undefined; - threadlocal var esm_absolute_package_path: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var esm_absolute_package_path_joined: [bun.MAX_PATH_BYTES]u8 = undefined; - - threadlocal var dir_entry_paths_to_resolve: [256]DirEntryResolveQueueItem = undefined; - threadlocal var open_dirs: [256]std.fs.IterableDir = undefined; - threadlocal var resolve_without_remapping: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var index: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var dir_info_uncached_filename: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var node_bin_path: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var dir_info_uncached_path: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var tsconfig_base_url: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var relative_abs_path: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var load_as_file_or_directory_via_tsconfig_base_path: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var node_modules_check: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var field_abs_path: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var tsconfig_path_abs: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var check_browser_map: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var remap_path: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var load_as_file: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var remap_path_trailing_slash: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var path_in_global_disk_cache: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var abs_to_rel: [bun.MAX_PATH_BYTES]u8 = undefined; - threadlocal var node_modules_paths_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var extension_path: [512]u8 = undefined; + pub threadlocal var tsconfig_match_full_buf: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var tsconfig_match_full_buf2: [bun.MAX_PATH_BYTES]u8 = undefined; + + pub threadlocal var esm_subpath: [512]u8 = undefined; + pub threadlocal var esm_absolute_package_path: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var esm_absolute_package_path_joined: [bun.MAX_PATH_BYTES]u8 = undefined; + + pub threadlocal var dir_entry_paths_to_resolve: [256]DirEntryResolveQueueItem = undefined; + pub threadlocal var open_dirs: [256]std.fs.IterableDir = undefined; + pub threadlocal var resolve_without_remapping: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var index: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var dir_info_uncached_filename: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var node_bin_path: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var dir_info_uncached_path: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var tsconfig_base_url: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var relative_abs_path: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var load_as_file_or_directory_via_tsconfig_base_path: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var node_modules_check: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var field_abs_path: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var tsconfig_path_abs: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var check_browser_map: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var remap_path: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var load_as_file: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var remap_path_trailing_slash: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var path_in_global_disk_cache: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var abs_to_rel: [bun.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var node_modules_paths_buf: [bun.MAX_PATH_BYTES]u8 = undefined; pub inline fn bufs(comptime field: std.meta.DeclEnum(@This())) *@TypeOf(@field(@This(), @tagName(field))) { return &@field(@This(), @tagName(field)); diff --git a/src/sync.zig b/src/sync.zig index d2ecd95bd38b48..ec9105cf3d76a8 100644 --- a/src/sync.zig +++ b/src/sync.zig @@ -69,7 +69,7 @@ pub const ThreadPool = struct { const allocator = self.allocator; const closure = try allocator.create(Closure); - errdefer allocator.free(closure); + errdefer allocator.destroy(closure); closure.* = Closure{ .func_args = args, .allocator = allocator,