Fix two toolchain defects found by the M checkpoint

A. Interpreter memory grew with the number of executed steps (one arena,
never reclaimed): block and call arguments, frames, frame storage, value
copies, place paths, channel buffers and per-step scratch now live in a
collectable execution heap. Between instructions, past a threshold, the
live state is copied into a fresh heap (sharing preserved) and the old one
released. Long-lived state (module, world, authority, task, channel and
region tables, the result) stays in the caller's arena. The guarded value
of a mutex is a separate cell (no interior pointers). Nothing observable
changes: fuel, schedule, PRNG, values, traps and run records are the same.
- test: five loop shapes x 100k/1M/4M iterations, measured with the
  interpreter's own heap counters: live state after a collection does not
  grow with the iteration count; the heap stays under a fixed bound
- conformance --collect-every-step: the second run of every run test
  collects before every instruction; records must be byte-identical
  (passes, also with --stress 20)

B. A void function whose body ends in an if/if-else/match/block/void call
lowered to `ret %` (malformed AIR, reported as E0001): it now lowers to
`ret`. Seven fall-through tests (six failed before).

Also: files_opened counts reads by relative path and file name; P6A-11
(malformed generated AIR as an internal compiler diagnostic) and Q-023
(ref of a whole array as an argument) recorded.
This commit is contained in:
dev committed 2026-10-05 15:34:12 +03:00
1 parent 4aa9183e78
commit 222c0c884c
15 files changed
+573 -48

No files matched your search

+10 -2
View File
@@ -526,7 +526,7 @@ const Lowerer = struct {
}
if (tail) |v| {
try l.checkTy(f.body.tail.?.span, v.ty, sig.ret);
try l.term(try l.fmt("ret %{s}", .{v.name}), f.body.tail.?.span);
try l.term(try l.retText(v), f.body.tail.?.span);
} else if (sig.ret == .void) {
try l.term("ret", f.body.span);
} else return l.fail("E7006", f.body.span, "the function can end without returning a value", &.{.{ .name = "function", .value = f.name }});
@@ -561,6 +561,14 @@ const Lowerer = struct {
}
}
/// `ret %v`, or `ret` for a void value: a void function whose body ends
/// in an `if`, `match`, loop, block or void call falls through with
/// nothing to return (spec 15 §4).
fn retText(l: *Lowerer, v: Value) Error![]const u8 {
if (v.ty == .void) return "ret";
return l.fmt("ret %{s}", .{v.name});
}
fn freshName(l: *Lowerer, base: []const u8) Error![]const u8 {
while (true) {
l.counter += 1;
@@ -813,7 +821,7 @@ const Lowerer = struct {
try l.checkTy(x.span, v.ty, l.ret);
if (l.cur != null) {
try l.endScopes(0, s.span);
try l.term(try l.fmt("ret %{s}", .{v.name}), s.span);
try l.term(try l.retText(v), s.span);
}
} else {
if (l.ret != .void) return l.fail("E7005", s.span, "`return` without a value in a function that returns one", &.{.{ .name = "expected", .value = l.tyText(l.ret) }});