Skip to documentation
SLOP

tiny.zen.AsciiRenderStorage

Reference tiny.zen AsciiRenderStorage

Defined in tiny.zen.

One reusable aligned region for ASCII render scratch and output.

API (29)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

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

Source

Source: lib/zen/src/diagram/ascii/storage.zig:45

zig
/// One reusable aligned region for ASCII render scratch and output.////// Call `init`, then `activate`. Output 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,    categories: [][]const u8,    stack_totals: []diagram.bounds.StackTotal,    canvas: []u8,    output: []u8,    in_use: bool = false,    category_count: usize = 0,    stack_total_count: usize = 0,    canvas_bytes: usize = 0,    output_bytes: usize = 0,    high_water_categories: usize = 0,    high_water_stack_totals: usize = 0,    high_water_canvas_bytes: usize = 0,    high_water_output_bytes: usize = 0,    rejected_render_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.ascii_render_storage",            .kind = .phase_static,            .limit_source = .caller,            .storage = .{                .covered = &.{                    .{                        .id = "borrowed_categorical_bound_slots",                        .lifetime = .steady,                        .detail = "borrowed categorical bound slots",                    },                    .{                        .id = "stacked_category_bound_totals",                        .lifetime = .steady,                        .detail = "stacked-category bound totals",                    },                    .{                        .id = "ascii_canvas_bytes",                        .lifetime = .steady,                        .detail = "ASCII canvas bytes",                    },                    .{                        .id = "compacted_ascii_output_bytes",                        .lifetime = .steady,                        .detail = "compacted ASCII output bytes",                    },                },                .excluded = &.{                    "caller-owned parsed diagram Document and retained strings",                    "JSON line scratch, Document parsing, Markdown output, and filesystem owners",                },            },            .capacity = .{                .inputs = &.{                    alloc_phase.capacity.bindInput(Limits, "max_categories", "max_categories"),                    alloc_phase.capacity.bindInput(Limits, "max_stack_totals", "max_stack_totals"),                    alloc_phase.capacity.bindInput(Limits, "max_canvas_bytes", "max_canvas_bytes"),                    alloc_phase.capacity.bindInput(Limits, "max_output_bytes", "max_output_bytes"),                },                .type_selectors = &.{                    alloc_phase.capacity.bindType([]const u8, "const_u8"),                    alloc_phase.capacity.bindType(diagram.bounds.StackTotal, "stacktotal"),                },                .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 } } },                    .{ .input = 2 },                    .{ .input = 3 },                    .{ .add = .{ .left = 2, .right = 4 } },                    .{ .add = .{ .left = 7, .right = 5 } },                    .{ .add = .{ .left = 8, .right = 6 } },                },                .assertions = &.{.{                    .scope = .closure_total,                    .measure = .retained,                    .relation = .exact,                    .expression = 9,                }},            },            .overload = .{                .kind = .reject_before_mutation,                .detail = "every max plus one plan and in-use acquisition reject before backing bytes or the active result change; only rejection telemetry advances",            },            .risks = .{                .transitive = .{                    .status = .witnessed,                    .detail = "bounds derivation, categorical lookup, canvas drawing, and row compaction use borrowed Document values and acquired slices only",                },                .foreign = .{                    .status = .excluded,                    .detail = "parsed-document ASCII rendering crosses no operating-system or foreign callback boundary",                },            },            .obligations = &.{                .{ .key = "zen_ascii_render_capacity", .role = .capacity_model },                .{ .key = "zen_ascii_render_acquisition", .role = .custom },                .{ .key = "zen_ascii_render_oom", .role = .custom },                .{ .key = "zen_ascii_render_boundaries", .role = .overload },                .{ .key = "zen_ascii_render_reuse", .role = .overload },                .{ .key = "zen_ascii_render_sealed", .role = .transitive_risk },                .{ .key = "zen_ascii_render_root", .role = .custom },                .{ .key = "zen_ascii_render_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,            .categories = typedSlice(                []const u8,                bytes,                capacity.categories_offset,                limits.max_categories,            ),            .stack_totals = typedSlice(                diagram.bounds.StackTotal,                bytes,                capacity.stack_totals_offset,                limits.max_stack_totals,            ),            .canvas = bytes[capacity.canvas_offset..][0..limits.max_canvas_bytes],            .output = bytes[capacity.output_offset..][0..limits.max_output_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.AsciiRenderStorageInUse);        plan.require(self.capacity.limits) catch |err| return self.reject(err);        self.in_use = true;        self.category_count = plan.categories;        self.stack_total_count = plan.stack_totals;        self.canvas_bytes = plan.canvas_bytes;        self.output_bytes = plan.output_bytes;        self.high_water_categories = @max(self.high_water_categories, plan.categories);        self.high_water_stack_totals = @max(self.high_water_stack_totals, plan.stack_totals);        self.high_water_canvas_bytes = @max(self.high_water_canvas_bytes, plan.canvas_bytes);        self.high_water_output_bytes = @max(self.high_water_output_bytes, plan.output_bytes);        self.assertStorage();        return .{            .plan = plan,            .categories = self.categories[0..plan.categories],            .stack_totals = self.stack_totals[0..plan.stack_totals],            .canvas = self.canvas[0..plan.canvas_bytes],            .output = self.output[0..plan.output_bytes],        };    }    /// Ends the active output borrow so the same region can render again.    pub fn reset(self: *Storage) void {        std.debug.assert(self.phase == .steady);        std.debug.assert(self.in_use);        self.in_use = false;        self.category_count = 0;        self.stack_total_count = 0;        self.canvas_bytes = 0;        self.output_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_categories = self.capacity.limits.max_categories,            .max_stack_totals = self.capacity.limits.max_stack_totals,            .max_canvas_bytes = self.capacity.limits.max_canvas_bytes,            .max_output_bytes = self.capacity.limits.max_output_bytes,            .categories = self.category_count,            .stack_totals = self.stack_total_count,            .canvas_bytes = self.canvas_bytes,            .output_bytes = self.output_bytes,            .high_water_categories = self.high_water_categories,            .high_water_stack_totals = self.high_water_stack_totals,            .high_water_canvas_bytes = self.high_water_canvas_bytes,            .high_water_output_bytes = self.high_water_output_bytes,            .rejected_render_count = self.rejected_render_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.categories = &.{};        self.stack_totals = &.{};        self.canvas = &.{};        self.output = &.{};    }    fn reject(self: *Storage, err: model.Exhaustion) model.Exhaustion {        self.rejected_render_count +|= 1;        return err;    }    fn assertStorage(self: *const Storage) void {        std.debug.assert(self.bytes.len == self.capacity.storage_bytes);        std.debug.assert(self.categories.len == self.capacity.limits.max_categories);        std.debug.assert(self.stack_totals.len == self.capacity.limits.max_stack_totals);        std.debug.assert(self.canvas.len == self.capacity.limits.max_canvas_bytes);        std.debug.assert(self.output.len == self.capacity.limits.max_output_bytes);        std.debug.assert(self.category_count <= self.categories.len);        std.debug.assert(self.stack_total_count <= self.stack_totals.len);        std.debug.assert(self.canvas_bytes <= self.canvas.len);        std.debug.assert(self.output_bytes <= self.output.len);        std.debug.assert(self.high_water_categories <= self.categories.len);        std.debug.assert(self.high_water_stack_totals <= self.stack_totals.len);        std.debug.assert(self.high_water_canvas_bytes <= self.canvas.len);        std.debug.assert(self.high_water_output_bytes <= self.output.len);        if (!self.in_use) {            std.debug.assert(self.category_count == 0);            std.debug.assert(self.stack_total_count == 0);            std.debug.assert(self.canvas_bytes == 0);            std.debug.assert(self.output_bytes == 0);        }    }};

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

