Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ examples/kvstore/go-client/kvstore-client
test_*
e2e_runner
.tmp/
.worktrees/

# Dolt database files (added by bd init)
.dolt/
Expand Down
11 changes: 2 additions & 9 deletions bench/packed_unpacked.zig
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,8 @@ fn measureAllocationSample(
}

pub fn main(init: std.process.Init) !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer {
const deinit_status = gpa.deinit();
if (deinit_status == .leak) {
std.debug.print("warning: allocator reported leaks\n", .{});
}
}

const allocator = gpa.allocator();
// Keep benchmark timings close to release behavior rather than debug allocator overhead.
const allocator = std.heap.smp_allocator;
const io = init.io;

const cfg = (parseArgs(init.minimal.args, io) catch |err| {
Expand Down
11 changes: 2 additions & 9 deletions bench/ping_pong.zig
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,8 @@ fn measureAllocationSample(
}

pub fn main(init: std.process.Init) !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer {
const deinit_status = gpa.deinit();
if (deinit_status == .leak) {
std.debug.print("warning: allocator reported leaks\n", .{});
}
}

const allocator = gpa.allocator();
// Keep benchmark timings close to release behavior rather than debug allocator overhead.
const allocator = std.heap.smp_allocator;
const io = init.io;

const cfg = (parseArgs(init.minimal.args, io) catch |err| {
Expand Down
18 changes: 9 additions & 9 deletions src/capnpc-zig/generator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub const Generator = struct {

// Generate declarations into a body buffer first, then emit only imports
// that are actually referenced by generated declarations.
var body = std.ArrayList(u8){};
var body = std.ArrayList(u8).empty;
defer body.deinit(self.allocator);
const body_writer = ArrayListWriter{ .list = &body, .allocator = self.allocator };

Expand All @@ -173,7 +173,7 @@ pub const Generator = struct {
try self.generateNodeRecursive(nested.id, &generated, &body);
}

var output = std.ArrayList(u8){};
var output = std.ArrayList(u8).empty;
errdefer output.deinit(self.allocator);
const writer = ArrayListWriter{ .list = &output, .allocator = self.allocator };

Expand Down Expand Up @@ -235,7 +235,7 @@ pub const Generator = struct {
var seen = std.AutoHashMap(schema.Id, void).init(self.allocator);
defer seen.deinit();

var entries = std.ArrayList(ManifestSerdeEntry){};
var entries = std.ArrayList(ManifestSerdeEntry).empty;
defer {
for (entries.items) |entry| {
self.allocator.free(entry.type_name);
Expand Down Expand Up @@ -503,7 +503,7 @@ pub const Generator = struct {
/// Reuses the first declaration for identical struct bodies by emitting a
/// type alias for later occurrences.
fn generateStructWithShapeSharing(self: *Generator, node: *const schema.Node, writer: anytype) !void {
var struct_buf = std.ArrayList(u8){};
var struct_buf = std.ArrayList(u8).empty;
defer struct_buf.deinit(self.allocator);

{
Expand Down Expand Up @@ -560,7 +560,7 @@ pub const Generator = struct {
/// Walk superclasses recursively to collect all ancestor interfaces (not including self).
/// Deduplicates by interface_id to handle diamond inheritance.
fn collectAncestors(self: *Generator, node: *const schema.Node) ![]AncestorInfo {
var result = std.ArrayList(AncestorInfo){};
var result = std.ArrayList(AncestorInfo).empty;
errdefer {
for (result.items) |a| self.allocator.free(a.name);
result.deinit(self.allocator);
Expand Down Expand Up @@ -1386,7 +1386,7 @@ pub const Generator = struct {
const node = self.getNode(struct_id) orelse return try self.allocator.alloc(InterfaceFieldInfo, 0);
const struct_info = node.struct_node orelse return try self.allocator.alloc(InterfaceFieldInfo, 0);

var result = std.ArrayList(InterfaceFieldInfo){};
var result = std.ArrayList(InterfaceFieldInfo).empty;
errdefer {
for (result.items) |item| {
self.allocator.free(item.name);
Expand Down Expand Up @@ -1521,7 +1521,7 @@ pub const Generator = struct {
}

fn toSnakeCaseLower(self: *Generator, name: []const u8) ![]u8 {
var out = std.ArrayList(u8){};
var out = std.ArrayList(u8).empty;
errdefer out.deinit(self.allocator);

var prev_was_sep = false;
Expand Down Expand Up @@ -2685,7 +2685,7 @@ test "Generator.writeByteArrayLiteral formats bytes" {
var gen = Generator.init(alloc, &.{}) catch unreachable;
defer gen.deinit();

var buf = std.ArrayList(u8){};
var buf = std.ArrayList(u8).empty;
defer buf.deinit(alloc);
const writer = ArrayListWriter{ .list = &buf, .allocator = alloc };

Expand All @@ -2698,7 +2698,7 @@ test "Generator.writeByteArrayLiteral handles empty data" {
var gen = Generator.init(alloc, &.{}) catch unreachable;
defer gen.deinit();

var buf = std.ArrayList(u8){};
var buf = std.ArrayList(u8).empty;
defer buf.deinit(alloc);
const writer = ArrayListWriter{ .list = &buf, .allocator = alloc };

Expand Down
2 changes: 1 addition & 1 deletion src/capnpc-zig/struct_gen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ test "StructGenerator.writeByteArrayLiteral formats bytes" {
const alloc = std.testing.allocator;
var sg = StructGenerator.init(alloc);

var buf = std.ArrayList(u8){};
var buf = std.ArrayList(u8).empty;
defer buf.deinit(alloc);
const writer = ArrayListWriter{ .list = &buf, .allocator = alloc };

Expand Down
2 changes: 1 addition & 1 deletion src/capnpc-zig/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn escapeZigKeyword(allocator: std.mem.Allocator, name: []const u8) ![]const
}

fn normalizeIdentifier(allocator: std.mem.Allocator, name: []const u8, capitalize_first: bool) ![]u8 {
var result = std.ArrayList(u8){};
var result = std.ArrayList(u8).empty;
errdefer result.deinit(allocator);

var capitalize_next = capitalize_first;
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/integration/host_peer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub const HostPeer = struct {
.allocator = allocator,
.outgoing_allocator = outgoing_allocator,
.peer = peer_mod.Peer.initDetached(allocator),
.outgoing = std.ArrayList([]u8){},
.host_calls = std.ArrayList(HostCall){},
.outgoing = std.ArrayList([]u8).empty,
.host_calls = std.ArrayList(HostCall).empty,
.pending_host_call_questions = std.AutoHashMap(u32, void).init(allocator),
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/level0/cap_table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ pub const OutboundCapEffects = struct {
.allocator = allocator,
.ctx = ctx,
.on_entry_rollback = on_entry_rollback,
.callback_applied = std.ArrayList(OutboundEntry){},
.consumed_receiver_answer_ids = std.ArrayList(u32){},
.callback_applied = std.ArrayList(OutboundEntry).empty,
.consumed_receiver_answer_ids = std.ArrayList(u32).empty,
};
}

Expand Down Expand Up @@ -390,7 +390,7 @@ const OutboundCapTable = struct {
fn init(allocator: std.mem.Allocator) OutboundCapTable {
return .{
.allocator = allocator,
.entries = std.ArrayList(OutboundEntry){},
.entries = std.ArrayList(OutboundEntry).empty,
.index_map = std.AutoHashMap(u64, u32).init(allocator),
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/level0/framing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const Framer = struct {
pub fn init(allocator: std.mem.Allocator) Framer {
return .{
.allocator = allocator,
.buffer = std.ArrayList(u8){},
.buffer = std.ArrayList(u8).empty,
.expected_total = null,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/level1/peer_promises.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn queuePendingCall(
var entry = try pending_calls.getOrPut(key);
const inserted = !entry.found_existing;
if (!entry.found_existing) {
entry.value_ptr.* = std.ArrayList(PendingCallType){};
entry.value_ptr.* = std.ArrayList(PendingCallType).empty;
}
errdefer if (inserted and entry.value_ptr.items.len == 0) {
_ = pending_calls.remove(key);
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/level2/connection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ test "connection handleRead assembles fragmented frame and dispatches once compl

var state = Harness.State{
.allocator = allocator,
.received = std.ArrayList(u32){},
.received = std.ArrayList(u32).empty,
};
defer state.received.deinit(allocator);

Expand Down Expand Up @@ -467,7 +467,7 @@ test "connection handleRead dispatches coalesced frames in order" {

var state = Harness.State{
.allocator = allocator,
.received = std.ArrayList(u32){},
.received = std.ArrayList(u32).empty,
};
defer state.received.deinit(allocator);

Expand Down Expand Up @@ -527,7 +527,7 @@ test "connection handleRead stops draining when message handler errors" {

var state = Harness.State{
.allocator = allocator,
.received = std.ArrayList(u32){},
.received = std.ArrayList(u32).empty,
};
defer state.received.deinit(allocator);

Expand Down
6 changes: 3 additions & 3 deletions src/rpc/level2/transport.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub const Transport = struct {
/// a socketpair for blocking/waking the writer thread.
const WriteQueue = struct {
mu: std.atomic.Mutex = .unlocked,
items: std.ArrayListUnmanaged([]u8) = .{},
items: std.ArrayListUnmanaged([]u8) = .empty,
closed: bool = false,
/// Notification socketpair. [0]=read (writer thread), [1]=write (enqueue).
/// Set to -1 when not initialized or after close.
Expand Down Expand Up @@ -129,7 +129,7 @@ pub const Transport = struct {
defer self.mu.unlock();
if (self.items.items.len == 0) return null;
const result = self.items;
self.items = .{};
self.items = .empty;
return result;
}

Expand Down Expand Up @@ -158,7 +158,7 @@ pub const Transport = struct {
// Reinitialize to valid empty state. ArrayListUnmanaged.deinit
// sets self.* = undefined, so a second drain would crash without
// this reset.
self.items = .{};
self.items = .empty;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/rpc/level3/peer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ pub const Peer = struct {
question_id: u32,
) !bool {
var canceled = false;
var empty_keys = std.ArrayList(u32){};
var empty_keys = std.ArrayList(u32).empty;
defer empty_keys.deinit(self.allocator);

var pending_it = pending_map.iterator();
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/level3/peer/peer_cap_lifecycle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ test "peer_cap_lifecycle releaseResultCaps releases sender-hosted and sender-pro
releases: std.ArrayList(u32),

fn init() @This() {
return .{ .releases = std.ArrayList(u32){} };
return .{ .releases = std.ArrayList(u32).empty };
}

fn deinit(state: *@This(), allocator: std.mem.Allocator) void {
Expand Down
12 changes: 6 additions & 6 deletions src/rpc/level3/peer/peer_embargo_accepts.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn queueEmbargoedAccept(
const key = try allocator.dupe(u8, embargo);
errdefer allocator.free(key);

var pending = std.ArrayList(PendingAcceptType){};
var pending = std.ArrayList(PendingAcceptType).empty;
errdefer pending.deinit(allocator);
try pending.append(allocator, .{
.answer_id = answer_id,
Expand Down Expand Up @@ -335,8 +335,8 @@ test "peer_embargo_accepts release routes to provided target and exception for m
fn init(allocator: std.mem.Allocator) @This() {
return .{
.allocator = allocator,
.provided = std.ArrayList(SentResult){},
.exceptions = std.ArrayList(SentException){},
.provided = std.ArrayList(SentResult).empty,
.exceptions = std.ArrayList(SentException).empty,
};
}

Expand Down Expand Up @@ -437,7 +437,7 @@ test "peer_embargo_accepts release converts provided-send errors to return excep
fn init(allocator: std.mem.Allocator) @This() {
return .{
.allocator = allocator,
.exceptions = std.ArrayList(SentException){},
.exceptions = std.ArrayList(SentException).empty,
};
}

Expand Down Expand Up @@ -563,8 +563,8 @@ test "peer_embargo_accepts peer helper factories queue and release through peer
.pending_accepts_by_embargo = std.StringHashMap(std.ArrayList(TestPendingAccept)).init(std.testing.allocator),
.pending_accept_embargo_by_question = std.AutoHashMap(u32, []u8).init(std.testing.allocator),
.provides_by_question = std.AutoHashMap(u32, ProvideEntry).init(std.testing.allocator),
.provided = std.ArrayList(SentProvided){},
.exceptions = std.ArrayList(SentException){},
.provided = std.ArrayList(SentProvided).empty,
.exceptions = std.ArrayList(SentException).empty,
};
defer peer.deinit();

Expand Down
4 changes: 2 additions & 2 deletions src/rpc/level3/peer/provide/peer_join_state.zig
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ const SendState = struct {
fn init(allocator: std.mem.Allocator) @This() {
return .{
.allocator = allocator,
.provided = std.ArrayList(SentProvided){},
.exceptions = std.ArrayList(SentException){},
.provided = std.ArrayList(SentProvided).empty,
.exceptions = std.ArrayList(SentException).empty,
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/serialization/message.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn unpackPacked(allocator: std.mem.Allocator, packed_bytes: []const u8) ![]u8 {
// Size-estimation pass: scan packed bytes to calculate exact output size.
const total_size = try estimateUnpackedSize(packed_bytes);

var out = std.ArrayList(u8){};
var out = std.ArrayList(u8).empty;
errdefer out.deinit(allocator);

try out.ensureTotalCapacity(allocator, total_size);
Expand Down Expand Up @@ -200,7 +200,7 @@ inline fn wordHasZeroByte(v: u64) bool {
fn packPacked(allocator: std.mem.Allocator, bytes: []const u8) ![]u8 {
if (bytes.len % 8 != 0) return error.InvalidMessageSize;

var out = std.ArrayList(u8){};
var out = std.ArrayList(u8).empty;
errdefer out.deinit(allocator);

var index: usize = 0;
Expand Down Expand Up @@ -1599,7 +1599,7 @@ pub const MessageBuilder = struct {
pub fn init(allocator: std.mem.Allocator) MessageBuilder {
return .{
.allocator = allocator,
.segments = std.ArrayList(std.ArrayList(u8)){},
.segments = std.ArrayList(std.ArrayList(u8)).empty,
};
}

Expand All @@ -1614,7 +1614,7 @@ pub const MessageBuilder = struct {
fn createSegmentWithCapacity(self: *MessageBuilder, min_capacity: usize) !u32 {
if (self.segments.items.len > std.math.maxInt(u32)) return error.TooManySegments;
const id: u32 = @intCast(self.segments.items.len);
try self.segments.append(self.allocator, std.ArrayList(u8){});
try self.segments.append(self.allocator, std.ArrayList(u8).empty);
errdefer _ = self.segments.pop();
if (min_capacity > 0) {
try self.segments.items[id].ensureTotalCapacity(self.allocator, min_capacity);
Expand Down Expand Up @@ -2073,7 +2073,7 @@ pub const MessageBuilder = struct {
/// header followed by all segment data. The caller must free the returned
/// slice.
pub fn toBytes(self: *MessageBuilder) ![]const u8 {
var result = std.ArrayList(u8){};
var result = std.ArrayList(u8).empty;
errdefer result.deinit(self.allocator);

// Ensure we have at least one segment
Expand Down Expand Up @@ -2133,7 +2133,7 @@ pub const MessageBuilder = struct {
/// Stream the framed wire format directly to `writer` without intermediate allocation.
pub fn writeTo(self: *MessageBuilder, writer: anytype) !void {
if (self.segments.items.len == 0) {
try self.segments.append(self.allocator, std.ArrayList(u8){});
try self.segments.append(self.allocator, std.ArrayList(u8).empty);
}

const segment_count_usize = self.segments.items.len;
Expand Down
2 changes: 1 addition & 1 deletion src/serialization/reader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub const Reader = struct {
/// segment_count is checked, so amplification from a malicious packed
/// stream is limited to the header region.
pub fn readPackedMessage(allocator: std.mem.Allocator, reader: anytype) ![]const u8 {
var out = std.ArrayList(u8){};
var out = std.ArrayList(u8).empty;
errdefer out.deinit(allocator);

var total_needed: ?usize = null;
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/zig/main_client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ fn usage() void {
}

pub fn main(init: std.process.Init.Minimal) !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer std.debug.assert(gpa.deinit() == .ok);
const allocator = gpa.allocator();

const args = parseArgs(allocator, init.args) catch |err| switch (err) {
Expand Down
Loading
Loading