tiny.zen.FootnoteStorage
Defined in tiny.zen.
API (23)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
bytescapacitydefinition_countdefinitionshigh_water_definitionshigh_water_joined_text_bytesin_usejoined_textjoined_text_bytesphaserejected_source_count
Source
Source: lib/zen/src/footnote/storage.zig:26
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, bytes: []align(capacity_mod.storage_alignment) u8, definitions: []model.Definition, joined_text: []u8, in_use: bool = false, definition_count: usize = 0, joined_text_bytes: usize = 0, high_water_definitions: 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.footnote_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "footnote_definition_descriptors", .lifetime = .steady, .detail = "footnote definition descriptors", }, .{ .id = "joined_footnote_continuation_text", .lifetime = .steady, .detail = "joined footnote continuation text", }, }, .excluded = &.{ "caller-owned Markdown source and borrowed keys or single-line text", "rendered HTML and inline-rendering owners", "heading, quiz, site, theme, and filesystem owners", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "max_definitions", "max_definitions"), alloc_phase.capacity.bindInput(Limits, "max_joined_text_bytes", "max_joined_text_bytes"), }, .type_selectors = &.{ alloc_phase.capacity.bindType(model.Definition, "definition"), }, .nodes = &.{ .{ .input = 0 }, .{ .scale = .{ .node = 0, .coefficient = .{ .size_of_concrete_type = 0 } } }, .{ .input = 1 }, .{ .add = .{ .left = 1, .right = 2 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 3, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "max plus one and in-use collection reject before the backing region or active result changes; only rejection telemetry advances", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "scanning, planning, descriptor filling, duplicate filtering, joining, lookup, and numbering use borrowed input and acquired slices only", }, .foreign = .{ .status = .excluded, .detail = "footnote collection crosses no operating-system or foreign callback boundary", }, }, .obligations = &.{ .{ .key = "zen_footnote_capacity", .role = .capacity_model }, .{ .key = "zen_footnote_acquisition", .role = .custom }, .{ .key = "zen_footnote_oom", .role = .custom }, .{ .key = "zen_footnote_boundaries", .role = .overload }, .{ .key = "zen_footnote_reuse", .role = .overload }, .{ .key = "zen_footnote_sealed", .role = .transitive_risk }, .{ .key = "zen_footnote_root", .role = .custom }, .{ .key = "zen_footnote_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, .definitions = typedSlice( model.Definition, bytes, capacity.definitions_offset, limits.max_definitions, ), .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 self.reject(error.FootnoteStorageInUse); const plan = plan_mod.Plan.inspect(source, self.capacity.limits) catch |err| { self.rejected_source_count +|= 1; return err; }; self.in_use = true; self.definition_count = plan.definitions; self.joined_text_bytes = plan.joined_text_bytes; self.high_water_definitions = @max(self.high_water_definitions, plan.definitions); self.high_water_joined_text_bytes = @max( self.high_water_joined_text_bytes, plan.joined_text_bytes, ); self.assertStorage(); return .{ .plan = plan, .definitions = self.definitions[0..plan.definitions], .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.definition_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_definitions = self.capacity.limits.max_definitions, .max_joined_text_bytes = self.capacity.limits.max_joined_text_bytes, .definition_count = self.definition_count, .joined_text_bytes = self.joined_text_bytes, .high_water_definitions = self.high_water_definitions, .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.definitions = &.{}; self.joined_text = &.{}; } fn reject(self: *Storage, err: model.Exhaustion) model.Exhaustion { self.rejected_source_count +|= 1; return err; } fn assertStorage(self: *const Storage) void { std.debug.assert(self.bytes.len == self.capacity.storage_bytes); std.debug.assert(self.definitions.len == self.capacity.limits.max_definitions); std.debug.assert(self.joined_text.len == self.capacity.limits.max_joined_text_bytes); std.debug.assert(self.definition_count <= self.definitions.len); std.debug.assert(self.joined_text_bytes <= self.joined_text.len); std.debug.assert(self.high_water_definitions <= self.definitions.len); std.debug.assert(self.high_water_joined_text_bytes <= self.joined_text.len); if (!self.in_use) { std.debug.assert(self.definition_count == 0); std.debug.assert(self.joined_text_bytes == 0); } }};Source: lib/zen/src/root.zig:129
zig
/// Reusable caller-allocated storage for one parsed footnote set.pub const FootnoteStorage = footnote.Storage;Also reachable as
Audit
| Definitions | 13 |
|---|---|
| Public names | 26 |
| Members | 11 |
| Version | 26.7.0 |
| Revision | daab053ee433 |