diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Core.zig | 7 | ||||
| -rw-r--r-- | core/Kind.zig | 50 | ||||
| -rw-r--r-- | core/Term.zig | 8 | ||||
| -rw-r--r-- | core/dump.zig | 4 | ||||
| -rw-r--r-- | core/exec.zig | 4 | ||||
| -rw-r--r-- | core/replica.zig | 152 |
6 files changed, 208 insertions, 17 deletions
diff --git a/core/Core.zig b/core/Core.zig index 3a2e1f51..b80fec2b 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -304,9 +304,10 @@ n_look_src: usize = 0, look_walk_owner: ?u32 = null, /// hands out Pane.serial; monotonic, never reused next_serial: u32 = 0, -/// The writes of its terminals' emulators, which no rollback copy holds -/// (Term.Outside): digested, dumped and copied as any field, so the same on -/// every side; the replica engine's one question of a unit reads it. +/// The writes of its terminals' emulators, and the opens and closes of its +/// plain kinds' states (Kind.reopen, Kind.close), which no rollback copy +/// holds (Term.Outside): digested, dumped and copied as any field, so the +/// same on every side; the replica engine's one question of a unit reads it. outside: pardes.Term.Outside = .{}, /// The column whose tag the running command came from, while it runs: /// the column acme's commands take from their Text's col. diff --git a/core/Kind.zig b/core/Kind.zig index 4841a55c..c8420c8a 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -39,7 +39,7 @@ pub const abi: u32 = c.PA_ABI; // records the core reads are the ones addons are built to. comptime { if (@sizeOf(usize) == 8) for (.{ - .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, + .{ c.pa_cell, 20 }, .{ c.pa_window, 32 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, .{ c.pa_placement, 80 }, .{ c.pa_paint, 48 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 }, .{ c.pa_api, 128 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 }, .{ c.pa_ops, 208 }, .{ c.pa_view, 32 }, .{ c.pa_tick, 128 }, @@ -320,10 +320,16 @@ pub fn reopen(p: *Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool { if (p.kinds.byName(s.nameOf())) |k| { // Its code: its library loaded at the first pane of its kind. if (s.ops == null) s.ops = Addon.need(&p.kinds, p.tape, k, &cl.refused, p.opts.distrusted); - // Its block made afresh by this open. + // Its block made afresh by this open. And what a plain kind keeps + // beside it (a PDF's document), made in every core that runs it, is + // no rollback copy's: a write outside the copy (Pardes.outside), + // counted by the registry's word on every side alike, the kind's + // code here or not. A client that kept this step to replay over its + // copy would make that state again and never close the first. if (p.kinds.kinds[k].caps.plain) { if (s.plain) |b| if (b.len > 0) s.gpa.free(b); s.plain = &.{}; + p.outside.n +%= 1; } // Its tag's computed words (UX K'3): its words, then Del. var w: std.Io.Writer = .fixed(&s.tail.bytes); @@ -416,6 +422,11 @@ pub fn close(p: *Pardes, pane: *Pane) void { // own memory (its pictures) is left be, as the rollback brings the pane // back; the session's order closes it. const kept = s.plain != null and s.ops != null and s.ops.?.close != null and p.tape.authorityOnly("a kind's close"); + // What a plain kind keeps beside its block let go: outside the copy, as + // its open was (reopen). + if (p.kinds.byName(s.nameOf())) |k| if (p.kinds.kinds[k].caps.plain) { + p.outside.n +%= 1; + }; if (!kept) { var i: usize = 0; while (i < ready.items.len) if (ready.items[i].draw == p and ready.items[i].serial == pane.serial) ready.orderedRemove(i).drop() else { @@ -518,7 +529,8 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator, var gpu: GpuPaint = .{ .arena = arena, .frame = frame }; var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len, .gpu = GpuPaint.emit, .gpu_ctx = &gpu }); const px = p.view().cell_pixels; - const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images) }); + const chrome = p.chrome(); + const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images), .hit = rgb(chrome.hit), .hit_current = rgb(chrome.hit_current) }); var cl: Call = .{ .p = null, .id = id, .slot = slot, .quiet = true, .core = p }; const prev = cl.begin("paint"); const before = if (checked) usedHash(slot) else {}; @@ -792,11 +804,6 @@ pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view { // derived, so a client joined from a dump has none. const notices = pardes.Messages.bands(p, pane, tag_rows, r).span(); const th = p.theme(); - const rgb = struct { - fn f(x: [3]u8) u32 { - return @as(u32, x[0]) << 16 | @as(u32, x[1]) << 8 | x[2]; - } - }.f; const policy = rasterPolicy(v.frontend.windowed); return .{ .cols = r.w -| pardes.config.GUTTER, @@ -816,6 +823,11 @@ pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view { }; } +/// A theme's colour as the header's PA_RGB. +fn rgb(x: [3]u8) u32 { + return @as(u32, x[0]) << 16 | @as(u32, x[1]) << 8 | x[2]; +} + /// Whether pane `id` has the keyboard in some view (its window focused). fn focusedAnywhere(p: *const Pardes, id: usize) bool { for (&p.views) |*v| if (v.*) |*vw| if (vw.active == id and vw.window_focused) return true; @@ -1298,8 +1310,11 @@ var drawn: u32 = 0; /// its own. pub fn landDraw(p: *Pardes, j: *host_io.KindJob) void { if (j.draw != p) return j.drop(); - // Its pane closed meanwhile: no paint of it would ever take it. - if (if (p.panes[j.pane]) |pane| pane.serial != j.serial else true) return j.drop(); + // Its pane closed meanwhile, or showing no kind now (a picker's preview + // closed, the pane its own text again): no paint of it would ever take + // it, nor would the pane's close (Kind.close: a slot's draws). + const pane = p.panes[j.pane] orelse return j.drop(); + if (pane.serial != j.serial or pane.addon == null) return j.drop(); ready.append(heap, j) catch return j.drop(); p.needs_frame = true; } @@ -1415,3 +1430,18 @@ const GpuPaint = struct { return 0; } }; + +test "a picture drawn for a pane that shows no kind's slot when it lands (a picker's preview closed meanwhile) is dropped, never kept for a paint that never comes" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + _ = try p.setTestFile("the notes\n"); + const id = p.view().active; + try std.testing.expect(p.panes[id].?.addon == null); + // A draw of the preview's, back from its worker after Esc gave the pane + // its own text again. + const j = try heap.create(host_io.KindJob); + j.* = .{ .gpa = heap, .pane = @intCast(id), .serial = p.panes[id].?.serial, .token = c.PA_DRAWN | 1, .gen = 0, .ops = &test_kind.ops, .in = try heap.dupe(u8, "draw"), .arena = .init(heap), .draw = p }; + Addon.holdJob(j.ops, true); + landDraw(p, j); + try std.testing.expectEqual(@as(usize, 0), ready.items.len); +} diff --git a/core/Term.zig b/core/Term.zig index 509da6d9..2f0a0f3f 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -19,9 +19,11 @@ const iface = plain.term; /// digested and dumped, a function of the tape, the same on every side (one /// side's emulator written where the others' are not is a digest that says /// `outside`). Every write below takes it and counts, and so does a write a -/// speculation owes (`resize`): over an input's apply, the count moved is -/// "this input wrote, or owes, state outside the copy", the one question -/// core/replica.zig `confirm` asks a unit. A load sets it from the dump. +/// speculation owes (`resize`), and a plain kind's state opened or closed +/// (Kind.reopen, Kind.close: what it keeps beside its block, a PDF's +/// document): over an input's apply, the count moved is "this input wrote, +/// or owes, state outside the copy", the one question core/replica.zig +/// `confirm` asks a unit. A load sets it from the dump. pub const Outside = struct { n: u64 = 0 }; /// The reloads this process made (a join's, on every side) and their time, /// for the soak's join line (test/replicas.zig `--bytes`). diff --git a/core/dump.zig b/core/dump.zig index a2b22cef..b1fad70e 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -1013,6 +1013,10 @@ pub fn plainHere(p: *Pardes, id: usize, old: *Kind.Slot, ops: *const Kind.Ops) ! s.selection = try p.gpa.dupe(u8, old.selection); // (and its place: the open's own `where` is of a block not yet the session's) const kept = .{ old.next_tick, old.views, old.focused, old.state, old.where_text }; + // The count of writes outside the copy stays the session's, as dumped: + // this open is the join's, no step the session took (Kind.reopen). + const outside = p.outside; + defer p.outside = outside; if (!Kind.reopen(p, id, s, old.file)) return error.KindRefused; // Its block the session's, byte for byte (its record), never through // the kind's load, which may tidy it. diff --git a/core/exec.zig b/core/exec.zig index 44cfea64..47fea012 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -751,6 +751,10 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { if (other.command != null and other.command_done and !other.command_pty and std.mem.eql(u8, other.cwdSlice(), dir) and !leased(p, other.serial)) break i; } else null; if (reuse) |id| { + // A process started and its emulator written, as a new command + // pane's (panes.newCommand): the session's, which a speculation + // waits for, nothing of the pane changed first. + if (p.tape.authorityOnly("run a command")) return null; const pane = p.panes[id].?; const owned = p.gpa.dupe(u8, line) catch |err| { p.reportError(.at(from), "exec", err); diff --git a/core/replica.zig b/core/replica.zig index 49ccd85b..a19340bd 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -7318,7 +7318,10 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re /// `addon`: a kind whose state is its own on the session (a PDF's), which /// the walk does not stand in (its Still has no search, place or word): /// the soak's (test/replicas.zig) PDF and pictures are, judged by name. -const On = enum { any, file, kind, shell, shell_normal, addon, dir }; +/// `command`: a pane in a directory with a finished command pane, which a +/// line run there runs in again (exec.runCommand); the walk stands in none: +/// the soak's are, judged by name, and the test after the walk. +const On = enum { any, file, kind, shell, shell_normal, addon, dir, command }; /// What a far client may wait a round trip for (the user's line, P14: a /// side effect on the system may be slow; motions, edits and layout are @@ -7352,6 +7355,7 @@ const may_wait = [_]Wait{ .{ .what = "Find *", .on = .any, .stop = "kind", .why = "the work tree it lists from, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the listing itself is the session's" }, .{ .what = "Grep *", .on = .any, .stop = "kind", .why = "the work tree it searches, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the search itself is the session's" }, .{ .what = "Exec *", .on = .any, .stop = "tty_taken", .why = "a program run in a shell: whether one has it, the session's" }, + .{ .what = "Exec *", .on = .command, .stop = "run a command", .why = "a line run again in its directory's finished command pane: its process and its emulator are the session's" }, .{ .what = "Term", .on = .any, .stop = "kind", .why = "a shell opened: its name asked of the disk first" }, .{ .what = "A-n", .on = .any, .stop = "open a terminal", .why = "a shell opened" }, .{ .what = "* A-n", .on = .any, .stop = "open a terminal", .why = "a shell opened (Alt-n after a prefix is still the global key)" }, @@ -7715,6 +7719,40 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' try std.testing.expectEqual(@as(u32, 0), stale); } +test "a far client's line run again in its directory's finished command pane waits for the session's order, at a stop may_wait lists: its process and its emulator are the session's" { + // The soak's (test/replicas.zig, seed 3 rtt 80): a client's key stopped + // at `spawn`, which may_wait does not list. Its speculation ran the + // reused pane's whole run (exec.runCommand): the emulator's writes + // refused (`a terminal's output`), then the spawn effect (a host entry + // that keeps stopping), the last one naming the stop. + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); + defer a.deinit(); + const file = a.core.view().active; + _ = try a.local(.{ .command = "Exec true" }); + const cmd = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.command != null) break id; + } else return error.NoCommandPane; + _ = try a.local(.{ .exited = .{ .pane = .at(cmd), .status = 0 } }); + _ = try a.local(.{ .eof = .{ .pane = .at(cmd) } }); + try std.testing.expect(a.core.panes[cmd].?.command_done); + a.core.view().active = file; + const r = try joinedFresh(a); + defer r.deinit(); + // The same line from the file's pane: its directory's finished pane runs it. + const stopped = r.stats.stopped; + const msg = try gpa.dupe(u8, try r.input(.{ .command = "Exec true" })); + defer gpa.free(msg); + try std.testing.expectEqual(stopped + 1, r.stats.stopped); + if (!mayWait(r.t.poisoned_by)) std.debug.print("stopped at `{s}`\n", .{r.t.poisoned_by}); + try std.testing.expect(mayWait(r.t.poisoned_by)); + r.confirm(try a.take(msg)); + r.settle(); + try agrees(a, r); + try std.testing.expect(!a.core.panes[cmd].?.command_done); +} + test "a far client's click into a shell whose program asked for focus events is instant: the session's step tells the program, a round trip later, and the client's guess is confirmed" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; @@ -9201,3 +9239,115 @@ test "a client joined after its session's shell was found to have no prompt mark _ = try n.serve(.{ .tag = 4, .op = .release, .node = run, .handle = h, .opened = true }, true); try n.agree(); } + +test "a picker's preview opens and closes a plain kind's state in the pane it lands in, no pane opened or closed: a client with a copy ahead never replays it over the copy, and every state the kind opens is closed once" { + // The soak's (test/replicas.zig with the pdf addon): `allocator leaks + // detected` at seed 0 rtt 80, the documents of PDFs a picker previewed + // (Pick.showKind) on a client, opened by a unit it kept to replay over + // its copy and opened again by the replay, the first never closed. + // A plain kind that holds something of its own outside its block for + // each state it opens, as the pdf addon holds a document (its `Own`): + // each open notes its block, each close lets it go, so a state opened + // and never closed stays noted. Its files are `.own`. + const Owned = struct { + const pa = pardes.Kind.c; + var noted: [8]?*anyopaque = @splat(null); + fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { + const st = pardes.Kind.api.alloc.?(4); + for (¬ed) |*n| if (n.* == null) { + n.* = st; + break; + }; + return st; + } + fn close(st: ?*anyopaque) callconv(.c) void { + for (¬ed) |*n| if (n.* == st) { + n.* = null; + return; + }; + } + fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {} + fn held() usize { + var n: usize = 0; + for (noted) |st| n += @intFromBool(st != null); + return n; + } + const ops = std.mem.zeroInit(pardes.Kind.Ops, .{ + .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "owned".* ++ @as([11]u8, @splat(0)), .version = 1, .exts = ".own", .flags = pa.PA_PLAIN }), + .open = open, + .close = close, + .paint = paint, + }); + }; + const gpa = std.testing.allocator; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paper.own", .data = "own" }); + var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + var line: [std.Io.Dir.max_path_bytes + 32]u8 = undefined; + { + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); + defer a.deinit(); + var words: [64]pardes.Kind.LoadedWord = undefined; + const owned = pardes.Kind.loadedOf(&Owned.ops, "/x/owned.so", @splat(7), &words); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &owned } }); + _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/notes.txt", .{dir}) }); + // A client in a view of its own, running the kind's code. + const joined = (try a.join(1, null)).?; + defer gpa.free(joined.dump); + const r = try Replica.initDump(gpa, 1, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); + defer r.deinit(); + r.core().kinds.ops[r.core().kinds.byName("owned").?] = &Owned.ops; + // SPC f f p at the session, in its view: its picker lists the tree, + // and paper.own, the one row, shows through the kind in the pane it + // lands in. The client idle meanwhile: its copy taken ahead, each + // unit replayed on top of it. + const At = struct { + fn sessionView(au: *Authority) void { + const was = Stepping.begin(&au.t, null); + au.core.toView(.at(0)); + was.end(); + } + }; + At.sessionView(a); + for (" ffp") |c| { + r.ready(); + r.confirm(try a.local(.{ .key = .{ .cp = c, .text = &.{c} } })); + r.ready(); + r.confirm(try a.local(.tick)); + } + const landing = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.addon != null) break id; + } else return error.NoPreview; + try std.testing.expect(r.core().panes[landing].?.addon != null); + // A key of the client's own on top, and the session's own key + // first: the client back to its copy, the units since replayed. + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + try key(r, 'j', &sent); + try std.testing.expectEqual(@as(usize, 1), r.applied); + const foreign = r.stats.foreign; + r.confirm(try a.local(.{ .key = .{ .cp = 'q', .text = "q" } })); + r.settle(); + try std.testing.expectEqual(foreign + 1, r.stats.foreign); + for (sent.items) |m| { + r.confirm(try a.take(m)); + r.settle(); + } + try agrees(a, r); + // Esc in the picker's view: the preview's state closed, the pane's + // own text back. + At.sessionView(a); + r.confirm(try a.local(.{ .key = .{ .cp = pardes.Key.escape } })); + r.settle(); + try agrees(a, r); + try std.testing.expect(r.core().panes[landing].?.addon == null); + } + try std.testing.expectEqual(@as(usize, 0), Owned.held()); +} |
