Skip to content

less undefined #4492

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

Closed
wants to merge 19 commits into from
6 changes: 3 additions & 3 deletions src/allocators.zig
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type {

allocator: Allocator,
mutex: Mutex = Mutex.init(),
head: *OverflowBlock = undefined,
head: ?*OverflowBlock = null,
tail: OverflowBlock = OverflowBlock{},
backing_buf: [count]ValueType = undefined,
used: u32 = 0,
Expand Down Expand Up @@ -230,12 +230,12 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type {

fn appendOverflow(self: *Self, value: ValueType) !*ValueType {
instance.used += 1;
return self.head.append(value) catch brk: {
return self.head.?.append(value) catch brk: {
var new_block = try self.allocator.create(OverflowBlock);
new_block.* = OverflowBlock{};
new_block.prev = self.head;
self.head = new_block;
break :brk self.head.append(value);
break :brk self.head.?.append(value);
};
}

Expand Down
31 changes: 16 additions & 15 deletions src/baby_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const bun = @import("root").bun;
pub fn BabyList(comptime Type: type) type {
return struct {
const ListType = @This();
ptr: [*]Type = undefined,
ptr: ?[*]Type = null,
len: u32 = 0,
cap: u32 = 0,

Expand All @@ -21,7 +21,7 @@ pub fn BabyList(comptime Type: type) type {
}

pub fn available(this: *@This()) []Type {
return this.ptr[this.len..this.cap];
return this.ptr.?[this.len..this.cap];
}

pub fn deinitWithAllocator(this: *@This(), allocator: std.mem.Allocator) void {
Expand All @@ -30,7 +30,7 @@ pub fn BabyList(comptime Type: type) type {
}

pub fn contains(this: @This(), item: []const Type) bool {
return this.len > 0 and @intFromPtr(item.ptr) >= @intFromPtr(this.ptr) and @intFromPtr(item.ptr) < @intFromPtr(this.ptr) + this.len;
return this.len > 0 and @intFromPtr(item.ptr) >= @intFromPtr(this.ptr.?) and @intFromPtr(item.ptr) < @intFromPtr(this.ptr.?) + this.len;
}

pub inline fn initConst(items: []const Type) ListType {
Expand All @@ -52,7 +52,7 @@ pub fn BabyList(comptime Type: type) type {
pub fn popOrNull(this: *@This()) ?Type {
if (this.len == 0) return null;
this.len -= 1;
return this.ptr[this.len];
return this.ptr.?[this.len];
}

pub fn clone(this: @This(), allocator: std.mem.Allocator) !@This() {
Expand All @@ -66,7 +66,7 @@ pub fn BabyList(comptime Type: type) type {
}

pub fn appendAssumeCapacity(this: *@This(), value: Type) void {
this.ptr[this.len] = value;
this.ptr.?[this.len] = value;
this.len += 1;
std.debug.assert(this.cap >= this.len);
}
Expand All @@ -81,7 +81,7 @@ pub fn BabyList(comptime Type: type) type {
}

pub fn appendSliceAssumeCapacity(this: *@This(), values: []const Type) void {
var tail = this.ptr[this.len .. this.len + values.len];
var tail = this.ptr.?[this.len .. this.len + values.len];
std.debug.assert(this.cap >= this.len + @as(u32, @truncate(values.len)));
bun.copy(Type, tail, values);
this.len += @as(u32, @truncate(values.len));
Expand Down Expand Up @@ -153,40 +153,41 @@ pub fn BabyList(comptime Type: type) type {
}

pub fn list(this: ListType) std.ArrayListUnmanaged(Type) {
const items = if (this.ptr) |ptr| ptr[0..this.len] else @as([]Type, &.{});
return std.ArrayListUnmanaged(Type){
.items = this.ptr[0..this.len],
.items = items,
.capacity = this.cap,
};
}

pub fn listManaged(this: ListType, allocator: std.mem.Allocator) std.ArrayList(Type) {
return std.ArrayList(Type){
.items = this.ptr[0..this.len],
.items = this.ptr.?[0..this.len],
.capacity = this.cap,
.allocator = allocator,
};
}

pub inline fn first(this: ListType) ?*Type {
return if (this.len > 0) this.ptr[0] else @as(?*Type, null);
return if (this.len > 0) this.ptr.?[0] else @as(?*Type, null);
}

pub inline fn last(this: ListType) ?*Type {
return if (this.len > 0) &this.ptr[this.len - 1] else @as(?*Type, null);
return if (this.len > 0) &this.ptr.?[this.len - 1] else @as(?*Type, null);
}

pub inline fn first_(this: ListType) Type {
return this.ptr[0];
return this.ptr.?[0];
}

pub inline fn at(this: ListType, index: usize) *const Type {
std.debug.assert(index < this.len);
return &this.ptr[index];
return &this.ptr.?[index];
}

pub inline fn mut(this: ListType, index: usize) *Type {
std.debug.assert(index < this.len);
return &this.ptr[index];
return &this.ptr.?[index];
}

pub fn one(allocator: std.mem.Allocator, value: Type) !ListType {
Expand All @@ -200,7 +201,7 @@ pub fn BabyList(comptime Type: type) type {
}

pub inline fn @"[0]"(this: ListType) Type {
return this.ptr[0];
return this.ptr.?[0];
}
const OOM = error{OutOfMemory};

Expand All @@ -218,7 +219,7 @@ pub fn BabyList(comptime Type: type) type {

pub inline fn slice(this: ListType) []Type {
@setRuntimeSafety(false);
return this.ptr[0..this.len];
return this.ptr.?[0..this.len];
}

pub fn write(this: *@This(), allocator: std.mem.Allocator, str: []const u8) !u32 {
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ pub const JSBundler = struct {
value: Value,
js_task: JSC.AnyTask = undefined,
task: JSC.AnyEventLoop.Task = undefined,
parse_task: *bun.ParseTask = undefined,
parse_task: ?*bun.ParseTask = null,

/// Faster path: skip the extra threadpool dispatch when the file is not found
was_file: bool = false,
Expand Down Expand Up @@ -823,7 +823,7 @@ pub const JSBundler = struct {

if (this.was_file) {
// Faster path: skip the extra threadpool dispatch
completion.bundler.graph.pool.pool.schedule(bun.ThreadPool.Batch.from(&this.parse_task.task));
completion.bundler.graph.pool.pool.?.schedule(bun.ThreadPool.Batch.from(&this.parse_task.?.task));
this.deinit();
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/bun.js/api/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ fn getImportedStyles(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callc
}

pub fn dump_mimalloc(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) callconv(.C) JSC.JSValue {
globalObject.bunVM().arena.dumpStats();
globalObject.bunVM().arena.?.dumpStats();
return .undefined;
}

Expand Down Expand Up @@ -1006,8 +1006,8 @@ pub const Crypto = struct {

const BoringSSL = bun.BoringSSL;
const EVP = struct {
ctx: BoringSSL.EVP_MD_CTX = undefined,
md: *const BoringSSL.EVP_MD = undefined,
ctx: BoringSSL.EVP_MD_CTX,
md: ?*const BoringSSL.EVP_MD = null,
algorithm: Algorithm,

// we do this to avoid asking BoringSSL what the digest name is
Expand Down Expand Up @@ -1134,7 +1134,7 @@ pub const Crypto = struct {
}

pub fn copy(this: *const EVP, engine: *BoringSSL.ENGINE) error{OutOfMemory}!EVP {
var new = init(this.algorithm, this.md, engine);
var new = init(this.algorithm, this.md.?, engine);
if (BoringSSL.EVP_MD_CTX_copy_ex(&new.ctx, &this.ctx) == 0) {
return error.OutOfMemory;
}
Expand Down
Loading