tiny.zen.HeadingStorage
Defined in tiny.zen.
One reusable aligned region for an inspected Markdown document.
API (26)
Actions
Public operations.
acquire: Acquires exact plan regions or rejects before backing bytes change.activatedeinitinitreset: Ends the active borrow so the same region can inspect another document.status: Returns current, high-water, and rejected demand without mutation.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
bytescapacityheading_countheadingshigh_water_headingshigh_water_id_byteshigh_water_text_bytesid_bytesidsin_usephaserejected_source_counttexttext_bytes
Source
Source: lib/zen/src/document/storage.zig:43
zig
/// One reusable aligned region for an inspected Markdown document.////// Call `init`, then `activate`. A document borrows the region until `reset`./// Call `deinit` with the allocator passed to `init` after the last reset.pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: capacity_mod.Capacity, bytes: []align(capacity_mod.storage_alignment) u8, headings: []model.Heading, text: []u8, ids: []u8, in_use: bool = false, heading_count: usize = 0, text_bytes: usize = 0, id_bytes: usize = 0, high_water_headings: usize = 0, high_water_text_bytes: usize = 0, high_water_id_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.Exhaustion; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "zen.heading_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "markdown_heading_descriptors", .lifetime = .steady, .detail = "Markdown heading descriptors", }, .{ .id = "source_independent_heading_text", .lifetime = .steady, .detail = "source-independent heading text", }, .{ .id = "stable_heading_identifiers", .lifetime = .steady, .detail = "stable heading identifiers", }, }, .excluded = &.{ "caller-owned Markdown source", "rendered HTML and inline-rendering owners", "site catalog, theme, and filesystem output owners", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(Limits, "max_headings", "max_headings"), alloc_phase.capacity.bindInput(Limits, "max_text_bytes", "max_text_bytes"), alloc_phase.capacity.bindInput(Limits, "max_id_bytes", "max_id_bytes"), }, .type_selectors = &.{ alloc_phase.capacity.bindType(model.Heading, "heading"), }, .nodes = &.{ .{ .input = 0 }, .{ .scale = .{ .node = 0, .coefficient = .{ .size_of_concrete_type = 0 } } }, .{ .input = 1 }, .{ .input = 2 }, .{ .add = .{ .left = 1, .right = 2 } }, .{ .add = .{ .left = 4, .right = 3 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 5, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "max plus one and in-use acquisition reject before the backing region or active result changes; only rejection telemetry advances", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "heading scanning, planning, copying, and identifier resolution use borrowed input and acquired slices only", }, .foreign = .{ .status = .excluded, .detail = "heading inspection crosses no operating-system or foreign callback boundary", }, }, .obligations = &.{ .{ .key = "zen_heading_capacity", .role = .capacity_model }, .{ .key = "zen_heading_acquisition", .role = .custom }, .{ .key = "zen_heading_oom", .role = .custom }, .{ .key = "zen_heading_boundaries", .role = .overload }, .{ .key = "zen_heading_reuse", .role = .overload }, .{ .key = "zen_heading_sealed", .role = .transitive_risk }, .{ .key = "zen_heading_root", .role = .custom }, .{ .key = "zen_heading_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, .headings = typedSlice( model.Heading, bytes, capacity.headings_offset, limits.max_headings, ), .text = bytes[capacity.text_offset..][0..limits.max_text_bytes], .ids = bytes[capacity.id_offset..][0..limits.max_id_bytes], }; } pub fn activate(self: *Storage) void { std.debug.assert(self.phase == .initialization); self.assertStorage(); self.phase = .steady; } /// Acquires exact plan regions or rejects before backing bytes change. pub fn acquire(self: *Storage, plan: plan_mod.Plan) AcquireError!Regions { std.debug.assert(self.phase == .steady); if (self.in_use) return self.reject(error.DocumentStorageInUse); plan.require(self.capacity.limits) catch |err| return self.reject(err); self.in_use = true; self.heading_count = plan.headings; self.text_bytes = plan.text_bytes; self.id_bytes = plan.id_bytes; self.high_water_headings = @max(self.high_water_headings, plan.headings); self.high_water_text_bytes = @max(self.high_water_text_bytes, plan.text_bytes); self.high_water_id_bytes = @max(self.high_water_id_bytes, plan.id_bytes); self.assertStorage(); return .{ .plan = plan, .headings = self.headings[0..plan.headings], .text = self.text[0..plan.text_bytes], .ids = self.ids[0..plan.id_bytes], }; } /// Ends the active borrow so the same region can inspect another document. pub fn reset(self: *Storage) void { std.debug.assert(self.phase == .steady); std.debug.assert(self.in_use); self.in_use = false; self.heading_count = 0; self.text_bytes = 0; self.id_bytes = 0; self.assertStorage(); } /// Returns current, high-water, and rejected demand without mutation. pub fn status(self: *const Storage) Status { return .{ .phase = self.phase, .in_use = self.in_use, .storage_bytes = self.capacity.storage_bytes, .max_headings = self.capacity.limits.max_headings, .max_text_bytes = self.capacity.limits.max_text_bytes, .max_id_bytes = self.capacity.limits.max_id_bytes, .heading_count = self.heading_count, .text_bytes = self.text_bytes, .id_bytes = self.id_bytes, .high_water_headings = self.high_water_headings, .high_water_text_bytes = self.high_water_text_bytes, .high_water_id_bytes = self.high_water_id_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.headings = &.{}; self.text = &.{}; self.ids = &.{}; } 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.headings.len == self.capacity.limits.max_headings); std.debug.assert(self.text.len == self.capacity.limits.max_text_bytes); std.debug.assert(self.ids.len == self.capacity.limits.max_id_bytes); std.debug.assert(self.heading_count <= self.headings.len); std.debug.assert(self.text_bytes <= self.text.len); std.debug.assert(self.id_bytes <= self.ids.len); std.debug.assert(self.high_water_headings <= self.headings.len); std.debug.assert(self.high_water_text_bytes <= self.text.len); std.debug.assert(self.high_water_id_bytes <= self.ids.len); if (!self.in_use) { std.debug.assert(self.heading_count == 0); std.debug.assert(self.text_bytes == 0); std.debug.assert(self.id_bytes == 0); } }};Source: lib/zen/src/root.zig:194
zig
/// Reusable caller-allocated storage for one inspected Markdown document.pub const HeadingStorage = document.Storage;Also reachable as
Audit
| Definitions | 13 |
|---|---|
| Public names | 26 |
| Members | 14 |
| Version | 26.7.0 |
| Revision | daab053ee433 |