diff options
Diffstat (limited to 'src/dump.zig')
| -rw-r--r-- | src/dump.zig | 75 |
1 files changed, 68 insertions, 7 deletions
diff --git a/src/dump.zig b/src/dump.zig index 517544fa..a880c7e1 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -747,6 +747,7 @@ pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane { const SlotRecord = struct { name: []const u8 = "", version: u32 = 0, + gen: u32 = 0, path: []const u8 = "", where: []const u8 = "", art: @import("surface.zig").Placement.Art = .{}, @@ -774,7 +775,7 @@ const SlotRecord = struct { pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) !void { var place: [32]u8 = undefined; - var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .cancelled = s.cancelled, .prefix = s.prefix.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection }; + var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .gen = s.gen, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .cancelled = s.cancelled, .prefix = s.prefix.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection }; var owned: ?[]u8 = null; defer if (owned) |o| s.gpa.free(o); if (s.ops != null) { @@ -806,7 +807,7 @@ pub fn slotRead(out: *Kind.Slot, gpa: std.mem.Allocator, bytes: []const u8) !voi var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); const r = try walk.load(SlotRecord, arena.allocator(), bytes, null); - out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .art = r.art, .live = r.live, .next_tick = r.next_tick, .views = r.views, .focused = r.focused, .cancelled = r.cancelled }; + out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .gen = r.gen, .art = r.art, .live = r.live, .next_tick = r.next_tick, .views = r.views, .focused = r.focused, .cancelled = r.cancelled }; errdefer out.free(); @memcpy(out.name[0..@min(15, r.name.len)], r.name[0..@min(15, r.name.len)]); out.path = try gpa.dupe(u8, r.path); @@ -844,11 +845,14 @@ pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void { if (!Kind.reopen(p, id, s, bytes)) { s.ops = null; s.live = false; - } else if (s.ops == null) { - // A replica's Shadow is the authority's pane as it is: it ticks - // when that one does, not because it was loaded (a kind opened - // here ticks to lay itself out). - s.next_tick, s.views, s.focused = kept; + } else { + s.version = p.kinds.kinds[k].version; + if (s.ops == null) { + // A replica's Shadow is the authority's pane as it is: it ticks + // when that one does, not because it was loaded (a kind opened + // here ticks to lay itself out). + s.next_tick, s.views, s.focused = kept; + } } } @@ -1125,3 +1129,60 @@ test "an old dump's file, a byte dump, is read by -l and by a Restore of its pat defer gpa.free(again); try std.testing.expectEqualSlices(u8, bytes, again); } + +test "restored syntax context caches are rebuilt rather than loaded with the core allocator" { + const gpa = std.testing.allocator; + var syntax_gpa: std.heap.DebugAllocator(.{}) = .init; + defer std.testing.expect(syntax_gpa.deinit() == .ok) catch @panic("syntax allocator leaked"); + const opts: Pardes.Options = .{ .tty_only = true, .tree_sitter_allocator = syntax_gpa.allocator() }; + const p = try Pardes.init(gpa, opts); + defer p.deinit(); + const pane = try p.setTestFile("fn example() void {}\n"); + const f = &pane.file.?; + const declarations = try p.tree_sitter_gpa.alloc(pardes.syntax.ContextDeclaration, 1); + @memset(std.mem.sliceAsBytes(declarations), 0); + f.context.replace(p.tree_sitter_gpa, declarations, f.revision); + // Older builds persisted these two fields; the schema reader must skip them too. + const OldFile = struct { + path: []const u8, + content: []const u8, + history: *pardes.panes.File.History, + context_declarations: []pardes.syntax.ContextDeclaration, + context_revision: ?u32, + }; + const old_bytes = try walk.save(OldFile, gpa, &.{ + .path = f.path, + .content = f.content, + .history = f.history, + .context_declarations = f.context.declarations, + .context_revision = f.context.revision, + }); + defer gpa.free(old_bytes); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const old = try walk.load(pardes.panes.File.State, arena.allocator(), old_bytes, null); + try std.testing.expectEqual(@as(usize, 0), old.context.declarations.len); + try std.testing.expectEqual(@as(?u32, null), old.context.revision); + const bytes = try dumpBytes(p); + defer gpa.free(bytes); + const q = try load(gpa, opts, bytes, null); + defer q.deinit(); + for (q.panes) |slot| if (slot) |restored| if (restored.file) |file| { + try std.testing.expectEqual(@as(usize, 0), file.context.declarations.len); + try std.testing.expectEqual(@as(?u32, null), file.context.revision); + }; +} + +test "optional GPU addon reload generation survives a replica dump" { + const gpa = std.testing.allocator; + var original: Kind.Slot = .{ .gpa = gpa, .arena = .init(gpa), .gen = 7, .live = true }; + defer original.free(); + var bytes: std.Io.Writer.Allocating = .init(gpa); + defer bytes.deinit(); + try slotWrite(&original, gpa, &bytes.writer); + var restored: Kind.Slot = undefined; + try slotRead(&restored, gpa, bytes.written()); + defer restored.free(); + try std.testing.expectEqual(original.gen, restored.gen); + try std.testing.expectEqual(walk.digest(Kind.Slot, &original), walk.digest(Kind.Slot, &restored)); +} |
