{"draft":null,"from":241,"to":242,"files":[{"path":"src/engine/graph.ts","added":32,"removed":0,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -612,6 +612,7 @@\n \t\t\tthis.#dependentsPages = storedLists<AtomId>(storage, \"dependents\");\n \t\t\tthis.#resolversPages = storedLists<AtomId>(storage, \"resolvers\");\n \t\t\tthis.#togetherPages = storedLists<TogetherLink>(storage, \"together\");\n+\t\t\tthis.#reasonsInPages = storedLists<AtomId>(storage, \"reasons-in\");\n \t\t\tthis.#fileAtomPages = storedLists<AtomId>(storage, \"file-atoms\");\n \t\t\tthis.#runStartPages = storedLists<number>(storage, \"run-starts\", (key) =>\n \t\t\t\tJSON.stringify([\"number\", Number(key)]),\n@@ -803,6 +804,16 @@\n \t#resolversPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n \t#together: StateMap<AtomId, TogetherLink[]> = new Map();\n \t#togetherPages: ReturnType<typeof storedLists<TogetherLink>> | undefined;\n+\t/** The atoms whose reasons point at each atom, in seq order, once each (abso Capacity). */\n+\t#reasonsIn = new Map<AtomId, AtomId[]>();\n+\t#reasonsInPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n+\t/** Whether a stored graph keeps reasons-in: from a fresh graph on, worked out when first needed. */\n+\t#reasonsInKnown: boolean | undefined;\n+\tget #reasonsInKept(): boolean {\n+\t\tif (!this.#storage) return true;\n+\t\tthis.#reasonsInKnown ??= this.#storage.read(\"reasons-in:meta\", \"kept\") === 1;\n+\t\treturn this.#reasonsInKnown;\n+\t}\n \t#fileAtoms: StateMap<string, AtomId[]> = new Map();\n \t#fileAtomPages: ReturnType<typeof storedLists<AtomId>> | undefined;\n \t/** First lines of runs (their n), by the node they were written after: a line's n, or -1 - a path's index. */\n@@ -1345,6 +1356,16 @@\n \t\telse yield* listOf(this.#resolvers.get(id));\n \t}\n \n+\t/**\n+\t * The atoms whose reasons point at this one, in seq order, once each; or undefined when a stored graph made before\n+\t * this index keeps none, and the caller looks at every atom (abso Capacity).\n+\t */\n+\treasonsTo(id: AtomId): readonly AtomId[] | undefined {\n+\t\tif (!this.#reasonsInKept) return undefined;\n+\t\tif (this.#reasonsInPages) return [...this.#reasonsInPages.values(id)];\n+\t\treturn this.#reasonsIn.get(id) ?? [];\n+\t}\n+\n \t/** `together` reasons touching this atom, in either direction. */\n \ttogetherLinks(id: AtomId): readonly TogetherLink[] {\n \t\treturn [...this.eachTogetherLink(id)];\n@@ -1546,6 +1567,8 @@\n \t\t}\n \t\tif (this.#storage && this.#atoms.length === 0 && this.#packFiles) {\n \t\t\tthis.#storage.write(\"file-lines:meta\", \"format\", 2);\n+\t\t\tthis.#storage.write(\"reasons-in:meta\", \"kept\", 1);\n+\t\t\tthis.#reasonsInKnown = true;\n \t\t\tthis.#formatKnown = 2;\n \t\t}\n \n@@ -1723,6 +1746,15 @@\n \t\t\tif (this.#fileAtomPages) this.#fileAtomPages.append(file, frozen.id);\n \t\t\telse pushIndex(this.#fileAtoms, file, frozen.id);\n \t\t}\n+\t\tif (this.#reasonsInKept) {\n+\t\t\tconst pointed = new Set<AtomId>();\n+\t\t\tfor (const r of frozen.reasons) {\n+\t\t\t\tif (pointed.has(r.to)) continue;\n+\t\t\t\tpointed.add(r.to);\n+\t\t\t\tif (this.#reasonsInPages) this.#reasonsInPages.append(r.to, frozen.id);\n+\t\t\t\telse pushIndex(this.#reasonsIn, r.to, frozen.id);\n+\t\t\t}\n+\t\t}\n \t\tfor (const r of frozen.reasons) {\n \t\t\tif (r.kind !== \"together\" || r.to === frozen.id) continue;\n "}],"unmatched":[]}