cli: add whole-value linear aggregates

Implement STD-5 through source, AIR, verifier and deterministic interpreter.
Constructors consume nested owners; exhaustive unpack/take, explicit swap and
own.pack preserve ownership on success and failure. Support owning Option and
Result while keeping classification helpers Copy-only. Preserve borrow identity
across whole replacement and collection; distinguish individual owned arrays
from repeated heap arrays.

Specify feature contracts, invariants, diagnostics, compatibility and measured
source/AIR budgets in RFC 0023 and normative docs. Add canonical round trips,
AIR/source acceptance and rejection fixtures, CLI integration and CI checks.

Validate build, unit/extended tests, full conformance, forced-collection schedule
stress (32 seeds per quantum), hosted smoke, CLI suites, source coverage (88/88),
formatting and reference bundle generation. Source bundle grows 3.2%; Quick
Reference grows 4.0%. No MCC improvement is claimed.

Dynamic initialized linear buffers and explicit drain remain Q-036/STD-6;
frame/region/repeated heap storage is Copy-only. RFC remains Proposed.
This commit is contained in:
dev committed 2026-10-06 21:23:52 +03:00
1 parent 7eea31518d
commit 4f084decce
109 files changed
+1814 -142

No files matched your search

+61 -4
View File
@@ -209,6 +209,19 @@ fn printOp(m: air.Module, f: air.Function, op: air.Op, w: *Writer) Writer.Error!
try w.print("cast.{s}.{s} ", .{ @tagName(x.mode), @tagName(x.to) });
try value(f, x.a, w);
},
.array_make => |x| {
try w.writeAll("array.make ");
try printType(m, x.ty, w);
try values(f, x.args, w);
},
.aggregate_unpack => |x| {
try w.writeAll(if (x.ty == .array) "array.unpack " else "struct.unpack ");
try printType(m, x.ty, w);
try w.writeByte(' ');
try value(f, x.value, w);
try w.print(", next -> @{s}", .{f.blocks[x.next].name});
},
.value_swap => |x| try two(f, w, "value.swap", x.borrow, x.value),
.struct_make => |x| {
try w.print("struct.make @{s}", .{m.types[x.decl].name});
try values(f, x.args, w);
@@ -251,8 +264,8 @@ fn printOp(m: air.Module, f: air.Function, op: air.Op, w: *Writer) Writer.Error!
try w.writeAll(", default -> ");
try target(f, x.default, w);
},
.enum_switch => |x| {
try w.writeAll("enum.switch ");
inline .enum_switch, .enum_take => |x| {
try w.writeAll(if (op == .enum_take) "enum.take " else "enum.switch ");
try printType(m, x.ty, w);
try w.writeByte(' ');
try value(f, x.value, w);
@@ -310,8 +323,15 @@ fn printOp(m: air.Module, f: air.Function, op: air.Op, w: *Writer) Writer.Error!
try values(f, x.args, w);
if (x.ok) |ok| try w.print(", ok -> @{s}, err -> @{s}", .{ f.blocks[ok].name, f.blocks[x.err.?].name });
},
.own_new => |x| {
try two(f, w, "own.new", x.value, x.cap);
inline .own_new, .own_pack => |x, tag| {
if (tag == .own_pack) {
try w.writeAll("own.pack ");
try printType(m, x.ty, w);
try w.writeByte(' ');
try value(f, x.value, w);
try w.writeAll(", ");
try value(f, x.cap, w);
} else try two(f, w, "own.new", x.value, x.cap);
try okErr(f, w, x.ok, x.err);
},
.own_array => |x| {
@@ -635,3 +655,40 @@ test "round-trip of ownership and arrays forms" {
\\
);
}
test "round-trip whole-value linear operations" {
try roundTrip(
\\module test.linear
\\air 0
\\lang 0.1
\\features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources]
\\type @Maybe = enum { some(own<u64>), none }
\\fn @main(%heap: cap<mem.alloc>) -> u64
\\effects [mem.alloc]
\\entry:
\\ %n = const.u64 42
\\ own.pack u64 %n, %heap, ok -> @got, err -> @failed
\\got(%owner: own<u64>):
\\ %items = array.make array<own<u64>,1>(%owner)
\\ array.unpack array<own<u64>,1> %items, next -> @element
\\element(%part: own<u64>):
\\ %slot = enum.make @Maybe.some(%part)
\\ %empty = enum.make @Maybe.none()
\\ %borrow = borrow.mut %slot
\\ %old = value.swap %borrow, %empty
\\ borrow.end %borrow
\\ enum.take @Maybe %slot, some -> @extra, none -> @replaced
\\extra(%extra_owner: own<u64>):
\\ own.free %extra_owner
\\ enum.take @Maybe %old, some -> @answer, none -> @no_answer
\\replaced:
\\ enum.take @Maybe %old, some -> @answer, none -> @no_answer
\\answer(%answer_owner: own<u64>):
\\ %value = own.take %answer_owner
\\ ret %value
\\no_answer:
\\ ret %n
\\failed(%e: alloc_error, %original: u64):
\\ ret %n
);
}