Skip to documentation
SLOP

tiny.zen.QuizStorage

Reference tiny.zen QuizStorage

Defined in tiny.zen.

API (26)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

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

Source

Source: lib/zen/src/quiz/storage.zig:30

zig
pub const Storage = struct {    phase: alloc_phase.capacity.Phase,    capacity: capacity_mod.Capacity,    bytes: []align(capacity_mod.storage_alignment) u8,    questions: []model.Question,    options: []model.Option,    joined_text: []u8,    in_use: bool = false,    question_count: usize = 0,    option_count: usize = 0,    joined_text_bytes: usize = 0,    high_water_questions: usize = 0,    high_water_options: usize = 0,    high_water_joined_text_bytes: usize = 0,    rejected_source_count: u64 = 0,    pub const Limits: type = capacity_mod.Limits;    pub const Capacity: type = capacity_mod.Capacity;    pub const Exhaustion: type = model.Exhaustion;    pub const InitError = std.mem.Allocator.Error || capacity_mod.DeriveError;    pub const AcquireError: type = model.Error;    pub const claim: alloc_phase.capacity.Declaration = .{        .source = .{            .id = "zen.quiz_storage",            .kind = .phase_static,            .limit_source = .caller,            .storage = .{                .covered = &.{                    .{                        .id = "quiz_question_descriptors",                        .lifetime = .steady,                        .detail = "quiz question descriptors",                    },                    .{                        .id = "quiz_option_descriptors",                        .lifetime = .steady,                        .detail = "quiz option descriptors",                    },                    .{                        .id = "normalized_continued_quiz_text",                        .lifetime = .steady,                        .detail = "normalized continued quiz text",                    },                },                .excluded = &.{                    "caller-owned quiz source and borrowed single-line text",                    "Markdown document, output, and inline-rendering owners",                    "site catalog, theme, and filesystem output owners",                },            },            .capacity = .{                .inputs = &.{                    alloc_phase.capacity.bindInput(Limits, "max_questions", "max_questions"),                    alloc_phase.capacity.bindInput(Limits, "max_options", "max_options"),                    alloc_phase.capacity.bindInput(Limits, "max_joined_text_bytes", "max_joined_text_bytes"),                },                .type_selectors = &.{                    alloc_phase.capacity.bindType(model.Question, "question"),                    alloc_phase.capacity.bindType(model.Option, "option"),                },                .nodes = &.{                    .{ .input = 0 },                    .{ .scale = .{ .node = 0, .coefficient = .{ .size_of_concrete_type = 0 } } },                    .{ .alignment = .{ .node = 1, .alignment = .{ .literal = 16 } } },                    .{ .input = 1 },                    .{ .scale = .{ .node = 3, .coefficient = .{ .size_of_concrete_type = 1 } } },                    .{ .alignment = .{ .node = 4, .alignment = .{ .literal = 16 } } },                    .{ .input = 2 },                    .{ .add = .{ .left = 2, .right = 5 } },                    .{ .add = .{ .left = 7, .right = 6 } },                },                .assertions = &.{.{                    .scope = .closure_total,                    .measure = .retained,                    .relation = .exact,                    .expression = 8,                }},            },            .overload = .{                .kind = .reject_before_mutation,                .detail = "invalid input and max plus one reject before the backing region or active result changes; only rejection telemetry advances",            },            .risks = .{                .transitive = .{                    .status = .witnessed,                    .detail = "scanning, planning, descriptor filling, and continuation joining use borrowed input and acquired slices only",                },                .foreign = .{                    .status = .excluded,                    .detail = "quiz parsing crosses no operating-system or foreign callback boundary",                },            },            .obligations = &.{                .{ .key = "zen_quiz_capacity", .role = .capacity_model },                .{ .key = "zen_quiz_acquisition", .role = .custom },                .{ .key = "zen_quiz_oom", .role = .custom },                .{ .key = "zen_quiz_boundaries", .role = .overload },                .{ .key = "zen_quiz_reuse", .role = .overload },                .{ .key = "zen_quiz_sealed", .role = .transitive_risk },                .{ .key = "zen_quiz_root", .role = .custom },                .{ .key = "zen_quiz_consumer", .role = .foreign_risk },            },        },        .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: std.mem.Allocator, limits: Limits) InitError!Storage {        const capacity = try Capacity.derive(limits);        const bytes = if (capacity.storage_bytes == 0)            @as([]align(capacity_mod.storage_alignment) u8, &.{})        else            try allocator.alignedAlloc(                u8,                .fromByteUnits(capacity_mod.storage_alignment),                capacity.storage_bytes,            );        return .{            .phase = .initialization,            .capacity = capacity,            .bytes = bytes,            .questions = typedSlice(                model.Question,                bytes,                capacity.questions_offset,                limits.max_questions,            ),            .options = typedSlice(                model.Option,                bytes,                capacity.options_offset,                limits.max_options,            ),            .joined_text = bytes[capacity.joined_text_offset..][0..limits.max_joined_text_bytes],        };    }    pub fn activate(self: *Storage) void {        std.debug.assert(self.phase == .initialization);        self.assertStorage();        self.phase = .steady;    }    pub fn acquire(self: *Storage, source: []const u8) AcquireError!Regions {        std.debug.assert(self.phase == .steady);        if (self.in_use) return error.QuizStorageInUse;        const plan = plan_mod.Plan.inspect(source, self.capacity.limits) catch |err| {            self.rejected_source_count +|= 1;            return err;        };        self.in_use = true;        self.question_count = plan.questions;        self.option_count = plan.options;        self.joined_text_bytes = plan.joined_text_bytes;        self.high_water_questions = @max(self.high_water_questions, plan.questions);        self.high_water_options = @max(self.high_water_options, plan.options);        self.high_water_joined_text_bytes = @max(            self.high_water_joined_text_bytes,            plan.joined_text_bytes,        );        self.assertStorage();        return .{            .plan = plan,            .questions = self.questions[0..plan.questions],            .options = self.options[0..plan.options],            .joined_text = self.joined_text[0..plan.joined_text_bytes],        };    }    pub fn reset(self: *Storage) void {        std.debug.assert(self.phase == .steady);        std.debug.assert(self.in_use);        self.in_use = false;        self.question_count = 0;        self.option_count = 0;        self.joined_text_bytes = 0;        self.assertStorage();    }    pub fn status(self: *const Storage) Status {        return .{            .phase = self.phase,            .in_use = self.in_use,            .storage_bytes = self.capacity.storage_bytes,            .max_questions = self.capacity.limits.max_questions,            .max_options = self.capacity.limits.max_options,            .max_joined_text_bytes = self.capacity.limits.max_joined_text_bytes,            .question_count = self.question_count,            .option_count = self.option_count,            .joined_text_bytes = self.joined_text_bytes,            .high_water_questions = self.high_water_questions,            .high_water_options = self.high_water_options,            .high_water_joined_text_bytes = self.high_water_joined_text_bytes,            .rejected_source_count = self.rejected_source_count,        };    }    pub fn deinit(self: *Storage, allocator: std.mem.Allocator) void {        std.debug.assert(self.phase != .teardown);        std.debug.assert(!self.in_use);        self.assertStorage();        self.phase = .teardown;        allocator.free(self.bytes);        self.bytes = &.{};        self.questions = &.{};        self.options = &.{};        self.joined_text = &.{};    }    fn assertStorage(self: *const Storage) void {        std.debug.assert(self.bytes.len == self.capacity.storage_bytes);        std.debug.assert(self.questions.len == self.capacity.limits.max_questions);        std.debug.assert(self.options.len == self.capacity.limits.max_options);        std.debug.assert(self.joined_text.len == self.capacity.limits.max_joined_text_bytes);        std.debug.assert(self.question_count <= self.questions.len);        std.debug.assert(self.option_count <= self.options.len);        std.debug.assert(self.joined_text_bytes <= self.joined_text.len);        std.debug.assert(self.high_water_questions <= self.questions.len);        std.debug.assert(self.high_water_options <= self.options.len);        std.debug.assert(self.high_water_joined_text_bytes <= self.joined_text.len);        if (!self.in_use) {            std.debug.assert(self.question_count == 0);            std.debug.assert(self.option_count == 0);            std.debug.assert(self.joined_text_bytes == 0);        }    }};

