tiny.hypothesis.ReplayCursor
Defined in database.
API (18)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/hypothesis/src/database.zig:86
zig
pub const ReplayCursor = struct { phase: alloc_phase.capacity.Phase, capacity: ReplayCapacity, dir: ?std.Io.Dir, names: []FailureName, encoded: []u8, choices: []ChoiceNode, name_count: usize = 0, next_name: usize = 0, status_value: ReplayStatus = .{}, pub const Limits: type = ReplayLimits; pub const Capacity: type = ReplayCapacity; pub const Status: type = ReplayStatus; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "hypothesis.replay_cursor", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "bounded_sorted_content_address_candidate_names", .lifetime = .steady, .detail = "bounded sorted content-address candidate names", }, .{ .id = "maximum_admitted_canonical_failure_bytes", .lifetime = .steady, .detail = "maximum admitted canonical failure bytes", }, .{ .id = "maximum_admitted_decoded_choice_nodes", .lifetime = .steady, .detail = "maximum admitted decoded choice nodes", }, }, .excluded = &.{ "caller-owned database path, namespace, replay context, and captured result", "directory and file handles plus operating-system directory and file caches", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "db_path", "db_path"), alloc_phase.capacity.bindInput(Limits, "max_byte_blocks", "max_byte_blocks"), alloc_phase.capacity.bindInput(Limits, "max_choices", "max_choices"), alloc_phase.capacity.bindInput(Limits, "max_entries", "max_entries"), }, .type_selectors = &.{}, .nodes = &.{ .{ .collection = .{ .length = 0 } }, .{ .input = 1 }, .{ .input = 2 }, .{ .input = 3 }, .{ .add = .{ .left = 0, .right = 1 } }, .{ .add = .{ .left = 4, .right = 2 } }, .{ .add = .{ .left = 5, .right = 3 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .upper_bound, .expression = 6, }}, }, .overload = .{ .kind = .not_applicable, .detail = "scan and record limits define the domain; rejected records do not exhaust storage", }, .risks = .{ .transitive = .{ .status = .open, .detail = "directory, file, sort, and SHA callees lack an allocation-closure certificate", }, .foreign = .{ .status = .excluded, .detail = "filesystem handles and caches are excluded; sealed replay observes caller allocation", }, }, .obligations = &.{ .{ .key = "hypothesis_replay_capacity", .role = .capacity_model }, .{ .key = "hypothesis_replay_sealed", .role = .foreign_risk }, .{ .key = "hypothesis_replay_oom_retry", .role = .custom }, }, }, .bindings = .{ .owner = @This(), .seal = .{ .family = alloc_phase.capacity.selector(@This().activate), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, .teardown = .{ .family = alloc_phase.capacity.selector(@This().deinit), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, }, }; pub fn init( allocator: Allocator, limits: Limits, ) !ReplayCursor { const capacity = try Capacity.derive(limits); var cursor = ReplayCursor{ .phase = .initialization, .capacity = capacity, .dir = null, .names = &.{}, .encoded = &.{}, .choices = &.{}, }; errdefer cursor.release(allocator); if (capacity.entries == 0) return cursor; cursor.dir = openNamespaceDir(limits.db_path, limits.namespace) catch |err| switch (err) { error.FileNotFound => return cursor, else => return err, }; cursor.names = try allocator.alloc(FailureName, capacity.entries); cursor.encoded = try allocator.alloc(u8, capacity.encoded_bytes); if (capacity.choices > 0) { cursor.choices = try allocator.alloc(ChoiceNode, capacity.choices); } try cursor.scanNames(); return cursor; } pub fn activate(self: *ReplayCursor) void { assert(self.phase == .initialization); assert(self.name_count <= self.capacity.entries); assert(self.next_name == 0); self.phase = .steady; } pub fn next(self: *ReplayCursor) !?FailureEntry { assert(self.phase == .steady); assert(self.next_name <= self.name_count); while (self.next_name < self.name_count) { const name = self.names[self.next_name]; self.next_name += 1; const failure = self.loadFailure(&name) catch |err| switch (err) { error.FileNotFound => null, else => return err, }; if (failure) |entry| { self.status_value.failures_loaded += 1; assert(self.status_value.failures_loaded <= self.name_count); return entry; } self.status_value.failures_rejected += 1; assert(self.status_value.failures_rejected <= self.name_count); } return null; } pub fn status(self: *const ReplayCursor) Status { assert(self.phase == .steady); return self.status_value; } pub fn deinit(self: *ReplayCursor, allocator: Allocator) void { assert(self.phase != .teardown); self.phase = .teardown; self.release(allocator); self.* = undefined; } fn scanNames(self: *ReplayCursor) !void { assert(self.phase == .initialization); var iterator = self.dir.?.iterate(); while (self.status_value.entries_scanned < self.capacity.entries) { const entry = try iterator.next(std.Options.debug_io) orelse break; self.status_value.entries_scanned += 1; if (entry.kind != .file) continue; if (!isFailureName(entry.name)) continue; @memcpy(self.names[self.name_count][0..], entry.name); self.name_count += 1; } self.status_value.scan_budget_saturated = self.status_value.entries_scanned == self.capacity.entries; self.status_value.candidate_files = self.name_count; std.mem.sort(FailureName, self.names[0..self.name_count], {}, nameLessThan); } fn loadFailure(self: *ReplayCursor, name: *const FailureName) !?FailureEntry { assert(self.phase == .steady); var file = try self.dir.?.openFile(std.Options.debug_io, name, .{ .allow_directory = false, }); defer file.close(std.Options.debug_io); const stat = try file.stat(std.Options.debug_io); if (stat.kind != .file) return null; const file_len = std.math.cast(usize, stat.size) orelse return null; if (file_len > self.encoded.len) return null; const data = self.encoded[0..file_len]; if (try file.readPositionalAll(std.Options.debug_io, data, 0) != file_len) { return null; } var trailing: [1]u8 = undefined; if (try file.readPositionalAll(std.Options.debug_io, &trailing, file_len) != 0) { return null; } if (!failureNameMatches(name, data)) return null; return deserializeFailureInto( self.choices, self.capacity.byte_blocks, data, ) catch |err| switch (err) { error.InvalidFormat, error.UnsupportedVersion, error.CapacityExceeded => null, }; } fn release(self: *ReplayCursor, allocator: Allocator) void { if (self.choices.len > 0) allocator.free(self.choices); if (self.encoded.len > 0) allocator.free(self.encoded); if (self.names.len > 0) allocator.free(self.names); if (self.dir) |dir| dir.close(std.Options.debug_io); }};Source: lib/hypothesis/src/root.zig:85
zig
pub const ReplayCursor = @import("database.zig").ReplayCursor;Complete caller list for ReplayCursor.activate
10 direct callers.
lib.hypothesis.src.database.checkReplayCursorAllocationFailures[function] — private source atlib/hypothesis/src/database.zig:567in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_fuzz:_complete_failure_identity_preserves_distinct_replay_inputs[function] — test source atlib/hypothesis/src/database.zig:769in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_fuzz:_load_rejects_a_valid_payload_under_the_wrong_content_address[function] — test source atlib/hypothesis/src/database.zig:814in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_accepts_exact_failure_capacity_and_rejects_max_plus_one[function] — test source atlib/hypothesis/src/database.zig:909in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_admits_at_most_the_requested_directory_prefix[function] — test source atlib/hypothesis/src/database.zig:878in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_keeps_pointers_stable_with_zero_steady_allocator_operations[function] — test source atlib/hypothesis/src/database.zig:935in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_save_and_load_failure[function] — test source atlib/hypothesis/src/database.zig:740in nearest public ownertiny.hypothesis.databasetiny.hypothesis.engine.runWithContextSeeded[function] atlib/hypothesis/src/engine.zig:177lib.hypothesis.src.properties.database.CursorModelProperty.property[function] — private source atlib/hypothesis/src/properties/database.zig:24in nearest public ownerlib.hypothesis.src.properties.databaselib.hypothesis.src.properties.database.ScanBudgetProperty.property[function] — private source atlib/hypothesis/src/properties/database.zig:70in nearest public ownerlib.hypothesis.src.properties.database
Complete caller list for ReplayCursor.deinit
10 direct callers.
lib.hypothesis.src.database.checkReplayCursorAllocationFailures[function] — private source atlib/hypothesis/src/database.zig:567in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_fuzz:_complete_failure_identity_preserves_distinct_replay_inputs[function] — test source atlib/hypothesis/src/database.zig:769in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_fuzz:_load_rejects_a_valid_payload_under_the_wrong_content_address[function] — test source atlib/hypothesis/src/database.zig:814in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_accepts_exact_failure_capacity_and_rejects_max_plus_one[function] — test source atlib/hypothesis/src/database.zig:909in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_admits_at_most_the_requested_directory_prefix[function] — test source atlib/hypothesis/src/database.zig:878in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_keeps_pointers_stable_with_zero_steady_allocator_operations[function] — test source atlib/hypothesis/src/database.zig:935in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_save_and_load_failure[function] — test source atlib/hypothesis/src/database.zig:740in nearest public ownertiny.hypothesis.databasetiny.hypothesis.engine.runWithContextSeeded[function] atlib/hypothesis/src/engine.zig:177lib.hypothesis.src.properties.database.CursorModelProperty.property[function] — private source atlib/hypothesis/src/properties/database.zig:24in nearest public ownerlib.hypothesis.src.properties.databaselib.hypothesis.src.properties.database.ScanBudgetProperty.property[function] — private source atlib/hypothesis/src/properties/database.zig:70in nearest public ownerlib.hypothesis.src.properties.database
Complete caller list for ReplayCursor.init
10 direct callers.
lib.hypothesis.src.database.checkReplayCursorAllocationFailures[function] — private source atlib/hypothesis/src/database.zig:567in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_fuzz:_complete_failure_identity_preserves_distinct_replay_inputs[function] — test source atlib/hypothesis/src/database.zig:769in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_fuzz:_load_rejects_a_valid_payload_under_the_wrong_content_address[function] — test source atlib/hypothesis/src/database.zig:814in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_accepts_exact_failure_capacity_and_rejects_max_plus_one[function] — test source atlib/hypothesis/src/database.zig:909in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_admits_at_most_the_requested_directory_prefix[function] — test source atlib/hypothesis/src/database.zig:878in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_keeps_pointers_stable_with_zero_steady_allocator_operations[function] — test source atlib/hypothesis/src/database.zig:935in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_save_and_load_failure[function] — test source atlib/hypothesis/src/database.zig:740in nearest public ownertiny.hypothesis.databasetiny.hypothesis.engine.runWithContextSeeded[function] atlib/hypothesis/src/engine.zig:177lib.hypothesis.src.properties.database.CursorModelProperty.property[function] — private source atlib/hypothesis/src/properties/database.zig:24in nearest public ownerlib.hypothesis.src.properties.databaselib.hypothesis.src.properties.database.ScanBudgetProperty.property[function] — private source atlib/hypothesis/src/properties/database.zig:70in nearest public ownerlib.hypothesis.src.properties.database
Complete caller list for ReplayCursor.next
10 direct callers.
lib.hypothesis.src.database.checkReplayCursorAllocationFailures[function] — private source atlib/hypothesis/src/database.zig:567in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_fuzz:_complete_failure_identity_preserves_distinct_replay_inputs[function] — test source atlib/hypothesis/src/database.zig:769in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_fuzz:_load_rejects_a_valid_payload_under_the_wrong_content_address[function] — test source atlib/hypothesis/src/database.zig:814in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_accepts_exact_failure_capacity_and_rejects_max_plus_one[function] — test source atlib/hypothesis/src/database.zig:909in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_admits_at_most_the_requested_directory_prefix[function] — test source atlib/hypothesis/src/database.zig:878in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_replay_cursor_keeps_pointers_stable_with_zero_steady_allocator_operations[function] — test source atlib/hypothesis/src/database.zig:935in nearest public ownertiny.hypothesis.databaselib.hypothesis.src.database.test_save_and_load_failure[function] — test source atlib/hypothesis/src/database.zig:740in nearest public ownertiny.hypothesis.databasetiny.hypothesis.engine.runWithContextSeeded[function] atlib/hypothesis/src/engine.zig:177lib.hypothesis.src.properties.database.CursorModelProperty.property[function] — private source atlib/hypothesis/src/properties/database.zig:24in nearest public ownerlib.hypothesis.src.properties.databaselib.hypothesis.src.properties.database.ScanBudgetProperty.property[function] — private source atlib/hypothesis/src/properties/database.zig:70in nearest public ownerlib.hypothesis.src.properties.database
Audit
| Definitions | 10 |
|---|---|
| Public names | 20 |
| Members | 9 |
| Version | 26.7.0 |
| Revision | daab053ee433 |