Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest Zig #1610

Merged
merged 73 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
72c8657
@min and @max
Jarred-Sumner Nov 29, 2022
b00d56a
builtins and some trivial ones
Jarred-Sumner Nov 29, 2022
0410789
Most of them
Jarred-Sumner Nov 29, 2022
6c4c424
more
Jarred-Sumner Nov 29, 2022
223515e
more!
Jarred-Sumner Nov 29, 2022
ddef776
More Progress
Jarred-Sumner Nov 29, 2022
8e81863
wip
Jarred-Sumner Nov 29, 2022
c6f38a9
Update tagged_pointer.zig
Jarred-Sumner Nov 29, 2022
0c482f6
Update http_client_async.zig
Jarred-Sumner Nov 29, 2022
a46f6db
Most of the iterable dir changes
Jarred-Sumner Nov 30, 2022
ebdab10
alright
Jarred-Sumner Nov 30, 2022
9c4c28e
Remove usages of deprecated formatters
Jarred-Sumner Nov 30, 2022
35424f2
:camera:
Jarred-Sumner Dec 8, 2022
c25950c
Merge branch 'main' into jarred/attempt-upgrade
Jarred-Sumner Dec 8, 2022
e58f769
fmt
Jarred-Sumner Dec 8, 2022
942ea16
Update shimmer.zig
Jarred-Sumner Dec 8, 2022
f89c55b
wip
Jarred-Sumner Dec 8, 2022
16f779c
wip
Jarred-Sumner Dec 8, 2022
77fcdac
wip
Jarred-Sumner Dec 8, 2022
7de388e
progress
Vexu Dec 19, 2022
8846e7f
more
Vexu Dec 19, 2022
19b0843
Merge branch 'main' into jarred/attempt-upgrade
Jarred-Sumner Dec 19, 2022
e007aa6
Merge branch 'main' into jarred/attempt-upgrade
Jarred-Sumner Dec 23, 2022
b48992c
Latest
Jarred-Sumner Dec 23, 2022
70ad718
stuck on error
Jarred-Sumner Dec 23, 2022
cb02d62
latest
Jarred-Sumner Dec 24, 2022
3acdfe3
Merge branch 'main' into jarred/attempt-upgrade
Jarred-Sumner Dec 24, 2022
9825aff
workaround stage2
Jarred-Sumner Dec 24, 2022
508f61b
wip
Jarred-Sumner Dec 24, 2022
12b5b7f
Update string_immutable.zig
Jarred-Sumner Dec 24, 2022
3368eed
wip
Jarred-Sumner Dec 25, 2022
26ec2ea
Migrate `Dirent` and `require("fs')` to use JSC<>Zig bindings
Jarred-Sumner Dec 25, 2022
2d7449d
Fix build errors
Jarred-Sumner Dec 25, 2022
b79ffac
Fixup most of the test failures
Jarred-Sumner Dec 25, 2022
52add73
Fix `make headers`
Jarred-Sumner Dec 26, 2022
a89029f
Fix "outside package path" error
Jarred-Sumner Dec 26, 2022
0341f91
Fixup aligned alloc
Jarred-Sumner Dec 26, 2022
0106b16
Add missing file
Jarred-Sumner Dec 26, 2022
45039a8
linux
Jarred-Sumner Dec 26, 2022
dd6b438
More linux fixes
Jarred-Sumner Dec 27, 2022
49c698e
use latest peechy
Jarred-Sumner Dec 27, 2022
ba7ae2d
Fix transpiler test failure
Jarred-Sumner Dec 27, 2022
407eeb2
Forgot about these
Jarred-Sumner Dec 27, 2022
d58d745
Fixup test failure
Jarred-Sumner Dec 27, 2022
40e3e67
Update node-timers.test.ts
Jarred-Sumner Dec 27, 2022
217771c
[node:htt] Fix `undefined is not an object` error
Jarred-Sumner Dec 27, 2022
dff7c69
Update http.exports.js
Jarred-Sumner Dec 27, 2022
259710b
Make this test less flaky
Jarred-Sumner Dec 27, 2022
07db129
fix hashes
Jarred-Sumner Dec 27, 2022
6ecd32c
Fix hex formatting and zls issues
Jarred-Sumner Dec 27, 2022
cda32d0
Download zig version
Jarred-Sumner Dec 27, 2022
da662ef
Update Dockerfile
Jarred-Sumner Dec 27, 2022
3138dde
Update Dockerfile
Jarred-Sumner Dec 27, 2022
12eb62f
Update uws
Jarred-Sumner Dec 27, 2022
d9d9158
Update Dockerfile
Jarred-Sumner Dec 27, 2022
f394462
Set llvm version
Jarred-Sumner Dec 27, 2022
c715c2e
Update README.md
Jarred-Sumner Dec 27, 2022
a1c78c3
Update uws
Jarred-Sumner Dec 27, 2022
b90c705
Update Dockerfile
Jarred-Sumner Dec 27, 2022
44d571d
Update io_linux.zig
Jarred-Sumner Dec 27, 2022
3a3a5f0
Update bun.zig
Jarred-Sumner Dec 27, 2022
d72a355
Log output
Jarred-Sumner Dec 27, 2022
4c504d9
workaround strange @cInclude error
Jarred-Sumner Dec 27, 2022
c5e03a1
Make ffi tests better
Jarred-Sumner Dec 27, 2022
a49f6af
Don't use cImport
Jarred-Sumner Dec 27, 2022
15ac345
Update c.zig
Jarred-Sumner Dec 27, 2022
edfc6b3
Update c-bindings.cpp
Jarred-Sumner Dec 27, 2022
2c39776
call setOutputDir
Jarred-Sumner Dec 27, 2022
5f33693
Update Dockerfile
Jarred-Sumner Dec 27, 2022
3180fa7
Use a longer name
Jarred-Sumner Dec 27, 2022
4f203c9
latest
Jarred-Sumner Dec 28, 2022
c8a9ab5
Merge branch 'main' into jarred/attempt-upgrade
Jarred-Sumner Dec 28, 2022
4bddb21
Update serve.test.ts
Jarred-Sumner Dec 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more
  • Loading branch information
