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/sketch | |
| 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/sketch')
| -rw-r--r-- | src/sketch/request.zig | 2 | ||||
| -rw-r--r-- | src/sketch/root.zig | 31 | ||||
| -rw-r--r-- | src/sketch/web.zig | 7 |
3 files changed, 12 insertions, 28 deletions
diff --git a/src/sketch/request.zig b/src/sketch/request.zig index 0b8b400..4a8e414 100644 --- a/src/sketch/request.zig +++ b/src/sketch/request.zig @@ -1,5 +1,5 @@ //! Requests from `update` that `draw` carries out once. `update` sees only -//! State and input, so when a key should do something to Session or Store +//! State and input, so when a key should do something to Session //! (start the microphone, open a dialog, seek a stream), State holds the //! request and Session remembers which ones it has handled: //! diff --git a/src/sketch/root.zig b/src/sketch/root.zig index d15046d..6d496bb 100644 --- a/src/sketch/root.zig +++ b/src/sketch/root.zig @@ -7,19 +7,18 @@ //! pub const height = 600; //! pub const State = struct { ... }; // saved, snapshotted, replayed: no pointers //! pub const Session = struct { ... }; // this process: survives reloads -//! pub const Store = struct { ... }; // on disk: survives restarts too //! pub const commands = .{"hello"}; // console completions //! pub fn init(state: *State, host: sk.Host) void //! pub fn setup(session: *Session, init: *sk.Init) !void //! pub fn update(state: *State, in: *const sk.Input) void -//! pub fn draw(state: *const State, session: *Session, store: *Store, f: *sk.Frame) void -//! pub fn command(state: *State, store: *Store, c: *sk.Console, line: []const u8) !bool +//! pub fn draw(state: *const State, session: *Session, f: *sk.Frame) void +//! pub fn command(state: *State, session: *Session, c: *sk.Console, line: []const u8) !bool //! //! Functions take the parameters they name, by type, in any order: `draw` -//! may ask for `*Session`, `*Store`, both or neither. `update` must be +//! may ask for `*Session` or not. `update` must be //! deterministic, so it gets `State` and `Input` only: the host replays //! recorded input through it. `draw` presents state as pictures and sound, -//! and changes only Session and Store. Geometry and colors are duck-typed: +//! and changes only Session. Geometry and colors are duck-typed: //! see `shape`. const std = @import("std"); pub const abi = @import("abi"); @@ -67,7 +66,6 @@ pub const Face = abi.Face; pub const Init = struct { host: Host, session: std.mem.Allocator, - store: std.mem.Allocator, }; /// What `draw` receives: input, host services, memory by lifetime and the @@ -82,14 +80,12 @@ pub const Frame = struct { scratch: std.mem.Allocator, /// For Session: this process. session: std.mem.Allocator, - /// For Store: on disk, across restarts. - store: std.mem.Allocator, /// A library's own state for this frame (canim's table of places), in /// `scratch`: null at each frame's start. user: ?*anyopaque = null, pub fn init(ctx: *const abi.Context) Frame { - return .{ .ctx = ctx, .in = ctx.input, .host = ctx.host, .scratch = ctx.scratch, .session = ctx.session, .store = ctx.store }; + return .{ .ctx = ctx, .in = ctx.input, .host = ctx.host, .scratch = ctx.scratch, .session = ctx.session }; } pub fn emit(f: *Frame, command: abi.Command) void { @@ -291,12 +287,11 @@ fn paint(value: anytype) Color { } /// What `command` receives: somewhere to answer, the current input, and the -/// allocators for Session and Store. +/// allocator for Session. pub const Console = struct { host: Host, in: *const Input, session: std.mem.Allocator, - store: std.mem.Allocator, pub fn log(c: *Console, message: []const u8) void { c.host.log(message); @@ -339,7 +334,6 @@ pub fn Glue(comptime App: type, comptime made: Build) type { return struct { pub const State = if (@hasDecl(App, "State")) App.State else struct {}; pub const Session = if (@hasDecl(App, "Session")) App.Session else struct {}; - pub const Store = if (@hasDecl(App, "Store")) App.Store else struct {}; const build: [abi.build.len:0]u8 = abi.build.*; @@ -350,7 +344,6 @@ pub fn Glue(comptime App: type, comptime made: Build) type { .height = if (@hasDecl(App, "height")) App.height else 600, .state = abi.layout.of(State, .state), .session = abi.layout.of(Session, .session), - .store = abi.layout.of(Store, .store), .commands = if (@hasDecl(App, "commands")) &App.commands else &.{}, .source = made.source ++ " " ++ abi.build, .record = made.record, @@ -377,10 +370,10 @@ pub fn Glue(comptime App: type, comptime made: Build) type { return std.mem.eql(u8, name, n); } }; - if (comptime is.named("update") and (T == *Session or T == *Store)) + if (comptime is.named("update") and T == *Session) @compileError("update must be deterministic: it gets State and Input only, so a replay reproduces it"); if (comptime is.named("setup") and (T == *State or T == *const State or T == *const Input)) - @compileError("setup initializes resources: it gets Session, Store, Init and Host only"); + @compileError("setup initializes resources: it gets Session, Init and Host only"); if (comptime (T == *Init or T == *const Init) and !is.named("setup")) @compileError(name ++ " gets no Init: only setup does"); if (comptime is.named("draw") and T == *State) @compileError("draw only reads State: take *const State"); if (comptime T == *Frame and !is.named("draw")) @compileError(name ++ " gets no Frame: only draw does"); @@ -389,8 +382,6 @@ pub fn Glue(comptime App: type, comptime made: Build) type { @ptrCast(@alignCast(offer.state)) else if (T == *Session or T == *const Session) @ptrCast(@alignCast(offer.ctx.session_root)) - else if (T == *Store or T == *const Store) - @ptrCast(@alignCast(offer.ctx.store_root)) else if (T == *const Input) offer.ctx.input else if (T == Host) @@ -416,7 +407,6 @@ pub fn Glue(comptime App: type, comptime made: Build) type { switch (which) { .state => @as(*State, @ptrCast(@alignCast(ptr))).* = .{}, .session => @as(*Session, @ptrCast(@alignCast(ptr))).* = .{}, - .store => @as(*Store, @ptrCast(@alignCast(ptr))).* = .{}, } } pub fn init(ctx: *const abi.Context, s: [*]u8) callconv(.c) void { @@ -424,7 +414,7 @@ pub fn Glue(comptime App: type, comptime made: Build) type { } pub fn setup(ctx: *const abi.Context) callconv(.c) bool { if (!@hasDecl(App, "setup")) return true; - var resource_init: Init = .{ .host = ctx.host, .session = ctx.session, .store = ctx.store }; + var resource_init: Init = .{ .host = ctx.host, .session = ctx.session }; const result = call(App.setup, "setup", .{ .ctx = ctx, .state = undefined, .resource_init = &resource_init }); if (@typeInfo(@TypeOf(result)) == .error_union) result catch |err| { ctx.host.print("session setup failed: {t}", .{err}); @@ -442,7 +432,7 @@ pub fn Glue(comptime App: type, comptime made: Build) type { } pub fn command(ctx: *const abi.Context, s: [*]u8, line: *const []const u8) callconv(.c) abi.Outcome { if (!@hasDecl(App, "command")) return .unknown; - var c: Console = .{ .host = ctx.host, .in = ctx.input, .session = ctx.session, .store = ctx.store }; + var c: Console = .{ .host = ctx.host, .in = ctx.input, .session = ctx.session }; const taken = call(App.command, "command", .{ .ctx = ctx, .state = s, .console = &c, .line = line.* }) catch |err| { c.print("{t}. Type help for usage.", .{err}); return .failed; @@ -488,7 +478,6 @@ test "setup receives session resources without a Frame and reports errors" { ctx.host = .{ .ctx = &seen, .vtable = &vtable }; ctx.session_root = std.mem.asBytes(&session); ctx.session = std.testing.allocator; - ctx.store = std.testing.allocator; const app = sketch(App, .{}); try std.testing.expect(!app.setup(&ctx)); defer std.testing.allocator.free(session.bytes); diff --git a/src/sketch/web.zig b/src/sketch/web.zig index fd8d7bb..9efad0f 100644 --- a/src/sketch/web.zig +++ b/src/sketch/web.zig @@ -2,7 +2,7 @@ //! the imports below: drawing on a 2D canvas, GPU work on WebGPU, sound and //! the microphone on Web Audio, files through the page. State, `update` and //! `draw` are the same Zig as on native. There is no timeline, and nothing -//! persists: Store lasts as long as the page. +//! persists. const std = @import("std"); const abi = @import("abi"); const root = @import("root.zig"); @@ -82,8 +82,6 @@ fn Driver(comptime App: type) type { var ready = false; var state: G.State = undefined; var session: G.Session = undefined; - // No disk on the web: the store lasts as long as the page. - var store: G.Store = undefined; var events: [1024]abi.Event = undefined; var event_count: usize = 0; var input: abi.Input = .{}; @@ -105,9 +103,7 @@ fn Driver(comptime App: type) type { .input = &input, .scratch = scratch.allocator(), .session = gpa, - .store = gpa, .session_root = std.mem.asBytes(&session), - .store_root = std.mem.asBytes(&store), .commands = &commands, }; } @@ -115,7 +111,6 @@ fn Driver(comptime App: type) type { fn init() callconv(.c) void { G.defaults(.state, std.mem.asBytes(&state)); G.defaults(.session, std.mem.asBytes(&session)); - G.defaults(.store, std.mem.asBytes(&store)); input.width = G.description.width; input.height = G.description.height; if (input.window_width == 0) { |
