tiny.smg.context.model
Defined in context.
API (31)
Actions
Public operations.
Types and contracts
Public types and contracts.
BasisBuilderCoverageEntryExpansionInspection: Retained rows and storage decoding use caller-backed dynamic_unbounded allocation.LimitsOmissionsOptionsReportSectionStateTargetTargetStateWork
Values and defaults
Public values and defaults.
entries_maxinput_bytes_maxoutput_bytes_maxrow_bytes_maxrows_maxschemasource_bytes_maxtargets_maxwal_bytes_max
Source
Source: tools/smg/src/context/model.zig
zig
const std = @import("std");const sys = @import("sys");pub const schema = "tiny.smg.context/v1";pub const targets_max = 8;pub const entries_max = 32;pub const rows_max = 256;pub const input_bytes_max = 8192;pub const row_bytes_max = 64 * 1024;pub const output_bytes_max = 64 * 1024;pub const source_bytes_max = 4 * 1024 * 1024;pub const wal_bytes_max = 8 * 1024 * 1024;pub const Limits = struct { entries: u8 = entries_max, rows: u16 = rows_max, depth: u8 = 2, source_bytes: u32 = source_bytes_max,};pub const Options = struct { limits: Limits = .{}, bytes: u32 = output_bytes_max, deadline_ms: u16 = 1000,};pub const State = enum { ready, absent, stale, unavailable, incompatible, budget_exhausted };pub const TargetState = enum { resolved, missing, ambiguous, unsupported, unqueried };pub const Basis = enum { verified_span, stale, unavailable, unverified, oversized };pub const Section = enum { target, owner, usages, impact, tests, dependencies };pub const Target = struct { input: []const u8, state: TargetState = .unqueried, name: ?[]const u8 = null, candidates: []const []const u8 = &.{},};pub const Entry = struct { target: []const u8, section: Section, relation: []const u8, name: []const u8, path: ?[]const u8, line: ?i64, source_span: ?@import("../root.zig").api.SourceSpan = null, source_sha256: ?[]const u8 = null, basis: Basis = .unverified,};pub const Coverage = struct { scope: []const u8 = "syntactic-neighborhood", source_scope: []const u8 = "declaration-spans", graph_sources_verified: bool = false, traversal_complete: bool = true, requested: u8 = 0, resolved: u8 = 0, missing: u8 = 0, ambiguous: u8 = 0, unsupported: u8 = 0, verified_spans: u8 = 0, unverified_spans: u8 = 0, source_bytes: u32 = 0,};pub const Work = struct { index_steps: u16 = 0, visited_index_rows: u16 = 0, visited_edges: u16 = 0, loaded_nodes: u16 = 0, depth_reached: u8 = 0,};pub const Omissions = struct { entries: u16 = 0, targets: u8 = 0, exact: bool = true, rows: bool = false, depth: bool = false, deadline: bool = false, source: bool = false, output: bool = false,};pub const Expansion = struct { cwd: []const u8, argv: []const []const u8 };pub const Report = struct { schema: []const u8 = model_schema, state: State = .ready, graph_head: ?[]const u8 = null, parser_identity: ?[]const u8 = null, project_identity: ?[]const u8 = null, limits: Limits = .{}, deadline_ms: u16 = 1000, work: Work = .{}, coverage: Coverage = .{}, targets: []const Target = &.{}, entries: []const Entry = &.{}, omissions: Omissions = .{}, problems: []const []const u8 = &.{}, expand: Expansion,};const model_schema = schema;/// Retained rows and storage decoding use caller-backed dynamic_unbounded allocation./// Fixed record counts and source byte limits bound work, not allocator overhead.pub const Inspection = struct { arena: std.heap.ArenaAllocator, result: Report, pub fn deinit(self: *Inspection) void { self.arena.deinit(); self.* = undefined; }};pub const Builder = struct { allocator: std.mem.Allocator, root: []const u8, options: Options, deadline_ns: i128, report: Report, targets: [targets_max]Target = undefined, target_count: u8 = 0, entries: [entries_max]Entry = undefined, entry_count: u8 = 0, pub fn active(self: *Builder) bool { std.debug.assert(self.target_count <= targets_max); std.debug.assert(self.entry_count <= self.options.limits.entries); if (sys.time.nanoTimestamp() < self.deadline_ns) return true; self.report.omissions.deadline = true; self.exhausted(); return false; } pub fn row(self: *Builder) bool { const work = self.report.work; std.debug.assert(work.visited_edges <= work.visited_index_rows); std.debug.assert(work.visited_index_rows <= work.index_steps); if (!self.active()) return false; if (self.report.work.index_steps == self.options.limits.rows) { self.report.omissions.rows = true; self.exhausted(); return false; } self.report.work.index_steps += 1; std.debug.assert(self.report.work.index_steps <= self.options.limits.rows); return true; } pub fn exhausted(self: *Builder) void { std.debug.assert(self.report.work.index_steps <= self.options.limits.rows); std.debug.assert(self.report.coverage.source_bytes <= self.options.limits.source_bytes); self.report.state = .budget_exhausted; self.report.coverage.traversal_complete = false; self.report.omissions.exact = false; } pub fn add(self: *Builder, entry: Entry) bool { std.debug.assert(self.entry_count <= self.options.limits.entries); for (self.entries[0..self.entry_count]) |existing| { if (existing.section == entry.section and std.mem.eql(u8, existing.target, entry.target) and std.mem.eql(u8, existing.name, entry.name)) return false; } if (self.entry_count == self.options.limits.entries) { self.report.omissions.entries +|= 1; self.exhausted(); return false; } std.debug.assert(entry.name.len != 0); std.debug.assert(entry.target.len != 0); self.entries[self.entry_count] = entry; self.entry_count += 1; return true; } pub fn finish(self: *Builder) !Report { std.debug.assert(self.target_count <= targets_max); std.debug.assert(self.entry_count <= entries_max); std.debug.assert(self.report.work.loaded_nodes <= self.report.work.visited_index_rows); std.debug.assert(self.report.work.depth_reached <= self.options.limits.depth); self.report.targets = try self.allocator.dupe(Target, self.targets[0..self.target_count]); self.report.entries = try self.allocator.dupe(Entry, self.entries[0..self.entry_count]); return self.report; }};pub fn validate(root: []const u8, targets: []const []const u8, options: Options) !void { if (!std.fs.path.isAbsolute(root)) return error.InvalidInspectionRoot; if (targets.len == 0 or targets.len > targets_max) return error.InvalidInspectionTargets; if (options.bytes < 1024 or options.bytes > output_bytes_max) { return error.InvalidInspectionLimit; } if (options.deadline_ms > 1000) return error.InvalidInspectionLimit; const limits = options.limits; if (limits.entries == 0 or limits.entries > entries_max) return error.InvalidInspectionLimit; if (limits.rows == 0 or limits.rows > rows_max) return error.InvalidInspectionLimit; if (limits.depth > 2 or limits.source_bytes > source_bytes_max) { return error.InvalidInspectionLimit; } var bytes: usize = root.len; try validText(root); for (targets) |target| { try validText(target); bytes += target.len; if (bytes > input_bytes_max) return error.InvalidInspectionTargets; }}fn validText(text: []const u8) !void { if (text.len == 0 or !std.unicode.utf8ValidateSlice(text)) { return error.InvalidInspectionTargets; } for (text) |byte| if (byte < 32 or byte == 127) return error.InvalidInspectionTargets;}Source: tools/smg/src/context/root.zig:6
zig
pub const model = @import("model.zig");Audit
| Definitions | 32 |
|---|---|
| Public names | 35 |
| Members | 94 |
| Version | 26.7.0 |
| Revision | daab053ee433 |