From e699ffe4182f66e28180ea2d91ab1fb8c408d49e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:45:31 -0300 Subject: 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 `.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 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/host/root.zig | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'src/host/root.zig') diff --git a/src/host/root.zig b/src/host/root.zig index c64af92..629c466 100644 --- a/src/host/root.zig +++ b/src/host/root.zig @@ -95,10 +95,10 @@ pub fn main(init: std.process.Init, linked: ?abi.Sketch) !void { // A scripted run from fresh state works on files of its own, moved to // the given path at exit: two runs of one build step (two `zig build`s - // at once share its output path) never share a state or store file, - // nor the files the sketch appends to, nor fail on the store's lock - // (its sessions are in memory). An export's are removed instead: - // nothing reads them, and a player may have the given ones open. + // at once share its output path) never share a state file, nor the + // files the sketch appends to (its sessions are in memory). An export's + // are removed instead: nothing reads them, and a player may have the + // given ones open. var private_buf: [std.fs.max_path_bytes]u8 = undefined; if (options.state.len == 0 and (script_path != null or options.export_to != null)) options.state = "sketch.state"; const given = options.state; @@ -156,9 +156,9 @@ const usage = /// A state file in a directory named `.sketchbook` (`zig build run`'s): /// the directory is made, with a `.gitignore` of `*` (its sessions database -/// grows, and a jj snapshot would commit it), and the state and store files -/// an older build kept beside it are moved in, once. A file is never -/// replaced: when both exist, nothing moves. +/// grows, and a jj snapshot would commit it), and the state file an older +/// build kept beside it is moved in, once. A file is never replaced: when +/// both exist, nothing moves. fn sketchbookDir(io: std.Io, state: []const u8) void { const dir = std.fs.path.dirname(state) orelse return; if (!std.mem.eql(u8, std.fs.path.basename(dir), ".sketchbook")) return; @@ -167,20 +167,15 @@ fn sketchbookDir(io: std.Io, state: []const u8) void { var buf: [std.fs.max_path_bytes]u8 = undefined; const ignore = std.fmt.bufPrint(&buf, "{s}/.gitignore", .{dir}) catch return; cwd.writeFile(io, .{ .sub_path = ignore, .data = "*\n", .flags = .{ .exclusive = true } }) catch {}; - for ([_][]const u8{ "", ".store" }) |suffix| { - var from_buf: [std.fs.max_path_bytes]u8 = undefined; - var to_buf: [std.fs.max_path_bytes]u8 = undefined; - const parent = std.fs.path.dirname(dir) orelse "."; - const from = std.fmt.bufPrintSentinel(&from_buf, "{s}/{s}{s}", .{ parent, std.fs.path.basename(state), suffix }, 0) catch return; - const to = std.fmt.bufPrintSentinel(&to_buf, "{s}{s}", .{ state, suffix }, 0) catch return; - switch (std.os.linux.errno(std.os.linux.renameat2(std.os.linux.AT.FDCWD, from.ptr, std.os.linux.AT.FDCWD, to.ptr, .{ .NOREPLACE = true }))) { - .SUCCESS => std.debug.print("sketchbook: moved {s} to {s}\n", .{ from, to }), - .EXIST => { - std.debug.print("sketchbook: {s} and {s} both exist: nothing moved, {s} is used\n", .{ from, to, to }); - return; - }, - else => {}, - } + var from_buf: [std.fs.max_path_bytes]u8 = undefined; + var to_buf: [std.fs.max_path_bytes]u8 = undefined; + const parent = std.fs.path.dirname(dir) orelse "."; + const from = std.fmt.bufPrintSentinel(&from_buf, "{s}/{s}", .{ parent, std.fs.path.basename(state) }, 0) catch return; + const to = std.fmt.bufPrintSentinel(&to_buf, "{s}", .{state}, 0) catch return; + switch (std.os.linux.errno(std.os.linux.renameat2(std.os.linux.AT.FDCWD, from.ptr, std.os.linux.AT.FDCWD, to.ptr, .{ .NOREPLACE = true }))) { + .SUCCESS => std.debug.print("sketchbook: moved {s} to {s}\n", .{ from, to }), + .EXIST => std.debug.print("sketchbook: {s} and {s} both exist: nothing moved, {s} is used\n", .{ from, to, to }), + else => {}, } } -- cgit v1.3