summaryrefslogtreecommitdiff
path: root/core/dump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 10:49:23 -0300
committerGabriel Schneider <[email protected]>2026-11-19 11:41:14 -0300
commit4569aefd55d04f434f2e2ed5e6e4a511a414cdc7 (patch)
tree53bbb915ea64c0ddcf93f7f61d25c33071ff2427 /core/dump.zig
parent70c1aed30c6884024ecc2bd7f82d47e371d58ca4 (diff)
downloadpardes-4569aefd55d04f434f2e2ed5e6e4a511a414cdc7.tar.gz
pardes-4569aefd55d04f434f2e2ed5e6e4a511a414cdc7.zip
fs: the file system's sites are read through the tape a step is handed, and the reads no tape saw are listed (the handle's step 2, P20, pardes-handle-sizing's second noun): every site of core/fs.zig is the handle's, the core's (`p.tape`: /os's stat, listing and read, a mount's read) where a function holds the core, else a `tape: *Tape` parameter, taken by 16 functions (fs.makeDirs, expandHome, expandHomeFrom, resolveOs, readFile, readFileLimit, readRestore, restorePath; exec.kindOf; up to a core: dump.directory, restoreFile, onDisk, Db.statePath, Core.recentKeeps, Core.parentTrouble, config.Runtime.apply); fs.resolve takes its optional core's tape, `none` without one; sam's World carries the session's tape for `~user`; the bodies of make_dirs, read_file and kind take Zig's io from the tape, and /os's stat and listing are handed it, so fs.zig and exec.zig read the process's io nowhere; the finding, what stopped compiling for want of an io: fs.readHost's two direct callers, both host halves (the tape's own read by path of a record sent by hash, which takes its tape's io; a client's join reading a plain kind's file through the walk's dump hook, whose mode `join_files` is now the host's io), and by reading one step's read no tape saw, ninep/ctl.zig's bare deniedAbove in a /pager open (served in serveFs, which a client replays), now taped as its neighbours are (`p.tape.value(.denied, ..)`, no new site); the host's own calls of these (the launcher, a -l dump, fonts, theme files, Upgrade, a dump failure's message, gui tests) pass `&tape.none`, recorded by nobody as before; and the replay's dump check now puts the core's tape aside with `on` (its dump's `onDisk` replayed a site the tape did not have: every --replay seed diverged at its end in the first gate). The five numbers: (1) functions that gained the parameter 16 (row: 19 + 7); (2) perfops 97 counts within 0.1%, largest image-frame on small +0.0295%, none on a per-row path gained it; (3) stopped compiling for want of an io: fs.readHost from tape.byHash and from dump.slotWrite (host halves), osHandle's io local (fed only sites); (4) global io uses 6 (10), calls into the free functions 80 (92), machine_lines fs.zig 39 -> 38, exec.zig 4 -> 3; (5) lines changed: tests 33, code about 130 (20 of them in host files). Lines in files not this work's: dev/tui/tui.zig 990, dev/gui/gui.zig 613 629 1054 3057 6171 6264 7494 8290, dev/file_watch.zig 612 644, dev/host_io.zig 1521, runtime/main.zig 1373 1391 1398, runtime/macos.zig 646 668, runtime/upgrade.zig 349 396 (each one argument). Gate: tui core-test 837/980 (143 skipped), shell-test 1015/1018, pane-test 183/184, behaviour-test 275/275 and --replay 20 seeds 0 failures, process-test lspcomplete and lspcompletemoved (the base's; pagercolor flaked once, passed alone three of three), replicas --clients 5 diverged 0, unequal 0, deltas wrong 0 (1731/0, 1620/0, 1737/0), quiet 545/0, 554/0, 651/0; daemon.py plain, --far, --games, --window-clients pass; semantics 2f615168fe07b35f (unmoved); frames 77/77 byte-identical in Debug, gui unit-test 1613/1617, perfab corpus2x +0.057% pictures identical in all 10 runs, perfops PASS
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/dump.zig')
-rw-r--r--core/dump.zig41
1 files changed, 22 insertions, 19 deletions
diff --git a/core/dump.zig b/core/dump.zig
index a37f46b9..e6e13a64 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -43,12 +43,12 @@ fn hostEnv(name: [*:0]const u8) ?[*:0]u8 {
/// Where the state file is (Db.zig) and relative Restore names are looked
/// up: the `DumpDir` setting when set (a leading `~/` is the home
/// directory), else the default.
-pub fn directory(buf: []u8, dir_setting: []const u8) ?[]const u8 {
+pub fn directory(tape: *pardes.tape.Tape, buf: []u8, dir_setting: []const u8) ?[]const u8 {
if (dir_setting.len == 0) return defaultDirectory(buf);
var joined: [4096]u8 = undefined;
// `~/x`, else a relative one from the directory pardes started in: the
// same place however it was written, and shown so.
- const raw = pardes.filesystem.expandHome(dir_setting, &joined);
+ const raw = pardes.filesystem.expandHome(tape, dir_setting, &joined);
var fba_buf: [4096]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&fba_buf);
var cwd_buf: [1024]u8 = undefined;
@@ -98,11 +98,11 @@ const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk, []const
const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Shares });
const OnDisk = [MAX_PANES]bool;
-fn onDisk(pane: *const pardes.panes.Pane) bool {
+fn onDisk(tape: *pardes.tape.Tape, pane: *const pardes.panes.Pane) bool {
const f = pane.file orelse return false;
if (f.output != null) return false;
const local = filesystem.localPath(f.path) orelse return false;
- return exec.kindOf(local) != null;
+ return exec.kindOf(tape, local) != null;
}
pub fn dumpState(p: *Pardes) !void {
@@ -177,8 +177,8 @@ pub fn dumpTo(p: *Pardes, to: ?[]const u8) !void {
/// with a `/` or `~/` (as it resolves, else as typed: the read says why),
/// or a bare word that names a file in the DumpDir or the directory pardes
/// runs in; null for one that names none: a label of the state file's.
-pub fn restoreFile(name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[]const u8 {
- const path = filesystem.restorePath(name, dir_setting, out);
+pub fn restoreFile(tape: *pardes.tape.Tape, name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[]const u8 {
+ const path = filesystem.restorePath(tape, name, dir_setting, out);
if (std.mem.indexOfScalar(u8, name, '/') != null or std.mem.startsWith(u8, name, "~")) return path;
return if (std.Io.Dir.path.isAbsolute(path)) path else null;
}
@@ -187,7 +187,7 @@ pub fn restoreFile(name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[
/// or an old byte dump), else the state file's dump of that label.
pub fn restoreBytes(p: *Pardes, gpa: std.mem.Allocator, name: []const u8) ![]u8 {
var buf: [4096]u8 = undefined;
- if (restoreFile(name, p.settings.dump_dir.get(), &buf)) |path| return filesystem.readFile(gpa, path);
+ if (restoreFile(p.tape, name, p.settings.dump_dir.get(), &buf)) |path| return filesystem.readFile(p.tape, gpa, path);
const got = p.db.getDump(p, gpa, name) catch |err| return if (err == error.OutOfMemory) error.OutOfMemory else error.BadDump;
return got orelse error.FileNotFound;
}
@@ -222,7 +222,7 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 {
var names: std.Io.Writer.Allocating = .init(gpa);
defer names.deinit();
for (p.panes, &on_disk) |slot, *on| if (slot) |pane| {
- on.* = onDisk(pane);
+ on.* = onDisk(p.tape, pane);
panes += 1;
const shown: []const u8 = if (pane.addon) |k| k.path else if (pane.file) |f| (if (f.output == null) f.path else "") else pane.cwdSlice();
if (shown.len == 0 or names.written().len + shown.len > 4096) continue;
@@ -263,15 +263,18 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 {
pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![]u8 {
slim_terminals = true;
defer slim_terminals = false;
- join_files = true;
- defer join_files = false;
+ // The join's file reads are the session's host's, between its steps:
+ // with its io, which the core's tape holds (a walk's hook takes no more).
+ join_files = p.tape.io;
+ defer join_files = null;
return dumpWith(p, deferred);
}
/// `dumpJoin`'s and `dumpExit`'s: a terminal dumps its size, not its emulator.
pub var slim_terminals = false;
-/// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file).
-var join_files = false;
+/// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file),
+/// read with this io.
+var join_files: ?std.Io = null;
fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 {
var d = try Session.init(p.gpa);
@@ -282,7 +285,7 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8
try d.put([]const filesystem.Mount, &mounts);
var on_disk: OnDisk = @splat(false);
for (p.panes, &on_disk) |slot, *on| if (slot) |pane| {
- on.* = onDisk(pane);
+ on.* = onDisk(p.tape, pane);
};
try d.put(OnDisk, &on_disk);
const theme: []const u8 = colors.themes[@min(p.settings.theme, colors.themes.len - 1)].name;
@@ -691,7 +694,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool
// Its file gone from disk since the dump: its text is nowhere else, so
// it is said deleted, and Del, Exit and Restore ask first. One never on
// disk (a name not yet saved) comes back as it was.
- if (was_on_disk and !onDisk(pane)) pardes.panes.File.deleted(p, @intCast(id));
+ if (was_on_disk and !onDisk(p.tape, pane)) pardes.panes.File.deleted(p, @intCast(id));
}
// ---- one pane to and from a dump: the store's, a handover's ----
@@ -808,10 +811,10 @@ pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer)
// Paid only at a client's join: the session keeps no file's bytes.
var file: ?[]u8 = null;
defer if (file) |f| s.gpa.free(f);
- if (join_files and s.plain != null and s.ops != null) if (filesystem.localPath(s.path)) |path| {
+ if (join_files) |io| if (s.plain != null and s.ops != null) if (filesystem.localPath(s.path)) |path| {
const z = try s.gpa.dupeSentinel(u8, path, 0);
defer s.gpa.free(z);
- file = filesystem.readHost(s.gpa, z, pardes.memory.limits.max_file_bytes) catch null;
+ file = filesystem.readHost(io, s.gpa, z, pardes.memory.limits.max_file_bytes) catch null;
r.file = file;
};
const bytes = try walk.save(SlotRecord, gpa, &r);
@@ -944,9 +947,9 @@ fn revivePdf(p: *Pardes, id: usize, pane: *pardes.panes.Pane, old: *pardes.panes
test "a DumpDir reads back absolute, however it was written" {
var buf: [4096]u8 = undefined;
- try std.testing.expectEqualStrings("/tmp/dumps", directory(&buf, "/tmp/dumps/").?);
- try std.testing.expectEqualStrings("/tmp/dumps", directory(&buf, "/tmp//x/../dumps").?);
- const rel = directory(&buf, "rel/");
+ try std.testing.expectEqualStrings("/tmp/dumps", directory(&pardes.tape.none, &buf, "/tmp/dumps/").?);
+ try std.testing.expectEqualStrings("/tmp/dumps", directory(&pardes.tape.none, &buf, "/tmp//x/../dumps").?);
+ const rel = directory(&pardes.tape.none, &buf, "rel/");
try std.testing.expect(std.Io.Dir.path.isAbsolute(rel.?) and std.mem.endsWith(u8, rel.?, "/rel"));
}