diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 16:12:18 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 16:23:31 -0300 |
| commit | e4bda7e899089b0c8594ad1b03099402bddeeef1 (patch) | |
| tree | 2972000d9c446cf51088b610610105fa5430a082 /core/Query.zig | |
| parent | d3f9f3775e2efbcb4d617afb4a18eaf5efa72e29 (diff) | |
| download | pardes-e4bda7e899089b0c8594ad1b03099402bddeeef1.tar.gz pardes-e4bda7e899089b0c8594ad1b03099402bddeeef1.zip | |
Query rows: what a step asks a worker to paint no longer hangs on the colours this process happens to have: the bytes soak's 'the core called search where the tape has a host' (g6, seed 5 at 80 ms, the witness parting at the session's own step) was a query row's colours read by the step that decides whether to ask a worker for its file's paint (Stream.paintRows, an effect on the tape): Query.writePlacesRows (Query.zig:1073) took a `/` row's colours from the owner's frame paint (File.highlights, painted by refreshHighlights, derived) and only a row left plain went to Shades.of, which asked; Shades.of asked only on a miss in the locations cache (derived: a dump carries none, so a client joined since has none); recolor asked only for rows whose colours were still zeros (derived); so a session that had drawn its owner, or had the file's colours from an earlier paint, asked nothing where a replica that never draws, or a client joined since, asked a worker (and its stream.rows_count, rows_paint, rows_asked, rows_asked_at moved on one side only: the four fields the witness named); FIRST the tests (core/replica.zig, a session whose host paints on workers): 'a client joined from a dump asks a worker for a `/` query's colours as the session does, though only the session has drawn its owner' and '... though only the session has them from an earlier paint', both on the base 'diverged: the core called search where the tape has a done (0)'; then the fix: Shades asks for every file its rows show (Shades.file at every row, whatever colours it has; Shades.done at the file's end and each walk's), paintRows decides on replicated state alone (the row ring, the pending paint, the pane's text), its key the path's hash (a file is painted once between two Greps, not again at each revision of an open text, which a frame paints where it is seen); a row's colours still come from the frame's paint and the cache, out of the rows' digest as before; root.zig's kept_out lines for highlights and locations_cache say so
Diffstat (limited to 'core/Query.zig')
| -rw-r--r-- | core/Query.zig | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/core/Query.zig b/core/Query.zig index ebb44155..f0e9ee1a 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -888,6 +888,7 @@ fn writeHitRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locatio if (gutter + code.len > buf.len) return; @memset(buf[address.len..gutter], ' '); @memcpy(buf[gutter..][0..code.len], code); + sh.file(p, path); try writeRow(p, out, rows, buf[0 .. gutter + code.len], .{ .kind = .match, .source_column = lead, @@ -895,16 +896,16 @@ fn writeHitRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locatio .at = .{ .line = line_no, .col = col + 1, .end_line = line_no, .end_col = @max(col + 1, end) }, .location_end = address.len, .code_start = gutter, - .colors = @constCast(if (shade.len >= lead + code.len) shade[lead..][0..code.len] else sh.of(p, path, line_no, code, lead)), + .colors = @constCast(if (shade.len >= lead + code.len) shade[lead..][0..code.len] else sh.of(line_no, code, lead)), }); } /// Rows' syntax colours from their file's whole (as Callstack's rows are), /// kept in the locations cache once a worker has painted it /// (Stream.paintRows): the line found going down the file a row at a time, -/// so a refill walks each file once. A file not painted, or whose line no -/// longer reads as the row does, is asked for (once a refill) and its rows -/// are plain till it lands (`recolor`). +/// so a refill walks each file once. Every file is asked for once its rows +/// are made (`file`, `done`; Stream.paintRows asks each once a Grep), and +/// a row it does not colour is plain till it lands (`recolor`). const Shades = struct { path: []const u8 = "", source: []const u8 = "", @@ -912,50 +913,54 @@ const Shades = struct { /// The line (1-based) that starts at `at` in `source`. line: usize = 1, at: usize = 0, - asked: bool = false, - /// The colours of `code`, which is line `line_no` of `path` from byte - /// `column` on, or none. - fn of(sh: *Shades, p: *Pardes, path: []const u8, line_no: usize, code: []const u8, column: usize) []const u8 { - if (path.len == 0 or line_no == 0 or code.len == 0) return &.{}; - if (!std.mem.eql(u8, path, sh.path)) { - // its own copy: a caller's path is often a buffer it reuses - sh.* = .{ .path = p.scratch.allocator().dupe(u8, path) catch return &.{} }; - if (p.locations_cache.peek(path)) |e| { - sh.source = e.source; - sh.colors = e.colors; - } + /// The rows of `path` follow (a caller's buffer: copied): the file + /// before them done. Called for every row, whatever colours it has, so + /// that every process asks paintRows at the same rows. + fn file(sh: *Shades, p: *Pardes, path: []const u8) void { + if (std.mem.eql(u8, path, sh.path)) return; + sh.done(p); + sh.* = .{ .path = p.scratch.allocator().dupe(u8, path) catch "" }; + if (p.locations_cache.peek(path)) |e| { + sh.source = e.source; + sh.colors = e.colors; } - if (sh.colors.len == 0 or sh.colors.len != sh.source.len) return sh.ask(p); + } + + /// The file's rows are made: its colours asked of a worker. + fn done(sh: *Shades, p: *Pardes) void { + if (sh.path.len > 0) Stream.paintRows(p, sh.path); + } + + /// The colours of `code`, which is line `line_no` of the file `file` + /// named from byte `column` on, or none. + fn of(sh: *Shades, line_no: usize, code: []const u8, column: usize) []const u8 { + if (sh.path.len == 0 or line_no == 0 or code.len == 0) return &.{}; + if (sh.colors.len == 0 or sh.colors.len != sh.source.len) return &.{}; if (line_no < sh.line) { sh.line = 1; sh.at = 0; } while (sh.line < line_no) : (sh.line += 1) { - sh.at = (std.mem.indexOfScalarPos(u8, sh.source, sh.at, '\n') orelse return sh.ask(p)) + 1; + sh.at = (std.mem.indexOfScalarPos(u8, sh.source, sh.at, '\n') orelse return &.{}) + 1; } const line = sh.source[sh.at .. std.mem.indexOfScalarPos(u8, sh.source, sh.at, '\n') orelse sh.source.len]; - if (column + code.len > line.len or !std.mem.eql(u8, line[column..][0..code.len], code)) return sh.ask(p); + if (column + code.len > line.len or !std.mem.eql(u8, line[column..][0..code.len], code)) return &.{}; return sh.colors[sh.at + column ..][0..code.len]; } - - fn ask(sh: *Shades, p: *Pardes) []const u8 { - if (!sh.asked) Stream.paintRows(p, sh.path); - sh.asked = true; - return &.{}; - } }; /// A file's colours arrived (Stream.paintRows): every query pane's hit /// rows still plain, live or frozen, coloured from what is painted now, in -/// place; the first row of a file not painted yet asks for it, so they are -/// painted one after another. +/// place; the next file not asked yet is asked for, so they are painted +/// one after another. pub fn recolor(p: *Pardes) void { for (p.panes) |slot| { const rp = slot orelse continue; if (rp.query == null) continue; const f = &rp.file.?; var sh: Shades = .{}; + defer sh.done(p); var lines = std.mem.splitScalar(u8, f.content, '\n'); // The rows are a blob (File.State): a digest keeps its word for // them and a rollback copy pins them, so they are made again, never @@ -967,9 +972,10 @@ pub fn recolor(p: *Pardes) void { for (f.location_rows, 0..) |row, i| { const text = lines.next() orelse break; if (row.kind != .match or row.location_end == 0 or row.at.line == 0 or row.colors.len == 0) continue; + sh.file(p, row.path); if (std.mem.indexOfNone(u8, row.colors, &.{0}) != null) continue; const code = text[@min(row.code_start, text.len)..]; - const got = sh.of(p, row.path, row.at.line, code[0..@min(code.len, row.colors.len)], row.source_column); + const got = sh.of(row.at.line, code[0..@min(code.len, row.colors.len)], row.source_column); if (got.len == 0) continue; const rows = fresh orelse locations.cloneRows(p.gpa, f.location_rows) catch break; fresh = rows; @@ -1027,6 +1033,7 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar const rel = lookPath(&relbuf, path, dir); const width = addressWidth(rel, index.len); var sh: Shades = .{}; + defer sh.done(p); const decls = ownerDecls(f) orelse &.{}; var decl_now: ?usize = null; var i: usize = @min(from, hits.len); @@ -1182,6 +1189,7 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void { } var current: ?usize = null; var sh: Shades = .{}; + defer sh.done(p); var width: usize = 0; var relbuf: [4096]u8 = undefined; for (q.found.items[lo..hi], lo..) |fd, i| { @@ -1342,6 +1350,7 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { var pathbuf: [4096 + 8]u8 = undefined; var n: usize = 0; var sh: Shades = .{}; + defer sh.done(p); var width: usize = 0; var relbuf: [4096]u8 = undefined; for (sorted.items, 0..) |ln, li| { |
