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
18 changes: 14 additions & 4 deletions scripts/unused_pub_detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ for (const f of prod) {
let pm;
while ((pm = pubRe.exec(line)) !== null) {
const name = pm[2];
if (depth === 0 && name === "main" && pm[1] === "fn") continue;
if (depth === 0 && name === "std_options") continue;
if (scope.length === 0 && name === "main" && pm[1] === "fn") continue;
if (scope.length === 0 && name === "std_options") continue;
if (name === "Self") continue;

decls.push({
Expand Down Expand Up @@ -191,6 +191,12 @@ function hasWord(text, word) {
return false;
}

function escapeRegex(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); }

function hasMemberAccess(text, name) {
return new RegExp("\\.\\s*" + escapeRegex(name) + "\\b").test(text);
}

// ---- STRIPPED TEXT CACHE (precomputed per-file, reused for self+ref checks) ----
const strippedCache = new Map();
function getStripped(f) {
Expand Down Expand Up @@ -218,9 +224,13 @@ for (const d of decls) {
if (d.parent) {
const qn = d.parent + "." + d.name;
if (isSelf) {
if (hasWordOutsideLines(selfText, qn, [d.line])) { prodCount++; continue; }
if (hasWordOutsideLines(selfText, qn, [d.line])) prodCount++
else if (hasWord(selfText, d.parent) && hasWordOutsideLines(selfText, d.name, [d.line])) prodCount++;
} else {
if (hasWord(getStripped(f), qn)) {
const fText = getStripped(f);
if (hasWord(fText, qn)) {
if (fileType.get(fp) === "prod") prodCount++; else testCount++;
} else if (hasWord(fText, d.parent) && hasMemberAccess(fText, d.name)) {
if (fileType.get(fp) === "prod") prodCount++; else testCount++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/config_loader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const Config = struct {
authorization_file: ?[]const u8,
allocator: Allocator,

pub const ServerConfig = struct {
const ServerConfig = struct {
port: u16 = 3000,
host: []const u8 = "0.0.0.0",
};
Expand All @@ -34,7 +34,7 @@ pub const Config = struct {
anonymous_subject_prefix: []const u8,
session: SessionConfig = .{},

pub const SessionConfig = struct {
const SessionConfig = struct {
claims: std.StringHashMapUnmanaged([]const u8) = .{},
token_grace_period_seconds: u32 = 30,
};
Expand Down
4 changes: 0 additions & 4 deletions src/connection/state.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ pub const Outbox = struct {
}
}

pub fn isEmpty(self: Outbox) bool {
return self.tail == self.head;
}

pub fn isFull(self: Outbox) bool {
return (self.head + 1) % outbox_capacity == self.tail;
}
Expand Down
54 changes: 0 additions & 54 deletions src/lock_free_cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -341,55 +341,6 @@ pub fn lockFreeCache(comptime t: type, comptime KeyType: type) type { // zwanzig
}
}

/// Evict multiple entries from the cache in a single COW operation
pub fn bulkEvict(self: *Self, keys: []const KeyType) void {
if (keys.len == 0) return;
while (true) {
const epoch_slot = self.epoch_manager.enter();
defer self.epoch_manager.exit(epoch_slot);

const old_entries = self.entries.load(.acquire);

var any_exists = false;
for (keys) |key| {
if (old_entries.contains(key)) {
any_exists = true;
break;
}
}
if (!any_exists) return;

const new_entries = self.cloneEntries(old_entries) catch return;

var evicted_entries = std.ArrayListUnmanaged(*CacheEntry).initCapacity(self.allocator, keys.len) catch {
new_entries.deinit();
self.allocator.destroy(new_entries);
return;
};
defer evicted_entries.deinit(self.allocator);

for (keys) |key| {
if (new_entries.fetchRemove(key)) |kv| {
evicted_entries.appendAssumeCapacity(kv.value);
}
}

if (self.entries.cmpxchgStrong(old_entries, new_entries, .acq_rel, .acquire)) |actual| {
_ = actual;
new_entries.deinit();
self.allocator.destroy(new_entries);
continue;
} else {
for (evicted_entries.items) |e| {
self.internalDefer(.{ .entry = e });
}
self.internalDefer(.{ .map = old_entries });
_ = self.epoch_manager.bump();
return;
}
}
}

fn internalDefer(self: *Self, resource: Resource) void {
const node = self.pool.pop() orelse blk: {
self.reclaim(false);
Expand Down Expand Up @@ -432,11 +383,6 @@ pub fn lockFreeCache(comptime t: type, comptime KeyType: type) type { // zwanzig
}
}

pub fn size(self: *Self) usize {
const map = self.entries.load(.acquire);
return map.count();
}

pub fn reclaim(self: *Self, force: bool) void {
const min_epoch = if (force) std.math.maxInt(u64) else self.epoch_manager.minActiveEpoch();

Expand Down
2 changes: 1 addition & 1 deletion src/memory_strategy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const MemoryStrategy = struct {
arena_pool: PoolConfig = .{ .pre_allocate = 1024, .max_capacity = 1024 },
connection_pool: PoolConfig = .{ .pre_allocate = 0, .max_capacity = 100_000 },

pub const PoolConfig = struct {
const PoolConfig = struct {
pre_allocate: u32,
max_capacity: u32,
};
Expand Down
1 change: 0 additions & 1 deletion src/msgpack_utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const std = @import("std");
const msgpack = @import("msgpack");

pub const Payload = msgpack.Payload;
pub const Map = msgpack.Map;

/// Security-appropriate parse limits for WebSocket message handling.
/// These align with the ZyncBase Wire Protocol Specification.
Expand Down
6 changes: 0 additions & 6 deletions src/queues/spmc_blocking_queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ pub fn spmcBlockingQueue(comptime T: type) type {
self.cond.broadcast();
}

pub fn isEmpty(self: *Self) bool {
self.mutex.lock();
defer self.mutex.unlock();
return self.count == 0;
}

pub fn deinit(self: *Self) void {
self.mutex.lock();
defer self.mutex.unlock();
Expand Down
1 change: 0 additions & 1 deletion src/storage_engine.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub const AckLatch = write_queue.AckLatch;
const CheckpointStats = write_queue.CheckpointStats;
pub const write_queue_type = write_queue.write_queue_type;
pub const ReadRequest = read_buffer.ReadRequest;
pub const ReadResponse = read_buffer.ReadResponse;
const DocId = typed_doc_id.DocId;
const metadata_cache_type = storage_cache.metadata_cache_type;
const namespace_cache_type = storage_cache.namespace_cache_type;
Expand Down
11 changes: 7 additions & 4 deletions src/subscription/change_queue_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ test "ChangeQueue: multi-shard init and deinit" {
// Test various shard counts
for ([_]usize{ 1, 2, 4, 8, 16 }) |num_shards| {
var queue = try ChangeQueue.init(alloc, num_shards);
defer queue.deinit();
try testing.expectEqual(num_shards, queue.shardCount());

// Verify each shard is accessible
// Verify each shard is accessible and initially empty
for (0..num_shards) |i| {
const shard = queue.getShard(i);
try testing.expect(shard.isEmpty());
if (shard.popTimed(0)) |job| {
var mut_job = job;
mut_job.deinit(alloc);
try testing.expect(false);
}
}

queue.deinit();
}
}
2 changes: 0 additions & 2 deletions src/wire/encode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ const Keys = struct {
pub const fields = comptimeEncodeKey("fields");
pub const field_flags = comptimeEncodeKey("fieldFlags");
pub const write_id = comptimeEncodeKey("writeId");
pub const details = comptimeEncodeKey("details");
pub const phase = comptimeEncodeKey("phase");
pub const batch_index = comptimeEncodeKey("batchIndex");
pub const session = comptimeEncodeKey("session");
pub const token = comptimeEncodeKey("token");
pub const presence_user_fields = comptimeEncodeKey("presenceUserFields");
pub const presence_shared_fields = comptimeEncodeKey("presenceSharedFields");
pub const event = comptimeEncodeKey("event");
Expand Down
Loading