Skip to documentation
SLOP

tiny.hypothesis.ReplayCursor

Reference 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.

No direct callersNo direct callsdatabaseReplayCursor
Static calls · unresolved targets: unknown · external targets: unknown.

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;
Called byCallsNo direct callsprivate sourcelib.hypothesis.src.databasecheckReplayCursorAllocationFailurestest sourcelib.hypothesis.src.databasetest: fuzz: complete failure identity...test sourcelib.hypothesis.src.databasetest: fuzz: load rejects a valid payl...test sourcelib.hypothesis.src.databasetest: replay cursor accepts exact fai...test sourcelib.hypothesis.src.databasetest: replay cursor admits at most th...+5 moreReplayCursoractivate
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.hypothesis.src.databasecheckReplayCursorAllocationFailurestest sourcelib.hypothesis.src.databasetest: fuzz: complete failure identity...test sourcelib.hypothesis.src.databasetest: fuzz: load rejects a valid payl...test sourcelib.hypothesis.src.databasetest: replay cursor accepts exact fai...test sourcelib.hypothesis.src.databasetest: replay cursor admits at most th...+5 moreprivate sourcelib.hypothesis.src.database.ReplayCursorreleaseReplayCursordeinit
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.hypothesis.src.databasecheckReplayCursorAllocationFailurestest sourcelib.hypothesis.src.databasetest: fuzz: complete failure identity...test sourcelib.hypothesis.src.databasetest: fuzz: load rejects a valid payl...test sourcelib.hypothesis.src.databasetest: replay cursor accepts exact fai...test sourcelib.hypothesis.src.databasetest: replay cursor admits at most th...+5 moreprivate sourcelib.hypothesis.src.databaseopenNamespaceDirReplayCursorinit
Static calls · unresolved targets: 1 · external targets: 3.
Called byCallsprivate sourcelib.hypothesis.src.databasecheckReplayCursorAllocationFailurestest sourcelib.hypothesis.src.databasetest: fuzz: complete failure identity...test sourcelib.hypothesis.src.databasetest: fuzz: load rejects a valid payl...test sourcelib.hypothesis.src.databasetest: replay cursor accepts exact fai...test sourcelib.hypothesis.src.databasetest: replay cursor admits at most th...+5 moreprivate sourcelib.hypothesis.src.database.ReplayCursorloadFailureReplayCursornext
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.hypothesis.src.databasetest: fuzz: load rejects a valid payl...test sourcelib.hypothesis.src.databasetest: replay cursor accepts exact fai...test sourcelib.hypothesis.src.databasetest: replay cursor admits at most th...enginerunWithContextSeededprivate sourcelib.hypothesis.src.properties.database.Cursor...propertyprivate sourcelib.hypothesis.src.properties.database.ScanBu...propertyReplayCursorstatus
Static calls · unresolved targets: 0 · external targets: 0.

Complete caller list for ReplayCursor.activate

10 direct callers.

Complete caller list for ReplayCursor.deinit

10 direct callers.

Complete caller list for ReplayCursor.init

10 direct callers.

Complete caller list for ReplayCursor.next

10 direct callers.

Audit

Definitions10
Public names20
Members9
Version26.7.0
Revisiondaab053ee433