zig
/// Reusable caller-allocated storage for bounded ASCII rendering.pub const AsciiRenderStorage = diagram.AsciiRenderStorage;
Called byCallstest sourcelib.zen.src.diagram.ascii.storagetest: ASCII render storage acquires o...private sourcelib.zen.src.diagram.ascii.storage.StorageassertStorageprivate sourcelib.zen.src.diagram.ascii.storage.StoragerejectAsciiRenderStorageacquire
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallstest sourcelib.zen.src.diagram.ascii.storagetest: ASCII render storage acquires o...private sourcelib.zen.src.diagram.ascii.storage.StorageassertStorageAsciiRenderStorageactivate
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.zen.src.diagram.ascii.storagecheckInitFailurestest sourcelib.zen.src.diagram.ascii.storagetest: ASCII render storage acquires o...private sourcelib.zen.src.diagram.ascii.storage.StorageassertStorageAsciiRenderStoragedeinit
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsprivate sourcelib.zen.src.diagram.ascii.storagecheckInitFailurestest sourcelib.zen.src.diagram.ascii.storagetest: ASCII render storage acquires o...private sourcelib.zen.src.diagram.ascii.storagetypedSliceAsciiRenderStorageinit
Static calls · unresolved targets: 2 · external targets: 1.
Called byCallstest sourcelib.zen.src.diagram.ascii.storagetest: ASCII render storage acquires o...private sourcelib.zen.src.diagram.ascii.storage.StorageassertStorageAsciiRenderStoragereset
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.zen.src.diagram.ascii.storagetest: ASCII render storage acquires o...AsciiRenderStoragestatus
Static calls · unresolved targets: 0 · external targets: 0.

Also reachable as

diagram.AsciiRenderStorage, diagram.ascii.RenderStorage.

Audit

Definitions13
Public names39
Members17
Version26.7.0
Revisiondaab053ee433