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/Host.zig | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'src/host/Host.zig') diff --git a/src/host/Host.zig b/src/host/Host.zig index 05d08f7..75b49b3 100644 --- a/src/host/Host.zig +++ b/src/host/Host.zig @@ -74,7 +74,6 @@ state: memory.StateFile, session: memory.Session, /// A failed resource setup disables app callbacks while keeping host controls alive. session_ready: bool = false, -store: memory.StoreFile, /// Images and buffers the sketch made (`newImage`, `decodeImage`, /// `newBuffer`): Session holds their handles, so they go when it resets. made: struct { images: std.ArrayList(abi.Image) = .empty, buffers: std.ArrayList(abi.Buffer) = .empty } = .{}, @@ -184,12 +183,6 @@ pub fn init(self: *Host, gpa: std.mem.Allocator, io: std.Io, environ: *const std if (state_path.len > 0) options.state = state_path; var state = try memory.StateFile.open(gpa, options.state); errdefer state.close(); - var store_buf: [std.fs.max_path_bytes]u8 = undefined; - var store = memory.StoreFile.open(gpa, try std.mem.print(&store_buf, "{s}.store", .{options.state}), options.fresh) catch |err| { - if (err == error.StoreInUse) std.log.err("{s}.store is open in another process", .{options.state}); - return err; - }; - errdefer store.close(); self.* = .{ .gpa = gpa, @@ -204,7 +197,6 @@ pub fn init(self: *Host, gpa: std.mem.Allocator, io: std.Io, environ: *const std .audio = .{ .gpa = gpa }, .state = state, .session = .init(gpa), - .store = store, .timeline = undefined, .sessions = .{ .gpa = gpa, .io = io }, .sketch = sketch, @@ -267,7 +259,6 @@ pub fn deinit(self: *Host) void { self.written.deinit(self.gpa); self.timeline.deinit(); self.session.deinit(self.gpa); - self.store.close(); self.made.images.deinit(self.gpa); self.made.buffers.deinit(self.gpa); self.state.close(); @@ -658,9 +649,7 @@ fn context(self: *Host) abi.Context { .input = &self.input, .scratch = self.frame_arena.allocator(), .session = self.session.heap.allocator(), - .store = self.store.allocator(), .session_root = self.session.bytes.ptr, - .store_root = self.store.root(), .commands = &self.commands, }; } @@ -774,7 +763,6 @@ fn adopt(self: *Host, sketch: abi.Sketch) !void { const adoption = try self.state.adopt(self.gpa, info.state, sketch.defaults); const session_reset = try self.session.adopt(self.gpa, info.session, sketch.defaults); if (session_reset) self.releaseMade(); - const stored = try self.store.adopt(self.gpa, info.store, sketch.defaults); _ = self.info_arena.reset(.retain_capacity); const arena = self.info_arena.allocator(); self.name = try arena.dupe(u8, info.name); @@ -797,10 +785,6 @@ fn adopt(self: *Host, sketch: abi.Sketch) !void { if (!self.session_ready) self.console.visible = true; } if (session_reset and self.reloads > 0) self.print("session layout changed: session reset", .{}); - switch (stored) { - .unchanged, .created => {}, - .migrated => |m| self.print("store layout changed: kept {d} fields, reset {d} to defaults", .{ m.kept, m.reset }), - } } /// Frees what the old Session made: its handles are gone with it. @@ -1155,11 +1139,10 @@ test "session setup runs for restored state and layout reset, not same-layout re const State = extern struct { value: u32 = 1 }; const Session1 = extern struct { ready: u32 = 0 }; const Session2 = extern struct { ready: u32 = 0, extra: u32 = 0 }; - const Store = struct {}; var setup_calls: usize = 0; var init_calls: usize = 0; var fail_setup = false; - const description: abi.Info = .{ .abi = abi.hash, .name = "setup-test", .width = 1, .height = 1, .state = abi.layout.of(State, .state), .session = abi.layout.of(Session1, .session), .store = abi.layout.of(Store, .store) }; + const description: abi.Info = .{ .abi = abi.hash, .name = "setup-test", .width = 1, .height = 1, .state = abi.layout.of(State, .state), .session = abi.layout.of(Session1, .session) }; const changed: abi.Info = blk: { var value = description; value.session = abi.layout.of(Session2, .session); @@ -1175,7 +1158,6 @@ test "session setup runs for restored state and layout reset, not same-layout re switch (kind) { .state => @as(*State, @ptrCast(@alignCast(ptr))).* = .{}, .session => @as(*Session1, @ptrCast(@alignCast(ptr))).* = .{}, - .store => {}, } } fn defaults2(kind: abi.Memory, ptr: [*]u8) callconv(.c) void { @@ -1203,9 +1185,7 @@ test "session setup runs for restored state and layout reset, not same-layout re var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); var state_buf: [std.fs.max_path_bytes]u8 = undefined; - var store_buf: [std.fs.max_path_bytes]u8 = undefined; const state_path = try std.mem.print(&state_buf, ".zig-cache/tmp/{s}/setup.state", .{&tmp.sub_path}); - const store_path = try std.mem.print(&store_buf, ".zig-cache/tmp/{s}/setup.store", .{&tmp.sub_path}); { var state = try memory.StateFile.open(a, state_path); defer state.close(); @@ -1218,8 +1198,6 @@ test "session setup runs for restored state and layout reset, not same-layout re host.gpa = a; host.state = try memory.StateFile.open(a, state_path); defer host.state.close(); - host.store = try memory.StoreFile.open(a, store_path, false); - defer host.store.close(); host.session = .init(a); defer host.session.deinit(a); host.info_arena = .init(a); -- cgit v1.3