M checkpoints recorded; harness statuses; memory test split; P6A-12
- results note docs/evaluation/results/2026-10-06-m-checkpoints.md: both checkpoints, owner's assessment (IR-tax closed at the engineering level, layer 7 GO; cost hypothesis open); plan status and order - P6A-12: source type-check completeness (E1001 reached the verifier from a source run); not a layer 7 blocker - harness: metrics.agent_status (max_tokens for a reply cut at its length limit, provider_rate_limited for 429/usage limits) and metrics.evaluation_status (accepted/rejected/evaluator_error/ infrastructure_failure/not_evaluated), kept apart; termination records max_tokens; checkpoint rows show both; evaluator contract: an infrastructure failure sets "infrastructure": true - interpreter memory test: fast form (20k-320k iterations, 256 KiB threshold via Options.collect_threshold) in zig build test; full form (100k/1M/4M) in zig build test-extended; CI job 'extended' also runs conformance with --collect-every-step
This commit is contained in:
1 parent
222c0c884c
commit
c2c238d9b1
13 files changed
+251
-19
No files matched your search
@@ -13,6 +13,15 @@ pub const run = machine.run;
|
||||
pub const writeOutcome = machine.writeOutcome;
|
||||
pub const writeValue = machine.writeValue;
|
||||
pub const call_depth_limit = machine.call_depth_limit;
|
||||
pub const MemoryStats = machine.MemoryStats;
|
||||
|
||||
/// For `tests/extended/memory.zig`: the loop shapes of the memory invariant
|
||||
/// test and the function that measures one.
|
||||
pub const memory_test = struct {
|
||||
pub const loop_shapes = machine.loop_shapes;
|
||||
pub const memoryOf = machine.memoryOf;
|
||||
pub const min_threshold = machine.Heap.min_threshold;
|
||||
};
|
||||
|
||||
test {
|
||||
_ = machine;
|
||||
|
||||
+24
-13
@@ -155,6 +155,9 @@ pub const Options = struct {
|
||||
memory: ?*MemoryStats = null,
|
||||
/// Collect before every instruction (tests: a missed root then fails).
|
||||
collect_every_step: bool = false,
|
||||
/// Smallest heap size that triggers a collection (default 4 MiB); a
|
||||
/// small value makes short test programs collect often.
|
||||
collect_threshold: ?usize = null,
|
||||
/// Maximum number of instructions to execute (spec 11 §7.1); null means unlimited.
|
||||
fuel: ?u64 = null,
|
||||
/// Capability grants for the parameters of the entry function.
|
||||
@@ -234,6 +237,10 @@ pub fn run(arena: std.mem.Allocator, module: air.Module, entry: []const u8, opti
|
||||
}
|
||||
|
||||
m.exec_heap.every_step = options.collect_every_step;
|
||||
if (options.collect_threshold) |t| {
|
||||
m.exec_heap.floor = t;
|
||||
m.exec_heap.threshold = t;
|
||||
}
|
||||
const outcome = try m.runProgram(idx, args);
|
||||
// The result outlives the execution heap.
|
||||
var result = outcome;
|
||||
@@ -401,13 +408,15 @@ const Task = struct {
|
||||
};
|
||||
|
||||
/// Execution heap: collected between instructions (see the file comment).
|
||||
const Heap = struct {
|
||||
pub const Heap = struct {
|
||||
space: std.heap.ArenaAllocator = .init(std.heap.page_allocator),
|
||||
threshold: usize = min_threshold,
|
||||
/// Smallest collection threshold (`Options.collect_threshold`).
|
||||
floor: usize = min_threshold,
|
||||
every_step: bool = false,
|
||||
stats: MemoryStats = .{},
|
||||
|
||||
const min_threshold = 4 << 20;
|
||||
pub const min_threshold = 4 << 20;
|
||||
};
|
||||
|
||||
const Machine = struct {
|
||||
@@ -562,7 +571,7 @@ const Machine = struct {
|
||||
st.collections += 1;
|
||||
st.peak_heap = @max(st.peak_heap, before);
|
||||
st.peak_live = @max(st.peak_live, live);
|
||||
m.exec_heap.threshold = @max(Heap.min_threshold, 2 * live);
|
||||
m.exec_heap.threshold = @max(m.exec_heap.floor, 2 * live);
|
||||
}
|
||||
|
||||
fn pushFrame(m: *Machine, task: u32, fn_index: u32, args: []const Value) !void {
|
||||
@@ -2047,7 +2056,7 @@ test "schedule seed: explicit value is used as is, default derives from the prog
|
||||
// not host RSS: for each loop shape, the live execution state after a
|
||||
// collection must not grow with the iteration count, and the heap stays
|
||||
// under a fixed bound.
|
||||
fn memoryOf(comptime body: []const u8, n: u64) !MemoryStats {
|
||||
pub fn memoryOf(comptime body: []const u8, n: u64, threshold: ?usize) !MemoryStats {
|
||||
var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator);
|
||||
defer arena_state.deinit();
|
||||
const arena = arena_state.allocator();
|
||||
@@ -2058,12 +2067,12 @@ fn memoryOf(comptime body: []const u8, n: u64) !MemoryStats {
|
||||
return error.NotAccepted;
|
||||
}
|
||||
var stats: MemoryStats = .{};
|
||||
const outcome = try run(arena, report.module.?, "main", .{ .grants = &.{.{ .parameter = "heap", .kind = "mem.alloc", .scope = "4096" }}, .memory = &stats });
|
||||
const outcome = try run(arena, report.module.?, "main", .{ .grants = &.{.{ .parameter = "heap", .kind = "mem.alloc", .scope = "4096" }}, .memory = &stats, .collect_threshold = threshold });
|
||||
try std.testing.expect(outcome == .returned);
|
||||
return stats;
|
||||
}
|
||||
|
||||
const loop_shapes = [_][]const u8{
|
||||
pub const loop_shapes = [_][]const u8{
|
||||
// scalar state carried in block arguments
|
||||
\\module t
|
||||
\\fn main(heap: cap<mem.alloc>) -> u64
|
||||
@@ -2133,18 +2142,20 @@ const loop_shapes = [_][]const u8{
|
||||
};
|
||||
|
||||
test "execution memory is bounded by live state, not by the iteration count" {
|
||||
// Fast form: a 256 KiB threshold makes 20k-320k iterations collect many
|
||||
// times. The full form (100k/1M/4M iterations, default threshold) is
|
||||
// tests/extended/memory.zig, run by `zig build test-extended`.
|
||||
const floor = 256 << 10;
|
||||
inline for (loop_shapes, 0..) |shape, k| {
|
||||
const small = try memoryOf(shape, 100_000);
|
||||
const mid = try memoryOf(shape, 1_000_000);
|
||||
const large = try memoryOf(shape, 4_000_000);
|
||||
const small = try memoryOf(shape, 20_000, floor);
|
||||
const mid = try memoryOf(shape, 80_000, floor);
|
||||
const large = try memoryOf(shape, 320_000, floor);
|
||||
errdefer std.debug.print("shape {d}: live {d}/{d}/{d} heap {d}/{d}/{d} collections {d}/{d}/{d}\n", .{
|
||||
k, small.peak_live, mid.peak_live, large.peak_live, small.peak_heap, mid.peak_heap, large.peak_heap,
|
||||
small.collections, mid.collections, large.collections,
|
||||
});
|
||||
try std.testing.expect(large.collections > 0);
|
||||
// Steady state: the live state of 4M iterations is the live state of 1M.
|
||||
try std.testing.expect(large.collections > mid.collections);
|
||||
try std.testing.expect(large.peak_live <= mid.peak_live + 64 * 1024);
|
||||
// The heap is bounded by a constant (collection threshold plus one growth step).
|
||||
try std.testing.expect(large.peak_heap <= 3 * Heap.min_threshold);
|
||||
try std.testing.expect(large.peak_heap <= 3 * floor + 64 * 1024);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user