diff --git a/scripts/unused_pub_detector.js b/scripts/unused_pub_detector.js index cdf419f3..ea4ba465 100644 --- a/scripts/unused_pub_detector.js +++ b/scripts/unused_pub_detector.js @@ -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({ @@ -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) { @@ -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++; } } diff --git a/src/config_loader.zig b/src/config_loader.zig index 3201c3a6..2fd4d2c0 100644 --- a/src/config_loader.zig +++ b/src/config_loader.zig @@ -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", }; @@ -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, }; diff --git a/src/connection/state.zig b/src/connection/state.zig index bce7ad93..7e88653f 100644 --- a/src/connection/state.zig +++ b/src/connection/state.zig @@ -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; } diff --git a/src/lock_free_cache.zig b/src/lock_free_cache.zig index 4058d8ed..1e45f5f9 100644 --- a/src/lock_free_cache.zig +++ b/src/lock_free_cache.zig @@ -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); @@ -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(); diff --git a/src/memory_strategy.zig b/src/memory_strategy.zig index bb92958a..bb543843 100644 --- a/src/memory_strategy.zig +++ b/src/memory_strategy.zig @@ -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, }; diff --git a/src/msgpack_utils.zig b/src/msgpack_utils.zig index 5143bfe2..53747849 100644 --- a/src/msgpack_utils.zig +++ b/src/msgpack_utils.zig @@ -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. diff --git a/src/queues/spmc_blocking_queue.zig b/src/queues/spmc_blocking_queue.zig index e4b833f8..a81c045c 100644 --- a/src/queues/spmc_blocking_queue.zig +++ b/src/queues/spmc_blocking_queue.zig @@ -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(); diff --git a/src/storage_engine.zig b/src/storage_engine.zig index df8b12be..77725ee2 100644 --- a/src/storage_engine.zig +++ b/src/storage_engine.zig @@ -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; diff --git a/src/subscription/change_queue_test.zig b/src/subscription/change_queue_test.zig index a70ec3e4..13c0b940 100644 --- a/src/subscription/change_queue_test.zig +++ b/src/subscription/change_queue_test.zig @@ -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(); } } diff --git a/src/wire/encode.zig b/src/wire/encode.zig index 08b4706e..e4e30de4 100644 --- a/src/wire/encode.zig +++ b/src/wire/encode.zig @@ -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");