P6A-8: Source Reference Bundle and harness profile aji_source

- source bundle: a /docs directory with QUICK.md (Quick Reference plus a
  where-to-read table), language/*.md, diagnostics/errors.md and the AIR
  bundle only under air/; built from docs/agent/source-bundle.txt
  (> output files, @manifest includes) by zig build agent-reference
- Quick Reference examples are checked: every aji block must be an
  excerpt of a conformance program in tests/conformance/source/quickref
  (zig build test fails otherwise); QR fixes found by the check
  (mut d = data, region not auto-borrowed, statement/borrow blocks that
  could not verify, io_error match)
- frontend: task.*/channel.*/mutex.* are not-yet-implemented, not E7006
- aji lower --stats: mechanical_air_eliminated_raw and _normalized (each
  byte-string materialization counted as one constant; spec 15 §11)
- harness: profile aji_source (doc_groups), per-file and per-group docs
  metrics on distinctive lines, profile columns (tool calls, lowered AIR
  raw/normalized, docs files read, IR-form and type-mismatch counts),
  dev-echo aji_source variant, scripted run and test, source token report
- plan: P6A-8 done, P6A-9 criteria; Q-021/Q-022 resolved; unsafe block
  deferred
This commit is contained in:
dev committed 2026-10-05 13:16:51 +03:00
1 parent 61be766634
commit 3e2d9b63a7
35 files changed
+1170 -106

No files matched your search

+55
View File
@@ -69,3 +69,58 @@ test {
_ = parse;
_ = lower_mod;
}
pub const Size = struct { bytes: usize, lines: usize };
/// AIR size with every byte-string materialization (the instructions from
/// its `local.zero` to its final `borrow.end`) replaced by one notional
/// line ` const.bytes %<storage>, b"<canonical literal>"` (spec 15 §11).
/// Blank lines are not counted, as for the raw size.
pub fn normalizedSize(arena: std.mem.Allocator, o: lower_mod.Output) std.mem.Allocator.Error!Size {
var size: Size = .{ .bytes = 0, .lines = 0 };
var it = std.mem.splitScalar(u8, o.air, '\n');
var i: usize = 0;
var last: u32 = 0;
while (it.next()) |ln| : (i += 1) {
const k: u32 = if (i < o.constant_of.len) o.constant_of[i] else 0;
if (k != 0) {
if (k != last) {
const c = o.constants[k - 1];
const text = try std.fmt.allocPrint(arena, " const.bytes %{s}, {s}", .{ c.storage, try canonicalBytes(arena, c.bytes) });
size.bytes += text.len + 1;
size.lines += 1;
}
last = k;
continue;
}
last = 0;
if (std.mem.trim(u8, ln, " \t\r").len == 0) continue;
size.bytes += ln.len + 1;
size.lines += 1;
}
return size;
}
/// `b"…"` with printable ASCII as is and `\n \r \t \0 \\ \" \xNN` otherwise.
pub fn canonicalBytes(arena: std.mem.Allocator, bytes: []const u8) std.mem.Allocator.Error![]const u8 {
var out: std.ArrayList(u8) = .empty;
try out.appendSlice(arena, "b\"");
for (bytes) |c| switch (c) {
'\n' => try out.appendSlice(arena, "\\n"),
'\r' => try out.appendSlice(arena, "\\r"),
'\t' => try out.appendSlice(arena, "\\t"),
0 => try out.appendSlice(arena, "\\0"),
'\\' => try out.appendSlice(arena, "\\\\"),
'"' => try out.appendSlice(arena, "\\\""),
0x20...0x21, 0x23...0x5b, 0x5d...0x7e => try out.append(arena, c),
else => try out.print(arena, "\\x{x:0>2}", .{c}),
};
try out.append(arena, '"');
return out.items;
}
test canonicalBytes {
var a = std.heap.ArenaAllocator.init(std.testing.allocator);
defer a.deinit();
try std.testing.expectEqualStrings("b\"hi\\n\\\"\\x01\"", try canonicalBytes(a.allocator(), "hi\n\"\x01"));
}