Vexu committed Dec 19, 2022
commit 8846e7fbd6460176dcdd728b1d252053e3f7bca6
6 changes: 3 additions & 3 deletions src/api/schema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub const Reader = struct {
return E.InvalidValue;
}

pub inline fn readArray(this: *Self, comptime T: type) ![]const T {
pub fn readArray(this: *Self, comptime T: type) ![]const T {
const length = try this.readInt(u32);
if (length == 0) {
return &([_]T{});
Expand Down Expand Up @@ -156,7 +156,7 @@ pub const Reader = struct {
.Packed => {
const sizeof = @sizeOf(T);
var slice = try this.read(sizeof);
return @ptrCast(*T, slice[0..sizeof]).*;
return @ptrCast(*align(1) T, slice[0..sizeof]).*;
},
else => {},
}
Expand Down Expand Up @@ -263,7 +263,7 @@ pub fn Writer(comptime WritableStream: type) type {
}
}

pub inline fn writeArray(this: *Self, comptime T: type, slice: anytype) !void {
pub fn writeArray(this: *Self, comptime T: type, slice: anytype) !void {
try this.writeInt(@truncate(u32, slice.len));

switch (T) {
Expand Down
2 changes: 1 addition & 1 deletion src/baby_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub fn BabyList(comptime Type: type) type {
}

pub fn one(allocator: std.mem.Allocator, value: Type) !ListType {
var items = try allocator.allocAdvanced(Type, @alignOf(Type), 1, .exact);
var items = try allocator.alloc(Type, 1);
items[0] = value;
return ListType{
.ptr = @ptrCast([*]Type, items.ptr),
Expand Down
7 changes: 4 additions & 3 deletions src/bun.js/api/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ pub fn readFileAsBytesCallback(
errdefer VirtualMachine.vm.allocator.free(contents_buf);
const contents_len = file.readAll(contents_buf) catch |err| {
JSError(getAllocator(ctx), "{s} reading file (\"{s}\")", .{ @errorName(err), path }, ctx, exception);
if (true) @panic("todo??");
return js.JSValueMakeUndefined(ctx);
};

Expand Down Expand Up @@ -3459,7 +3460,7 @@ pub const JSZlib = struct {
}
return ZigString.init("Zlib returned an error").toErrorInstance(globalThis);
};
reader.list = .{ .items = try reader.list.toOwnedSlice(allocator) };
reader.list = .{ .items = reader.list.toOwnedSlice(allocator) catch @panic("TODO") };
reader.list.capacity = reader.list.items.len;
reader.list_ptr = &reader.list;

Expand Down Expand Up @@ -3491,7 +3492,7 @@ pub const JSZlib = struct {
}
return ZigString.init("Zlib returned an error").toErrorInstance(globalThis);
};
reader.list = .{ .items = try reader.list.toOwnedSlice(allocator) };
reader.list = .{ .items = reader.list.toOwnedSlice(allocator) catch @panic("TODO") };
reader.list.capacity = reader.list.items.len;
reader.list_ptr = &reader.list;

Expand Down Expand Up @@ -3521,7 +3522,7 @@ pub const JSZlib = struct {
}
return ZigString.init("Zlib returned an error").toErrorInstance(globalThis);
};
reader.list = .{ .items = try reader.list.toOwnedSlice(allocator) };
reader.list = .{ .items = reader.list.toOwnedSlice(allocator) catch @panic("TODO") };
reader.list.capacity = reader.list.items.len;
reader.list_ptr = &reader.list;

Expand Down
7 changes: 4 additions & 3 deletions src/bun.js/api/bun/subprocess.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ pub const Subprocess = struct {
var cwd = jsc_vm.bundler.fs.top_level_dir;

var stdio = [3]Stdio{
.{ .ignore = .{} },
.{ .ignore = {} },
.{ .pipe = null },
.{ .inherit = {} },
};
Expand Down Expand Up @@ -1762,7 +1762,8 @@ pub const Subprocess = struct {
} else if (value.as(JSC.WebCore.Response)) |req| {
req.getBodyValue().toBlobIfPossible();
return extractStdioBlob(globalThis, req.getBodyValue().useAsAnyBlob(), i, stdio_array);
} else if (JSC.WebCore.ReadableStream.fromJS(value, globalThis)) |*req| {
} else if (JSC.WebCore.ReadableStream.fromJS(value, globalThis)) |req_const| {
var req = req_const;
if (i == std.os.STDIN_FILENO) {
if (req.toAnyBlob(globalThis)) |blob| {
return extractStdioBlob(globalThis, blob, i, stdio_array);
Expand All @@ -1776,7 +1777,7 @@ pub const Subprocess = struct {
return false;
}

stdio_array[i] = .{ .pipe = req.* };
stdio_array[i] = .{ .pipe = req };
return true;
},
else => {},
Expand Down
12 changes: 6 additions & 6 deletions src/bun.js/api/ffi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,10 @@ pub const FFI = struct {
extern fn pthread_jit_write_protect_np(enable: bool) callconv(.C) void;

const MyFunctionSStructWorkAround = struct {
JSVALUE_TO_INT64: fn (JSValue0: JSC.JSValue) callconv(.C) i64,
JSVALUE_TO_UINT64: fn (JSValue0: JSC.JSValue) callconv(.C) u64,
INT64_TO_JSVALUE: fn (arg0: [*c]JSC.JSGlobalObject, arg1: i64) callconv(.C) JSC.JSValue,
UINT64_TO_JSVALUE: fn (arg0: [*c]JSC.JSGlobalObject, arg1: u64) callconv(.C) JSC.JSValue,
JSVALUE_TO_INT64: *const fn (JSValue0: JSC.JSValue) callconv(.C) i64,
JSVALUE_TO_UINT64: *const fn (JSValue0: JSC.JSValue) callconv(.C) u64,
INT64_TO_JSVALUE: *const fn (arg0: [*c]JSC.JSGlobalObject, arg1: i64) callconv(.C) JSC.JSValue,
UINT64_TO_JSVALUE: *const fn (arg0: [*c]JSC.JSGlobalObject, arg1: u64) callconv(.C) JSC.JSValue,
bun_call: *const @TypeOf(JSC.C.JSObjectCallAsFunction),
};
const headers = @import("../bindings/headers.zig");
Expand Down Expand Up @@ -832,7 +832,7 @@ pub const FFI = struct {
return;
}

var bytes: []u8 = try allocator.rawAlloc(@intCast(usize, relocation_size), 16, 16, 0);
var bytes: []u8 = try allocator.alloc(u8, @intCast(usize, relocation_size));
defer {
if (this.step == .failed) {
allocator.free(bytes);
Expand Down Expand Up @@ -992,7 +992,7 @@ pub const FFI = struct {
return;
}

var bytes: []u8 = try allocator.rawAlloc(@intCast(usize, relocation_size), 16, 16, 0);
var bytes: []u8 = try allocator.alloc(u8, @intCast(usize, relocation_size));
defer {
if (this.step == .failed) {
allocator.free(bytes);
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/html_rewriter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub const HTMLRewriter = struct {
if (sink.response.body.value == .Locked and @ptrToInt(sink.response.body.value.Locked.task) == @ptrToInt(sink) and
sink.response.body.value.Locked.promise == null)
{
sink.response.body.value = .{ .Empty = .{} };
sink.response.body.value = .{ .Empty = {} };
// is there a pending promise?
// we will need to reject it
} else if (sink.response.body.value == .Locked and @ptrToInt(sink.response.body.value.Locked.task) == @ptrToInt(sink) and
Expand Down
43 changes: 26 additions & 17 deletions src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -553,26 +553,33 @@ pub fn NewRequestContextStackAllocator(comptime RequestContext: type, comptime c

pub fn get(this: *@This()) std.mem.Allocator {
this.unused = Set.initFull();
return std.mem.Allocator.init(this, alloc, resize, free);
return .{
.ptr = this,
.vtable = &.{
.alloc = alloc,
.resize = resize,
.free = free,
},
};
}

fn alloc(self: *@This(), a: usize, b: u29, c: u29, d: usize) ![]u8 {
fn alloc(self_: *anyopaque, a: usize, b: u8, d: usize) ?[*]u8 {
const self = @ptrCast(*@This(), @alignCast(@alignOf(@This()), self_));
if (self.unused.findFirstSet()) |i| {
self.unused.unset(i);
return std.mem.asBytes(&self.buf[i]);
}

return try self.fallback_allocator.rawAlloc(a, b, c, d);
return self.fallback_allocator.rawAlloc(a, b, d);
}

fn resize(
_: *@This(),
_: *anyopaque,
_: []u8,
_: u29,
_: u8,
_: usize,
_: u29,
_: usize,
) ?usize {
) bool {
unreachable;
}

Expand All @@ -582,11 +589,12 @@ pub fn NewRequestContextStackAllocator(comptime RequestContext: type, comptime c
}

fn free(
self: *@This(),
self_: *anyopaque,
buf: []u8,
buf_align: u29,
buf_align: u8,
return_address: usize,
) void {
const self = @ptrCast(*@This(), @alignCast(@alignOf(@This()), self_));
const bytes = std.mem.asBytes(&self.buf);
if (sliceContainsSlice(bytes, buf)) {
const index = if (bytes[0..buf.len].ptr != buf.ptr)
Expand Down Expand Up @@ -2085,7 +2093,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
this.renderDefaultError(
vm.log,
error.ExceptionOcurred,
try exception_list.toOwnedSlice(),
exception_list.toOwnedSlice() catch @panic("TODO"),
"<r><red>{s}<r> - <b>{s}<r> failed",
.{ @as(string, @tagName(this.method)), this.ensurePathname() },
);
Expand Down Expand Up @@ -2390,7 +2398,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
if (request.as(Request)) |req| {
var old = req.body;
old.Locked.onReceiveValue = null;
req.body = .{ .Empty = .{} };
req.body = .{ .Empty = {} };
old.resolve(&req.body, this.server.globalThis);
return;
}
Expand All @@ -2401,7 +2409,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
if (request.as(Request)) |req| {
var old = req.body;
old.Locked.onReceiveValue = null;
req.body = .{ .Empty = .{} };
req.body = .{ .Empty = {} };
old.toError(error.RequestBodyTooLarge, this.server.globalThis);
return;
}
Expand All @@ -2418,7 +2426,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
if (request.as(Request)) |req| {
var old = req.body;
old.Locked.onReceiveValue = null;
req.body = .{ .Empty = .{} };
req.body = .{ .Empty = {} };
old.resolve(&req.body, this.server.globalThis);
return;
}
Expand Down Expand Up @@ -4124,7 +4132,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {

var url: URL = undefined;
var first_arg = args.nextEat().?;
var body: JSC.WebCore.Body.Value = .{ .Empty = .{} };
var body: JSC.WebCore.Body.Value = .{ .Empty = {} };
var existing_request: ?WebCore.Request = null;
// TODO: set Host header
// TODO: set User-Agent header
Expand Down Expand Up @@ -4401,7 +4409,8 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
if (written > 0) {
var message = output_buf[0..written];
zig_str = ZigString.init(std.fmt.allocPrint(bun.default_allocator, "OpenSSL {s}", .{message}) catch unreachable);
zig_str.withEncoding().mark();
var encoded_str = zig_str.withEncoding();
encoded_str.mark();
}
}

Expand Down Expand Up @@ -4516,7 +4525,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
.uws_request = req,
.https = ssl_enabled,
.body = .{
.Empty = .{},
.Empty = {},
},
};

Expand Down Expand Up @@ -4596,7 +4605,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
.upgrader = ctx,
.https = ssl_enabled,
.body = .{
.Empty = .{},
.Empty = {},
},
};
ctx.upgrade_context = upgrade_ctx;
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/transpiler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ fn transformOptionsFromJSC(ctx: JSC.C.JSContextRef, temp_allocator: std.mem.Allo
return transpiler;
}

names[define_iter.i] = try prop.toOwnedSlice(allocator) catch unreachable;
names[define_iter.i] = prop.toOwnedSlice(allocator) catch unreachable;
var val = JSC.ZigString.init("");
property_value.toZigString(&val, globalThis);
if (val.len == 0) {
Expand Down Expand Up @@ -627,7 +627,7 @@ fn transformOptionsFromJSC(ctx: JSC.C.JSContextRef, temp_allocator: std.mem.Allo
};
buf.items.len += name.len;
if (name.len > 0) {
replacements.putAssumeCapacity(name, .{ .delete = .{} });
replacements.putAssumeCapacity(name, .{ .delete = {} });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3323,7 +3323,7 @@ pub const VM = extern struct {
return cppFn("deleteAllCode", .{ vm, global_object });
}

extern fn Bun__setOnEachMicrotaskTick(vm: *VM, ptr: ?*anyopaque, callback: ?(fn (*anyopaque) callconv(.C) void)) void;
extern fn Bun__setOnEachMicrotaskTick(vm: *VM, ptr: ?*anyopaque, callback: ?*const fn (*anyopaque) callconv(.C) void) void;

pub fn onEachMicrotask(vm: *VM, comptime Ptr: type, ptr: *Ptr, comptime callback: *const fn (*Ptr) void) void {
if (comptime is_bindgen) {
Expand Down
Loading