Source: lib/zen/src/root.zig:158

zig
/// Reusable caller-allocated storage for one parsed quiz.pub const QuizStorage = quiz.Storage;
Called byCallstest sourcelib.zen.src.quiz.storagetest: quiz storage acquires one exact...private sourcelib.zen.src.quiz.storage.StorageassertStorageQuizStorageacquire
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallstest sourcelib.zen.src.quiz.storagetest: quiz storage acquires one exact...private sourcelib.zen.src.quiz.storage.StorageassertStorageQuizStorageactivate
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.zen.src.quiz.storagecheckInitFailurestest sourcelib.zen.src.quiz.storagetest: quiz storage acquires one exact...private sourcelib.zen.src.quiz.storage.StorageassertStorageQuizStoragedeinit
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsprivate sourcelib.zen.src.quiz.storagecheckInitFailurestest sourcelib.zen.src.quiz.storagetest: quiz storage acquires one exact...private sourcelib.zen.src.quiz.storagetypedSliceQuizStorageinit
Static calls · unresolved targets: 2 · external targets: 1.
Called byCallstest sourcelib.zen.src.quiz.storagetest: quiz storage acquires one exact...private sourcelib.zen.src.quiz.storage.StorageassertStorageQuizStoragereset
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.zen.src.quiz.storagetest: quiz storage acquires one exact...QuizStoragestatus
Static calls · unresolved targets: 0 · external targets: 0.

Also reachable as

quiz.Storage.

Audit

Definitions13
Public names26
Members14
Version26.7.0
Revisiondaab053ee433