Phase 6A: .aji layers 3-4 (addressable values, lexical borrows, slices)

Owner rules: addressability is decided by lowering (a variable that is
borrowed, indexed or written through a place gets frame storage in the
entry block; otherwise SSA; by name, deterministic); borrows are bound
only by 'ref r = place;' / 'mut r = place;' and live to the end of the
block (borrow.end at every normal exit, including break/continue/return);
no shadowing of an active borrow in the same scope; ref/mut as call
arguments are temporaries ended after the call; *r only for scalar and
struct referents, slices via s[i], s[a..b], s.len; writes *r = v,
r.f = v, s[i] = v with the value evaluated first; split_at as the only
multi-result binding; slice.copy(mut dst, ref src) as the only copy;
[e; N] evaluates e once; byte strings as [u8; N] in frame storage with
a fixed escape set; borrow.index.proven only for the verifier's own
fact form (if i < s.len, same SSA values), otherwise checked.

Diagnostics on lowered AIR are deduplicated per code and source
location. aji lower --stats counts code only (no comment lines).

Tests: 10 run (architecture goldens: value-only has no local.alloc,
borrowed has local.alloc, proven indexing), 6 rejects incl.
verifier-caught E2101 (aliasing; parent used after split_at).
Expansion on these programs: 4-9x bytes, 2.2-6.6x lines.
This commit is contained in:
dev committed 2026-10-05 11:51:04 +03:00
1 parent 0fdd04179b
commit eca30f817a
28 files changed
+1157 -73

No files matched your search

+20 -13
View File
@@ -100,24 +100,31 @@ fn run(io: std.Io, arena: std.mem.Allocator, args: []const [:0]const u8, out: *s
.ok => |o| {
if (stats) {
// How much mechanical work the frontend took over.
const lines = struct {
fn count(t: []const u8) usize {
var n: usize = 0;
// Code only: blank lines and `//` / `;` comment lines are not counted.
const Code = struct { bytes: usize, lines: usize };
const code = struct {
fn count(t: []const u8) Code {
var c: Code = .{ .bytes = 0, .lines = 0 };
var it = std.mem.splitScalar(u8, t, '\n');
while (it.next()) |ln| n += @intFromBool(std.mem.trim(u8, ln, " \t\r").len != 0);
return n;
while (it.next()) |ln| {
const tr = std.mem.trim(u8, ln, " \t\r");
if (tr.len == 0 or std.mem.startsWith(u8, tr, "//") or std.mem.startsWith(u8, tr, ";")) continue;
c.bytes += ln.len + 1;
c.lines += 1;
}
return c;
}
}.count;
const sl = lines(source);
const al = lines(o.air);
const sc = code(source);
const ac = code(o.air);
var s: std.json.Stringify = .{ .writer = out };
try s.write(.{
.source_bytes = source.len,
.source_lines = sl,
.air_bytes = o.air.len,
.air_lines = al,
.expansion_bytes = @as(f64, @floatFromInt(o.air.len)) / @as(f64, @floatFromInt(@max(source.len, 1))),
.expansion_lines = @as(f64, @floatFromInt(al)) / @as(f64, @floatFromInt(@max(sl, 1))),
.source_bytes = sc.bytes,
.source_lines = sc.lines,
.air_bytes = ac.bytes,
.air_lines = ac.lines,
.expansion_bytes = @as(f64, @floatFromInt(ac.bytes)) / @as(f64, @floatFromInt(@max(sc.bytes, 1))),
.expansion_lines = @as(f64, @floatFromInt(ac.lines)) / @as(f64, @floatFromInt(@max(sc.lines, 1))),
});
try out.writeByte('\n');
return .accepted;