diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 00:45:31 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | e699ffe4182f66e28180ea2d91ab1fb8c408d49e (patch) | |
| tree | 0577374fb6164ef214cd727b662a23498ad547eb /src/layout.zig | |
| parent | a1ae80096bd69ee7d92ea9e4564e960d8553395e (diff) | |
| download | sketchbook-e699ffe4182f66e28180ea2d91ab1fb8c408d49e.tar.gz sketchbook-e699ffe4182f66e28180ea2d91ab1fb8c408d49e.zip | |
Delete the Store; State is checked against the 64 MiB a save holds
A sketch's data is State: flat bytes, what grows has its capacity in its
type. The Store, a heap in a file mapped at 0x2000_0000_0000 with 64 GiB
reserved, its power-of-two allocator, its root adopt and migration, and
its test, are gone from memory.zig; so are Context.store and store_root,
Info.store, Memory.store, the Store declaration's glue, Init.store,
Frame.store and Console.store, the web host's store in wasm memory, the
host's StoreFile wiring and `<state>.store` file, the `.store` suffix in
moving an old state into .sketchbook/, the build's tests' `rm` of it, and
layout.check's `pointers` flag (State is the one checked memory now).
Its one real user, micscope, moved off it in the change before. Old
`.state.store` files are not read, converted or deleted, and stay
ignored by .gitignore. A sketch that still declares a Store gets no
error for the declaration: nothing reads it, and a `*Store` parameter is
a compile error (no argument of that type).
layout.of(T, .state) refuses a State bigger than layout.max_state, 64 MiB,
one constant: "State is N bytes, and a save holds at most 64 MiB: lower
a capacity (an array, an sk.List), or keep what need not be saved in
Session." The pointer-hash gap the spec found (a Store pointer's
element type changing kept the old bytes) is gone with the only
persisted memory that held pointers.
README: no Store row, allocator row, migration paragraph, file bullet or
known limits; draw and command lose their store parameter; State's row
says 64 MiB at most; data that grows and is the user's work goes in a
List in State or, bigger than a save, in files the sketch appends to.
Tests: zig build test, 166/166 steps (the store's unit test gone; new: a
65-MiB State fails to compile with the message above, by expect_errors).
micscope, spheres, noc's e2e and drat-meout's test unchanged and green.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/layout.zig b/src/layout.zig index 5e60e22..d61ebf3 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -19,17 +19,20 @@ //! - Session lives in this process: anything, as long as pointers go into //! memory the host owns (its heaps, mapped files), never into the sketch //! library, which a reload unmaps. -//! - Store is a file mapped at the same address in every run: pointers into -//! the store itself, but no host handles. const std = @import("std"); const abi = @import("abi.zig"); +/// The most a State may be, in bytes: a save holds at most 64 MiB. +pub const max_state = 64 << 20; + pub fn of(comptime T: type, comptime memory: abi.Memory) abi.Layout { return comptime blk: { @setEvalBranchQuota(1_000_000); switch (memory) { - .state => check(T, "State", @typeName(T), false), - .store => check(T, "Store", @typeName(T), true), + .state => { + check(T, @typeName(T)); + if (@sizeOf(T) > max_state) @compileError(std.fmt.comptimePrint("State is {d} bytes, and a save holds at most {d} MiB: lower a capacity (an array, an sk.List), or keep what need not be saved in Session.", .{ @sizeOf(T), max_state >> 20 })); + }, .session => {}, } const Leaves = struct { @@ -155,17 +158,16 @@ pub fn resolve(fields: []const abi.Field, path: []const u8) ?Resolved { return null; } -fn check(comptime T: type, comptime memory: []const u8, comptime path: []const u8, comptime pointers: bool) void { +fn check(comptime T: type, comptime path: []const u8) void { comptime { - if (T == abi.Image or T == abi.Audio or T == abi.Buffer) @compileError(memory ++ " cannot hold host handles (" ++ path ++ "): they mean nothing to the next process. Keep them in Session."); + if (T == abi.Image or T == abi.Audio or T == abi.Buffer) @compileError("State cannot hold host handles (" ++ path ++ "): they mean nothing to the next process. Keep them in Session."); switch (@typeInfo(T)) { - // Not followed: types can point to themselves. - .pointer => if (!pointers) @compileError(memory ++ " cannot hold pointers (" ++ path ++ "): it is saved to disk and outlives every address. Keep indices or offsets, or put it in Store or Session."), - .array => |a| check(a.child, memory, path ++ "[]", pointers), - .vector => |v| check(v.child, memory, path ++ "[]", pointers), - .optional => |o| check(o.child, memory, path, pointers), - .@"struct" => |s| for (s.field_names, s.field_types) |name, F| check(F, memory, path ++ "." ++ name, pointers), - .@"union" => |u| for (u.field_names, u.field_types) |name, F| check(F, memory, path ++ "." ++ name, pointers), + .pointer => @compileError("State cannot hold pointers (" ++ path ++ "): it is saved to disk and outlives every address. Keep indices or offsets, or put it in Session."), + .array => |a| check(a.child, path ++ "[]"), + .vector => |v| check(v.child, path ++ "[]"), + .optional => |o| check(o.child, path), + .@"struct" => |s| for (s.field_names, s.field_types) |name, F| check(F, path ++ "." ++ name), + .@"union" => |u| for (u.field_names, u.field_types) |name, F| check(F, path ++ "." ++ name), else => {}, } } |
