diff --git a/src/features/vcs/__tests__/graphReference.ts b/src/features/vcs/__tests__/graphReference.ts new file mode 100644 index 000000000..ab581bce9 --- /dev/null +++ b/src/features/vcs/__tests__/graphReference.ts @@ -0,0 +1,150 @@ +/** + * The dense-array lane layout `computeGraph` used before its lanes were kept sparsely, kept + * verbatim as the oracle for the differential tests: it scans every slot number per row. + */ +import { emptyGraphState, graphLayout } from "../graph"; +import type { GraphCommit, GraphRow, GraphSegment, GraphState, EdgeKind } from "../graph"; + +interface Lane { + id: string; + source?: string; + kind?: EdgeKind; + color: number; + dashed?: true; +} + +const firstFree = (lanes: Array) => { + const i = lanes.indexOf(null); + return i < 0 ? lanes.length : i; +}; + +const seg = (from: number, to: number, color: number, dashed?: boolean): GraphSegment => + dashed ? { from, to, color, dashed: true } : { from, to, color }; + +const laneOf = (id: string, color: number, dashed: boolean): Lane => + dashed ? { id, color, dashed: true } : { id, color }; + +/** + * Lays out `commits` (continuing from `state`, so pages can be appended). + * Each lane keeps its position while it lives; freed slots are reused. + */ +export function referenceComputeGraph( + commits: ReadonlyArray, + state: GraphState = emptyGraphState(), +): { rows: GraphRow[]; state: GraphState } { + const lanes = [...state.lanes]; + const track = commits.some((c) => c.refs !== undefined); + const positions = new Map(commits.map((c, i) => [c.id, i])); + const layout = graphLayout(commits); + const refAware = commits.some((c) => c.refs?.length); + const stableColor = (id: string, fallback: number) => { + if (!refAware) return fallback; + const index = positions.get(id); + const owner = index == null ? id : layout.owners[index]!; + let hash = 2166136261; + for (const char of owner) hash = Math.imul(hash ^ char.charCodeAt(0), 16777619); + return hash >>> 0; + }; + const describe = (s: GraphSegment, lane: Lane) => + track ? { ...s, edge: `${lane.source ?? ""}\0${lane.id}`, source: lane.source, kind: lane.kind } : s; + + let nextColor = state.nextColor; + const rows: GraphRow[] = []; + + for (const c of commits) { + const matching: number[] = []; + lanes.forEach((l, i) => { + if (l?.id === c.id) matching.push(i); + }); + let lane: number; + let color: number; + if (matching.length) { + lane = matching[0]!; + color = lanes[lane]!.color; + } else { + const preferred = refAware ? Math.max(0, layout.layout[positions.get(c.id)!]! - 1) : firstFree(lanes); + lane = !lanes[preferred] ? preferred : firstFree(lanes); + color = stableColor(c.id, nextColor++); + } + const widthBefore = lanes.length; + + const up: GraphSegment[] = []; + const upTargets: string[] = []; + lanes.forEach((l, i) => { + if (!l) return; + up.push(describe(seg(i, l.id === c.id ? lane : i, l.color, l.dashed), l)); + upTargets.push(l.id); + }); + for (const m of matching) lanes[m] = null; + if (lane >= lanes.length) lanes.length = lane + 1; + lanes[lane] = null; + + const down: GraphSegment[] = []; + const downTargets: string[] = []; + lanes.forEach((l, i) => { + if (l) { + down.push(describe(seg(i, i, l.color, l.dashed), l)); + downTargets.push(l.id); + } + }); + + c.parents.forEach((p, k) => { + const dashed = !!c.dashed?.[k]; + const kind = c.edgeTypes?.[k] ?? (dashed ? "filtered" : "normal"); + const info = { + id: p, + source: c.id, + kind: !positions.has(p) && kind !== "shallow" ? ("unloaded" as const) : kind, + }; + if (track && kind === "shallow") { + down.push({ + ...describe(seg(lane, lane, color, dashed), { ...info, color }), + kind: kind === "shallow" ? "shallow" : "unloaded", + arrow: "down", + targetRow: -1, + }); + downTargets.push(p); + return; + } + // The first parent continues this lane even if another lane also leads to it + // (both lines then converge at the parent's node, like `git log --graph`). + if (k === 0) { + lanes[lane] = { ...laneOf(p, color, dashed), ...info }; + down.push(describe(seg(lane, lane, color, dashed), { ...info, color })); + downTargets.push(p); + return; + } + const existing = lanes.findIndex((l) => l?.id === p); + if (existing >= 0) { + down.push( + describe(seg(lane, existing, lanes[existing]!.color, dashed), { ...info, color: lanes[existing]!.color }), + ); + downTargets.push(p); + return; + } + const slot = firstFree(lanes); + const col = stableColor(p, nextColor++); + lanes[slot] = { ...laneOf(p, col, dashed), ...info }; + down.push(describe(seg(lane, slot, col, dashed), { ...info, color: col })); + downTargets.push(p); + }); + + while (lanes.length && lanes[lanes.length - 1] === null) lanes.pop(); + const widthAfter = down.reduce((width, segment) => Math.max(width, segment.to + 1), 0); + rows.push({ + ...(track ? { id: c.id } : {}), + lane, + color, + up, + down, + upTargets, + downTargets, + width: Math.max(widthBefore, widthAfter, lane + 1), + }); + } + if (track && rows.length) { + const last = rows.at(-1)!; + last.down = last.down.map((s) => (s.kind === "unloaded" ? { ...s, arrow: "down", targetRow: -1 } : s)); + } + return { rows, state: { lanes, nextColor } }; +} diff --git a/src/features/vcs/__tests__/logGraphEquivalence.test.ts b/src/features/vcs/__tests__/logGraphEquivalence.test.ts new file mode 100644 index 000000000..bc4c4eeeb --- /dev/null +++ b/src/features/vcs/__tests__/logGraphEquivalence.test.ts @@ -0,0 +1,183 @@ +import type { Commit } from "@/bindings"; +import { afterEach, describe, expect, it, vi } from "vitest"; + +vi.mock("../graph", async (original) => { + const real = await original(); + return { ...real, computeGraph: vi.fn(real.computeGraph) }; +}); + +import { computeGraph, type GraphCommit } from "../graph"; +import { presentLogGraph, type GraphOptions } from "../logPresentation"; +import { commitKey, graphCommit } from "../multiRoot"; +import { referenceComputeGraph } from "./graphReference"; + +const { computeGraph: real } = await vi.importActual("../graph"); + +const id = (i: number) => `c${i.toString(16).padStart(6, "0")}`; + +/** + * A deterministic history in log order (children before parents): up to eight branches + * that fork, merge (some with a filtered edge) and carry refs, cut off at `count` commits so + * that the oldest ones lead to parents that are not loaded. + */ +function history(count: number, withRefs: boolean): Commit[] { + let seed = 7; + const rnd = () => (seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff; + const total = count + 40; + const tips: number[] = [0]; + const parents: number[][] = [[]]; + const dashed = new Map(); + for (let i = 1; i < total; i++) { + const r = rnd(); + const h = Math.floor(rnd() * tips.length); + if (r < 0.06 && tips.length < 8) { + parents.push([tips[h]!]); + tips.push(i); + } else if (r < 0.14 && tips.length > 1) { + const other = (h + 1) % tips.length; + parents.push([tips[h]!, tips[other]!]); + if (rnd() < 0.3) dashed.set(i, [false, true]); + tips[h] = i; + tips.splice(other, 1); + } else { + parents.push([tips[h]!]); + tips[h] = i; + } + } + const commits: Commit[] = []; + for (let i = total - 1; i >= 40; i--) { + const refs: string[] = []; + if (withRefs) { + if (i === total - 1) refs.push("HEAD", "main"); + else if (i % 211 === 0) refs.push(`tag: v${i}`); + else if (i % 97 === 0) refs.push(`feature-${i}`); + else if (i % 151 === 0) refs.push(`origin/topic-${i}`); + } + commits.push({ + id: id(i), + shortId: id(i), + parents: parents[i]!.map(id), + ...(dashed.has(i) ? { dashed: dashed.get(i)! } : {}), + author: "A", + email: "a@x.org", + summary: id(i), + message: id(i), + timeMs: i, + refs, + remoteNames: refs.filter((r) => r.startsWith("origin/")), + } as Commit); + } + return commits; +} + +const noFragments = () => ({ expanded: new Set(), collapsed: new Set(), merges: new Set() }); + +function fragmentVariants(commits: readonly Commit[]) { + const linear = commits.filter((c) => c.parents.length === 1 && !c.refs.length).map((c) => c.id); + const merges = commits.filter((c) => c.parents.length === 2).map((c) => c.id); + const every = (ids: string[], n: number) => new Set(ids.filter((_, i) => i % n === 0)); + return { + none: noFragments(), + collapsed: { ...noFragments(), collapsed: every(linear, 7) }, + expandedLinear: { ...noFragments(), expanded: every(linear, 5), merges: every(merges, 3) }, + someMerges: { ...noFragments(), merges: every(merges, 2) }, + allMerges: { ...noFragments(), merges: new Set(["*"]) }, + }; +} + +afterEach(() => vi.mocked(computeGraph).mockImplementation(real)); + +describe("computeGraph lane slots", () => { + const pages = (commits: readonly Commit[], size: number) => { + const source = commits.map(graphCommit); + return Array.from({ length: Math.ceil(source.length / size) }, (_, i) => source.slice(i * size, (i + 1) * size)); + }; + + it.each([true, false])("lays out page by page exactly like the dense lane array (refs: %s)", (withRefs) => { + let state = { lanes: [] as ReturnType["state"]["lanes"], nextColor: 0 }; + let expected = state; + // Pages are laid out on their own, so the loaded part of the log is each page itself. + for (const page of pages(history(2400, withRefs), 300)) { + const got = real(page, state); + const want = referenceComputeGraph(page, expected); + expect(got.rows).toEqual(want.rows); + expect(got.state).toEqual(want.state); + expect(got.state.lanes.length).toBe(want.state.lanes.length); + state = got.state; + expected = want.state; + } + }); + + it("continues from a state with vacated, occupied and never-used slots", () => { + const lanes: Array<{ id: string; color: number } | null> = []; + lanes[1] = { id: "b", color: 3 }; + lanes[4] = null; + lanes[6] = { id: "d", color: 5 }; + const commits: GraphCommit[] = [ + { id: "a", parents: ["b", "e"] }, + { id: "e", parents: ["d"] }, + { id: "b", parents: ["d"] }, + { id: "d", parents: [] }, + ]; + const got = real(commits, { lanes: [...lanes], nextColor: 9 }); + const want = referenceComputeGraph(commits, { lanes: [...lanes], nextColor: 9 }); + expect(got).toEqual(want); + }); + + it("scans a number of lane slots per row that does not depend on the highest slot number", () => { + const chain = (rows: number): GraphCommit[] => + Array.from({ length: rows }, (_, i) => ({ + id: `n${i}`, + parents: [i + 1 < rows ? `n${i + 1}` : "base"], + refs: i === 0 ? ["main"] : [], + })); + /** Array elements the scans of one `computeGraph` call go over, with a lane at slot 30 000. */ + const scanned = (rows: number) => { + const lanes: Array<{ id: string; color: number } | null> = []; + lanes[30_000] = { id: "base", color: 1 }; + const names = ["forEach", "indexOf", "findIndex", "filter", "some", "map", "reduce", "includes"] as const; + const original = new Map(names.map((n) => [n, Array.prototype[n]])); + let visited = 0; + for (const n of names) + Object.defineProperty(Array.prototype, n, { + configurable: true, + writable: true, + value(this: unknown[], ...args: unknown[]) { + visited += this.length; + return (original.get(n) as (...a: unknown[]) => unknown).apply(this, args); + }, + }); + try { + real(chain(rows), { lanes, nextColor: 0 }); + } finally { + for (const n of names) + Object.defineProperty(Array.prototype, n, { configurable: true, writable: true, value: original.get(n) }); + } + return visited; + }; + // Reading the given state costs once per call; each further row may only scan its live lanes. + expect((scanned(400) - scanned(100)) / 300).toBeLessThan(100); + }); +}); + +describe("presentLogGraph", () => { + const optionCombinations: GraphOptions[] = [false, true].flatMap((collapseLinear) => + [false, true].flatMap((linearizeMerges) => + [false, true].map((longEdges) => ({ collapseLinear, linearizeMerges, longEdges })), + ), + ); + + it.each([true, false])("keeps every option and fragment combination unchanged (refs: %s)", (withRefs) => { + const commits = history(2400, withRefs); + const head = new Set([commitKey(commits[0]!)]); + const variants = fragmentVariants(commits); + for (const options of optionCombinations) + for (const [name, fragments] of Object.entries(variants)) { + vi.mocked(computeGraph).mockImplementation(real); + const got = presentLogGraph(commits, options, fragments, head); + vi.mocked(computeGraph).mockImplementation(referenceComputeGraph); + const want = presentLogGraph(commits, options, fragments, head); + expect(got, `${JSON.stringify(options)} ${name}`).toEqual(want); + } + }); +}); diff --git a/src/features/vcs/__tests__/logUiFeatures.test.tsx b/src/features/vcs/__tests__/logUiFeatures.test.tsx index f45f8407f..b25cb409a 100644 --- a/src/features/vcs/__tests__/logUiFeatures.test.tsx +++ b/src/features/vcs/__tests__/logUiFeatures.test.tsx @@ -34,6 +34,7 @@ import { LogScope } from "../LogScope"; import { CommitDetails } from "../log/CommitDetails"; import { DEFAULT_LOG_OPTIONS, useLogOptions } from "../logOptions"; import { emptyFilters, openLogTab, reloadLog, selectGitTab, useGitLog } from "../logStore"; +import * as logPresentation from "../logPresentation"; import { commitKey } from "../multiRoot"; import { useVcs } from "../store"; @@ -149,6 +150,24 @@ describe("log controls", () => { expect(screen.getByRole("status")).toHaveTextContent("b"); }); + it("lays the graph out again only for the options that shape it", async () => { + const present = vi.spyOn(logPresentation, "presentLogGraph"); + render(); + const list = await screen.findByRole("listbox", { name: "Commits" }); + await waitFor(() => expect(within(list).getAllByRole("option")).toHaveLength(3)); + const laidOut = () => present.mock.calls.length; + const before = laidOut(); + + act(() => useLogOptions.setState({ showAuthor: false, columnWidths: { author: 200 } })); + expect(laidOut()).toBe(before); + + act(() => useLogOptions.setState({ longEdges: true })); + expect(laidOut()).toBe(before + 1); + + act(() => useGitLog.setState({ commits: [...useGitLog.getState().commits, c("older")] })); + expect(laidOut()).toBe(before + 2); + }); + it("hides the column headers unless View Options shows them", async () => { render(); await screen.findByRole("listbox", { name: "Commits" }); diff --git a/src/features/vcs/graph.ts b/src/features/vcs/graph.ts index ce860dcbc..0dc0989b9 100644 --- a/src/features/vcs/graph.ts +++ b/src/features/vcs/graph.ts @@ -67,17 +67,109 @@ export interface GraphCommit { export const emptyGraphState = (): GraphState => ({ lanes: [], nextColor: 0 }); -const firstFree = (lanes: Array) => { - const i = lanes.indexOf(null); - return i < 0 ? lanes.length : i; -}; - const seg = (from: number, to: number, color: number, dashed?: boolean): GraphSegment => dashed ? { from, to, color, dashed: true } : { from, to, color }; const laneOf = (id: string, color: number, dashed: boolean): Lane => dashed ? { id, color, dashed: true } : { id, color }; +/** Inserts `value` into the ascending `list` (no-op if present). */ +function insertSorted(list: number[], value: number) { + let lo = 0; + let hi = list.length; + while (lo < hi) { + const mid = (lo + hi) >>> 1; + if (list[mid]! < value) lo = mid + 1; + else hi = mid; + } + if (list[lo] !== value) list.splice(lo, 0, value); +} + +function removeSorted(list: number[], value: number) { + let lo = 0; + let hi = list.length; + while (lo < hi) { + const mid = (lo + hi) >>> 1; + if (list[mid]! < value) lo = mid + 1; + else hi = mid; + } + if (list[lo] === value) list.splice(lo, 1); +} + +/** + * The lane slots of the layout. A lane may sit at a high slot number (the preferred lane of + * a commit is its branch's layout number, which grows with the log), so the slots are kept + * sparsely: a row then costs the number of live lanes, not the highest slot number. + * A slot is a lane, `null` (vacated: the next free slot, see {@link firstFree}) or absent + * (never used, which counts as unoccupied but is not offered as the next free slot). + */ +class LaneSlots { + /** Slot count (the highest slot ever extended to, less trimmed vacated tail slots). */ + length: number; + private readonly slots = new Map(); + /** Slot numbers holding a lane, ascending. */ + private readonly live: number[] = []; + /** Slot numbers holding `null`, ascending. */ + private readonly vacated: number[] = []; + + constructor(initial: ReadonlyArray) { + this.length = initial.length; + initial.forEach((lane, i) => { + if (lane === undefined) return; + this.slots.set(i, lane); + (lane ? this.live : this.vacated).push(i); + }); + } + + get(i: number): Lane | null | undefined { + return this.slots.get(i); + } + + /** Lanes in slot order. */ + forEachLane(fn: (lane: Lane, slot: number) => void) { + for (const i of this.live) fn(this.slots.get(i) as Lane, i); + } + + /** Slots of the lanes leading to `id`, in slot order. */ + slotsOf(id: string): number[] { + return this.live.filter((i) => (this.slots.get(i) as Lane).id === id); + } + + /** The first vacated slot, else one past the last. */ + firstFree(): number { + return this.vacated.length ? this.vacated[0]! : this.length; + } + + vacate(i: number) { + if (i >= this.length) this.length = i + 1; + removeSorted(this.live, i); + this.slots.set(i, null); + insertSorted(this.vacated, i); + } + + set(i: number, lane: Lane) { + if (i >= this.length) this.length = i + 1; + removeSorted(this.vacated, i); + insertSorted(this.live, i); + this.slots.set(i, lane); + } + + /** Drops vacated slots at the end. */ + trim() { + while (this.length && this.slots.get(this.length - 1) === null) { + this.vacated.pop(); + this.slots.delete(this.length - 1); + this.length--; + } + } + + toArray(): Array { + const out = new Array(this.length); + for (const [i, lane] of this.slots) out[i] = lane; + return out; + } +} + /** * Lays out `commits` (continuing from `state`, so pages can be appended). * Each lane keeps its position while it lives; freed slots are reused. @@ -86,7 +178,7 @@ export function computeGraph( commits: ReadonlyArray, state: GraphState = emptyGraphState(), ): { rows: GraphRow[]; state: GraphState } { - const lanes = [...state.lanes]; + const lanes = new LaneSlots(state.lanes); const track = commits.some((c) => c.refs !== undefined); const positions = new Map(commits.map((c, i) => [c.id, i])); const layout = graphLayout(commits); @@ -106,40 +198,33 @@ export function computeGraph( const rows: GraphRow[] = []; for (const c of commits) { - const matching: number[] = []; - lanes.forEach((l, i) => { - if (l?.id === c.id) matching.push(i); - }); + const matching = lanes.slotsOf(c.id); let lane: number; let color: number; if (matching.length) { lane = matching[0]!; - color = lanes[lane]!.color; + color = lanes.get(lane)!.color; } else { - const preferred = refAware ? Math.max(0, layout.layout[positions.get(c.id)!]! - 1) : firstFree(lanes); - lane = !lanes[preferred] ? preferred : firstFree(lanes); + const preferred = refAware ? Math.max(0, layout.layout[positions.get(c.id)!]! - 1) : lanes.firstFree(); + lane = !lanes.get(preferred) ? preferred : lanes.firstFree(); color = stableColor(c.id, nextColor++); } const widthBefore = lanes.length; const up: GraphSegment[] = []; const upTargets: string[] = []; - lanes.forEach((l, i) => { - if (!l) return; + lanes.forEachLane((l, i) => { up.push(describe(seg(i, l.id === c.id ? lane : i, l.color, l.dashed), l)); upTargets.push(l.id); }); - for (const m of matching) lanes[m] = null; - if (lane >= lanes.length) lanes.length = lane + 1; - lanes[lane] = null; + for (const m of matching) lanes.vacate(m); + lanes.vacate(lane); const down: GraphSegment[] = []; const downTargets: string[] = []; - lanes.forEach((l, i) => { - if (l) { - down.push(describe(seg(i, i, l.color, l.dashed), l)); - downTargets.push(l.id); - } + lanes.forEachLane((l, i) => { + down.push(describe(seg(i, i, l.color, l.dashed), l)); + downTargets.push(l.id); }); c.parents.forEach((p, k) => { @@ -163,27 +248,30 @@ export function computeGraph( // The first parent continues this lane even if another lane also leads to it // (both lines then converge at the parent's node, like `git log --graph`). if (k === 0) { - lanes[lane] = { ...laneOf(p, color, dashed), ...info }; + lanes.set(lane, { ...laneOf(p, color, dashed), ...info }); down.push(describe(seg(lane, lane, color, dashed), { ...info, color })); downTargets.push(p); return; } - const existing = lanes.findIndex((l) => l?.id === p); + const existing = lanes.slotsOf(p)[0] ?? -1; if (existing >= 0) { down.push( - describe(seg(lane, existing, lanes[existing]!.color, dashed), { ...info, color: lanes[existing]!.color }), + describe(seg(lane, existing, lanes.get(existing)!.color, dashed), { + ...info, + color: lanes.get(existing)!.color, + }), ); downTargets.push(p); return; } - const slot = firstFree(lanes); + const slot = lanes.firstFree(); const col = stableColor(p, nextColor++); - lanes[slot] = { ...laneOf(p, col, dashed), ...info }; + lanes.set(slot, { ...laneOf(p, col, dashed), ...info }); down.push(describe(seg(lane, slot, col, dashed), { ...info, color: col })); downTargets.push(p); }); - while (lanes.length && lanes[lanes.length - 1] === null) lanes.pop(); + lanes.trim(); const widthAfter = down.reduce((width, segment) => Math.max(width, segment.to + 1), 0); rows.push({ ...(track ? { id: c.id } : {}), @@ -200,7 +288,7 @@ export function computeGraph( const last = rows.at(-1)!; last.down = last.down.map((s) => (s.kind === "unloaded" ? { ...s, arrow: "down", targetRow: -1 } : s)); } - return { rows, state: { lanes, nextColor } }; + return { rows, state: { lanes: lanes.toArray(), nextColor } }; } /** diff --git a/src/features/vcs/log/CommitList.tsx b/src/features/vcs/log/CommitList.tsx index dbdb53c05..d9a84c04a 100644 --- a/src/features/vcs/log/CommitList.tsx +++ b/src/features/vcs/log/CommitList.tsx @@ -158,12 +158,14 @@ export function CommitList({ fileHistory = false }: { fileHistory?: boolean }) { ), [all, heads, headCommit], ); + // Only these options shape the graph: resizing a column or toggling the author must not lay it out again. + const { collapseLinear, linearizeMerges, longEdges } = opts; const keep = useMemo( () => - opts.collapseLinear || fragments.collapsed.size + collapseLinear || fragments.collapsed.size ? new Set([...headKeys, ...selection, ...Object.keys(bookmarks)]) : null, - [opts.collapseLinear, fragments.collapsed, headKeys, selection, bookmarks], + [collapseLinear, fragments.collapsed, headKeys, selection, bookmarks], ); const { commits, @@ -171,7 +173,10 @@ export function CommitList({ fileHistory = false }: { fileHistory?: boolean }) { linear, collapsed, graph: displayedGraph, - } = useMemo(() => presentLogGraph(all, opts, fragments, keep ?? new Set()), [all, opts, fragments, keep]); + } = useMemo( + () => presentLogGraph(all, { collapseLinear, linearizeMerges, longEdges }, fragments, keep ?? new Set()), + [all, collapseLinear, linearizeMerges, longEdges, fragments, keep], + ); const { edges: highlighted, nodes: highlightedNodes } = useMemo(() => { const empty = { edges: new Set(), nodes: new Set() }; if (!hoverColor) return empty; diff --git a/src/features/vcs/logPresentation.ts b/src/features/vcs/logPresentation.ts index 680ce1944..164261808 100644 --- a/src/features/vcs/logPresentation.ts +++ b/src/features/vcs/logPresentation.ts @@ -10,10 +10,13 @@ import { import { commitKey, graphCommit, type RepoCommit } from "./multiRoot"; import type { LogOptions } from "./logOptions"; +/** The options that shape the displayed graph; every other option leaves it as it is. */ +export type GraphOptions = Pick; + /** The same displayed adjacency drives painting, navigation and fragment actions. */ export function presentLogGraph( all: readonly RepoCommit[], - options: LogOptions, + options: GraphOptions, fragments: { expanded: ReadonlySet; collapsed: ReadonlySet; merges: ReadonlySet }, keep: ReadonlySet, ) {