tiny.profiling.iteration.model
Defined in iteration.
API (12)
Actions
Public operations.
Types and contracts
Public types and contracts.
Values and defaults
Public values and defaults.
default_timeout_msmarker_schemamaximum_patch_bytesmaximum_plan_bytesmaximum_source_bytesmaximum_timeout_msreceipt_schemaschematest_receipt_schema
Source
Source: src/profiling/iteration/model.zig
zig
const std = @import("std");const profiling = @import("../root.zig");const scenario = profiling.scenario;pub const schema = "tiny.profiling.iteration/v1";pub const receipt_schema = "tiny.profiling.iteration-receipt/v1";pub const test_receipt_schema = "tiny.build.test-run-receipt/v1";pub const marker_schema = "tiny.build.iteration-generation/v1";pub const maximum_plan_bytes: usize = 1024 * 1024;pub const maximum_source_bytes: usize = 16 * 1024 * 1024;pub const maximum_patch_bytes: usize = 512 * 1024;pub const maximum_timeout_ms: u64 = 30 * 60 * 1000;pub const default_timeout_ms: u64 = 5 * 60 * 1000;pub const Patch = struct { path: []const u8, before: []const u8, after: []const u8,};pub const Plan = struct { name: []const u8, step: []const u8, args: []const []const u8 = &.{}, patch: Patch, timeout_ms: u64 = default_timeout_ms, pub fn validate(self: Plan) !void { try validateString(self.name); try validateStep(self.step); if (self.args.len > scenario.maximum_arguments) { return error.TooManyIterationArguments; } for (self.args) |argument| { try validateString(argument); if (reservedArgument(argument)) { return error.ReservedIterationArgument; } } if (std.fs.path.isAbsolute(self.patch.path)) { return error.AbsoluteIterationPatchPath; } try validateString(self.patch.path); if (self.patch.before.len == 0 or self.patch.before.len > maximum_patch_bytes or self.patch.after.len == 0 or self.patch.after.len > maximum_patch_bytes or std.mem.indexOfScalar(u8, self.patch.before, 0) != null or std.mem.indexOfScalar(u8, self.patch.after, 0) != null) { return error.InvalidIterationPatch; } if (whitespaceEqual(self.patch.before, self.patch.after)) { return error.WhitespaceOnlyIterationPatch; } if (self.timeout_ms < 1000 or self.timeout_ms > maximum_timeout_ms) { return error.InvalidIterationTimeout; } }};fn validateString(value: []const u8) !void { if (value.len == 0 or value.len > scenario.maximum_string_bytes or std.mem.indexOfScalar(u8, value, 0) != null) { return error.InvalidIterationString; }}fn validateStep(value: []const u8) !void { try validateString(value); if (value[0] == '-') return error.InvalidIterationStep; for (value) |byte| { if (!std.ascii.isAlphanumeric(byte) and byte != '.' and byte != '_' and byte != '-') { return error.InvalidIterationStep; } } if (std.mem.eql(u8, value, "watch") or std.mem.eql(u8, value, "iteration-observe")) { return error.InvalidIterationStep; }}fn reservedArgument(value: []const u8) bool { const reserved = [_][]const u8{ "-Diteration-step", "-Diteration-receipt-dir", "-Diteration-receipt-token", "-Dtiming-receipt-dir", "-Dtiming-receipt-token", "-Dtiming-runner", "-fincremental", "-fno-incremental", "--watch", }; for (reserved) |prefix| { if (std.mem.startsWith(u8, value, prefix) and (value.len == prefix.len or value[prefix.len] == '=')) { return true; } } return false;}fn whitespaceEqual(left: []const u8, right: []const u8) bool { var left_index: usize = 0; var right_index: usize = 0; while (true) { while (left_index < left.len and std.ascii.isWhitespace(left[left_index])) { left_index += 1; } while (right_index < right.len and std.ascii.isWhitespace(right[right_index])) { right_index += 1; } if (left_index == left.len or right_index == right.len) { return left_index == left.len and right_index == right.len; } if (left[left_index] != right[right_index]) return false; left_index += 1; right_index += 1; }}test "iteration plans reject formatting-only patches and receipt overrides" { const base = Plan{ .name = "focused compile", .step = "profile-harness-test", .patch = .{ .path = "src/profiling/test.zig", .before = "const x = 1;", .after = "const x = 2;", }, }; try base.validate(); var formatting = base; formatting.patch.after = " const x = 1; "; try std.testing.expectError( error.WhitespaceOnlyIterationPatch, formatting.validate(), ); var override = base; override.args = &.{"-Dtiming-runner=false"}; try std.testing.expectError( error.ReservedIterationArgument, override.validate(), );}Source: src/profiling/iteration/root.zig:2
zig
pub const model = @import("model.zig");Audit
| Definitions | 13 |
|---|---|
| Public names | 13 |
| Members | 8 |
| Version | 26.7.0 |
| Revision | daab053ee433 |