reflex-quant 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/graph.ts", "../src/kernel.ts", "../src/host.ts", "../src/index.ts"],
4
- "sourcesContent": ["import { stats } from \"./instrumentation\";\n\n// Compile-time vocabulary of the runtime graph. Nothing here exists at runtime.\n\n// The aliases name different facts but do not brand numbers: counters wrap at\n// MASK and edge versions can carry UNREAD.\nexport type Flags = number;\nexport type Version = number;\nexport type Generation = number;\n\n/** A computed's or watcher's body; a signal has none. */\nexport type Fn = (prev: unknown) => unknown;\n/** A watcher's cleanup, run untracked. */\nexport type Cleanup = () => unknown;\n\nexport interface Node {\n flags: Flags;\n value: unknown;\n /** Bumps on every Object.is-visible change of value. */\n ver: Version;\n /** null for a signal and for a disposed node. */\n fn: Fn | null;\n /** Sources, in read order. */\n deps: Edge | null;\n /** The running pass's last accepted source edge. */\n last: Edge | null;\n /** Subscribers, in birth order. */\n subs: Edge | null;\n lastSub: Edge | null;\n /** While a reader indexes: this node's edge into that reader. */\n slot: Edge | null;\n /** Successful runs; edges born since the last one are tentative. */\n gen: Generation;\n}\n\nexport interface Edge {\n readonly from: Node;\n readonly to: Node;\n /** from.ver when `to` read it; UNREAD while indexed and not yet read. */\n ver: Version | typeof UNREAD;\n /** to.gen + 1 at birth: tentative while it still equals to.gen + 1. */\n gen: Generation;\n prev: Edge | null;\n next: Edge | null;\n prevSub: Edge | null;\n nextSub: Edge | null;\n}\n\n/** Shared LIFO of the kernel's walks: edges, and (source, cell) pairs. */\nexport type WorkStack = (Node | Edge | null)[];\n\n// Flag layout and constants used by the kernel and host.\nexport const enum Flag {\n /** A source below may have changed; a watcher must validate. */\n Stale = 1 << 0,\n /** Must run: first run, failed run, or a direct source changed. */\n Dirty = 1 << 1,\n /** Its run is on the stack. */\n Busy = 1 << 2,\n /** Its run put its edges into the sources' slots. */\n Indexed = 1 << 3,\n /** A watcher: handed to the host, never read. */\n Watch = 1 << 4,\n /** Woken by signals only; computed sources need no validation. */\n Woken = 1 << 5,\n /**\n * Development builds only (C1 is a precondition): a computed whose\n * validation is on the stack, no longer STALE and not yet clean. WOKEN's\n * bit, so every mask stays a byte: WOKEN is a watcher's, CHECKING a\n * computed's, and no node is both. A production build never sets it, so\n * a mask that tests it is inert there.\n */\n Checking = 1 << 5,\n /** Host policy: scheduled by the reference host. */\n Auto = 1 << 6,\n /** Host policy: already in its queue. */\n Queued = 1 << 7,\n /** Its run marked its unread edges UNREAD; pairs are found through subscribers. */\n Marked = 1 << 8,\n}\n\n/** edge.ver of an edge the marked or indexed run has not read yet. */\nexport const UNREAD = -1;\n/** Counters wrap inside the SMI range. */\nexport const MASK = 0x3fffffff;\n/**\n * A committed edge keeps its birth generation, and generations wrap: an edge\n * 2^30 - 1 commits old would read as born in the next run (tentative). So a\n * node restamps its edges with its own generation whenever a commit makes\n * `gen & SETTLE` zero, twice a cycle, and no edge falls that far behind.\n */\nexport const SETTLE = 0x1fffffff;\n/** Scan budget of every bounded search: a constant keeps a run linear. */\nexport const SCAN = 8;\n/**\n * Work-stack slots kept at rest, and the length past which the outermost\n * walk's end cuts the stack back to them. The gap keeps walks only a little\n * deeper than KEEP from cutting and regrowing on every pass.\n */\nexport const KEEP = 256;\nexport const TRIM = 512;\n\n// Intrusive graph operations independent of the execution context.\n\nexport function node(fn: Node[\"fn\"], value: unknown, flags: Flags): Node {\n return {\n flags,\n value,\n ver: 0,\n fn,\n deps: null,\n last: null,\n subs: null,\n lastSub: null,\n slot: null,\n gen: 0,\n };\n}\n\n/** Move an unread edge (strictly after `next`) up to the cursor. */\nexport function move(c: Node, e: Edge, last: Edge | null, next: Edge): void {\n const before = e.prev!;\n const after = e.next;\n before.next = after;\n\n if (after !== null) after.prev = before;\n\n e.prev = last;\n e.next = next;\n\n if (last !== null) last.next = e;\n else c.deps = e;\n next.prev = e;\n c.last = e;\n}\n\n/** Remove every edge of `c` after `last` (all of them when null). */\nexport function cut(c: Node, last: Edge | null): void {\n let e = last === null ? c.deps : last.next;\n\n if (e === null) return;\n\n if (last === null) c.deps = null;\n else last.next = null;\n // The cut head's back pointer would tie this garbage to the live list, and\n // so to garbage cut later: old garbage keeps newer garbage alive.\n e.prev = null;\n\n for (; e !== null; e = e.next) unsub(e);\n}\n\n/** Restamp every edge of `c`, all of them committed, with its generation (SETTLE). */\nexport function settle(c: Node): void {\n const gen = c.gen;\n\n for (let e = c.deps; e !== null; e = e.next) e.gen = gen;\n}\n\n/** Take an edge out of its source's subscriber list. */\nexport function unsub(e: Edge): void {\n if (__STATS__) stats.unlinks++;\n\n const s = e.from;\n const before = e.prevSub;\n const after = e.nextSub;\n\n if (before !== null) before.nextSub = after;\n else s.subs = after;\n\n if (after !== null) after.prevSub = before;\n else s.lastSub = before;\n // Subscribers are in birth order, so an old removed edge would point at a\n // much younger one and keep it (and its watcher) alive across scavenges.\n e.prevSub = null;\n e.nextSub = null;\n}\n", "// Reactive kernel: tracking, propagation, validation and execution.\n// Detached edges must not retain pointers into live lists.\n// See research/LOG.md for representation rationale.\n\nimport {\n Flag,\n KEEP,\n MASK,\n SCAN,\n SETTLE,\n TRIM,\n UNREAD,\n cut,\n move,\n settle,\n unsub,\n} from \"./graph\";\nimport type { Edge, Flags, Node, WorkStack } from \"./graph\";\nimport { stats } from \"./instrumentation\";\n\nexport { node } from \"./graph\";\nexport { stats } from \"./instrumentation\";\n\n/** The running consumer, or null outside a tracking pass. */\nlet active: Node | null = null;\n/**\n * One LIFO work stack shared by all walks: sibling edges to resume (mark),\n * edges to climb back through (pull), and (source, cell) pairs an indexed run\n * displaced. Every walk pops back to its own base before returning, and the\n * outermost one gives back what a deep walk grew (`trim`).\n */\nconst stack: WorkStack = new Array(256).fill(null);\n/** First free index of `stack`. */\nlet top = 0;\n/** Longest the work stack has been when `trim` cut it (research). */\nlet peak = 0;\nlet wake: (w: Node) => void = () => {};\n\n/**\n * The host is told about every watcher a write or mark reaches. It owns the\n * deduplication (a queued watcher is not queued again), so a watcher left\n * STALE by a failed check is delivered again by the next push.\n */\nexport function onWake(fn: (w: Node) => void): void {\n wake = fn;\n}\n\n/** Nothing running, the work stack empty (tests). */\nexport function idle(): boolean {\n return active === null && top === 0;\n}\n\n/**\n * Deepest work-stack top reached so far (research). Walks null the slots\n * they pop and only `trim` shrinks the array, so the high-water mark is its\n * length or the longest length `trim` cut.\n */\nexport function stackHighWater(): number {\n return stack.length > peak ? stack.length : peak;\n}\n\n/** Slots the work stack holds now (tests). */\nexport function stackLength(): number {\n return stack.length;\n}\n\n/**\n * At rest, cut a stack that a deep walk grew past TRIM back to KEEP slots,\n * so one deep walk does not hold its depth in memory for good. Setting the\n * length right-trims V8's backing store in place: no allocation, and the\n * array stays packed.\n *\n * Only the end of an outermost validation calls it (top 0), whichever walk\n * grew the stack. A deep mark walk runs through computeds that are STALE\n * afterwards, so their next demand is such a validation; `write` and `mark`\n * stay as they were. The guard costs one length load and one compare per\n * validation, nothing per node.\n */\nfunction trim(): void {\n if (__STATS__ && stack.length > peak) peak = stack.length;\n\n stack.length = KEEP;\n}\n\n// ------------------------------------------------------------------- write\n\nexport function write(s: Node, value: unknown): void {\n if (Object.is(s.value, value)) return;\n\n s.value = value;\n s.ver = (s.ver + 1) & MASK;\n\n for (let e = s.subs; e !== null; e = e.nextSub) {\n const n = e.to;\n const f = n.flags;\n\n if (__STATS__) stats.marks++;\n\n if ((f & Flag.Busy) !== 0) {\n // Running: it may not have read s yet, so versions decide.\n if ((f & Flag.Stale) === 0) {\n n.flags = f | Flag.Stale;\n\n if ((f & Flag.Watch) !== 0) wake(n);\n else if (n.subs !== null) mark(n.subs);\n }\n } else if ((f & Flag.Watch) !== 0) {\n n.flags = f | Flag.Dirty | Flag.Woken;\n\n wake(n);\n } else if ((f & Flag.Stale) !== 0) {\n n.flags = f | Flag.Dirty;\n } else {\n n.flags = f | Flag.Dirty | Flag.Stale;\n\n if (n.subs !== null) mark(n.subs);\n }\n }\n}\n\n/** Mark everything below the subscriber list `first` STALE, depth first. */\nfunction mark(first: Edge): void {\n const base = top;\n let e: Edge | null = first;\n\n for (;;) {\n while (e !== null) {\n const n: Node = e.to;\n const f = n.flags;\n\n if (__STATS__) stats.marks++;\n // A watcher has no subscribers; the host deduplicates, so it is always told.\n if ((f & Flag.Watch) !== 0) {\n n.flags = f | Flag.Stale;\n wake(n);\n } else if ((f & Flag.Stale) === 0) {\n n.flags = f | Flag.Stale;\n\n if (n.subs !== null) {\n if (e.nextSub !== null) stack[top++] = e.nextSub;\n\n e = n.subs;\n continue;\n }\n }\n e = e.nextSub;\n }\n\n if (top === base) return;\n\n e = stack[--top] as Edge;\n stack[top] = null;\n }\n}\n\n// -------------------------------------------------------------------- read\n\n/** Bring `n` up to date if it is a stale computed, then track it. */\nexport function read(n: Node): unknown {\n const value = peek(n);\n const c = active;\n\n if (c !== null) {\n if (__STATS__) stats.reads++;\n\n const last = c.last;\n const next = last === null ? c.deps : last.next;\n\n if (next !== null && next.from === n) {\n if (__STATS__) stats.hits++;\n\n c.last = next;\n next.ver = n.ver;\n } else miss(c, n, last, next);\n }\n return value;\n}\n\n/** `read` without its tracking half: bring `n` up to date, record no relation. */\nexport function peek(n: Node): unknown {\n if ((n.flags & (Flag.Stale | Flag.Dirty | Flag.Busy | Flag.Checking)) !== 0)\n pull(n);\n\n return n.value;\n}\n\n/**\n * Pull a computed up to date. Existential, in read order: sources are\n * checked first to last and the first changed one makes the node run. A\n * STALE source is descended into (the stack keeps the edge to climb back\n * through); a DIRTY one runs. A throw leaves every node on the walk DIRTY.\n * A node whose run is on the stack is a cycle. A development build also\n * diagnoses a node whose validation is on the stack (CHECKING): C1 is a\n * precondition, so its committed value never answers such a demand there.\n */\nfunction pull(root: Node): void {\n const f = root.flags;\n\n if ((f & (Flag.Busy | Flag.Checking)) !== 0)\n throw new Error(\"Cycle detected\");\n\n if ((f & Flag.Dirty) !== 0) return exec(root);\n\n verify(root, f);\n}\n\n/**\n * The walk of `pull` for a STALE node that is not DIRTY, BUSY or CHECKING;\n * kept apart so `pull` stays small. A node disposed during the walk is not\n * run (W3), nor left DIRTY.\n *\n * Development builds diagnose C1: a node on the walk is CHECKING until it is\n * clean or runs, and a source on the stack (BUSY or CHECKING) is a cycle\n * even when no push marked it again, since its version is not yet a fact.\n * CHECKING is set by the store that clears STALE and cleared by `exec` as it\n * sets BUSY; only a node found clean pays a store of its own. Production\n * builds compile all of it away.\n */\nfunction verify(root: Node, f: Flags): void {\n root.flags = __DEV__ ? (f & ~Flag.Stale) | Flag.Checking : f & ~Flag.Stale;\n const base = top;\n let n = root;\n let e = root.deps;\n\n try {\n for (;;) {\n settled: {\n while (e !== null) {\n const s: Node = e.from;\n const sf = s.flags;\n\n if (__STATS__) stats.checks++;\n\n if (\n (sf &\n (__DEV__\n ? Flag.Stale | Flag.Dirty | Flag.Busy | Flag.Checking\n : Flag.Stale | Flag.Dirty)) !==\n 0\n ) {\n if ((sf & (Flag.Busy | Flag.Checking)) !== 0)\n throw new Error(\"Cycle detected\");\n\n if ((sf & Flag.Dirty) === 0) {\n s.flags = __DEV__\n ? (sf & ~Flag.Stale) | Flag.Checking\n : sf & ~Flag.Stale;\n stack[top++] = e;\n n = s;\n e = s.deps;\n continue;\n }\n exec(s);\n }\n\n if (s.ver !== e.ver) {\n if (n.fn !== null) exec(n);\n break settled;\n }\n e = e.next;\n }\n // Every source unchanged: clean, and no longer on the walk.\n if (__DEV__) n.flags &= ~Flag.Checking;\n }\n\n // Climb; a parent whose child changed runs as well.\n for (;;) {\n if (top === base) {\n if (stack.length > TRIM && base === 0) trim();\n\n return;\n }\n\n const up = stack[--top] as Edge;\n stack[top] = null;\n n = up.to;\n\n if (up.from.ver === up.ver) {\n e = up.next;\n break;\n }\n\n if (n.fn !== null) exec(n);\n }\n }\n } catch (error) {\n if (n.fn !== null)\n n.flags = __DEV__\n ? (n.flags | Flag.Dirty) & ~Flag.Checking\n : n.flags | Flag.Dirty;\n\n while (top > base) {\n const p = (stack[--top] as Edge).to;\n\n if (p.fn !== null)\n p.flags = __DEV__\n ? (p.flags | Flag.Dirty) & ~Flag.Checking\n : p.flags | Flag.Dirty;\n stack[top] = null;\n }\n throw error;\n }\n}\n\n/**\n * Universal check of a watcher: pull every committed source, so a throwing\n * one surfaces before any irreversible step. Marks DIRTY on change. Tentative\n * edges (reads of a failed run) only wake; they exist only while a run is\n * owed, and then versions need no comparison.\n */\nexport function check(w: Node): void {\n const tentative = (w.gen + 1) & MASK;\n let e = w.deps;\n\n // Until a run is owed, versions decide; then only the pulls remain. A\n // development build pulls a source on the stack too, so the C1 diagnosis\n // fails here, before the cleanup (P4).\n if ((w.flags & Flag.Dirty) === 0) {\n for (; e !== null; e = e.next) {\n const s = e.from;\n\n if (__STATS__) stats.checks++;\n\n if (\n (s.flags &\n (__DEV__\n ? Flag.Stale | Flag.Dirty | Flag.Busy | Flag.Checking\n : Flag.Stale | Flag.Dirty)) !==\n 0 &&\n e.gen !== tentative\n )\n pull(s);\n\n if (s.ver !== e.ver) {\n w.flags |= Flag.Dirty;\n e = e.next;\n break;\n }\n }\n }\n\n for (; e !== null; e = e.next) {\n if (__STATS__) stats.checks++;\n\n const s = e.from;\n\n if (\n (s.flags &\n (__DEV__\n ? Flag.Stale | Flag.Dirty | Flag.Busy | Flag.Checking\n : Flag.Stale | Flag.Dirty)) !==\n 0 &&\n e.gen !== tentative\n )\n pull(s);\n }\n}\n\nexport function untracked<T>(fn: () => T): T {\n const prev = active;\n active = null;\n\n try {\n return fn();\n } finally {\n active = prev;\n }\n}\n\n// --------------------------------------------------------------------- run\n\n/** Run `n.fn` as a tracking pass; commit value and edges on success. */\nexport function exec(n: Node): void {\n const prev = active;\n const base = top;\n\n if (__STATS__) stats.runs++;\n // Cleared before the run: a push during it marks the node again. In a\n // development build a computed's validation ends here, BUSY taking over\n // from CHECKING; on a watcher the bit is WOKEN, which this run discharges.\n n.flags =\n (n.flags &\n ~(__DEV__\n ? Flag.Stale | Flag.Dirty | Flag.Checking\n : Flag.Stale | Flag.Dirty)) |\n Flag.Busy;\n n.last = null;\n active = n;\n let value: unknown;\n\n try {\n value = n.fn!(n.value);\n } catch (error) {\n active = prev;\n fail(n, base);\n throw error;\n }\n active = prev;\n const f = n.flags;\n\n if ((f & Flag.Indexed) !== 0) unindex(n, base);\n\n n.flags = f & ~(Flag.Busy | Flag.Indexed | Flag.Marked);\n\n if (n.fn === null) return detach(n);\n // Commit only after a successful run. Dropping the unread suffix removes\n // sources that this pass no longer depends on.\n const last = n.last as Edge | null;\n\n if ((last === null ? n.deps : last.next) !== null) cut(n, last);\n\n n.gen = (n.gen + 1) & MASK;\n\n // Every edge is committed now; see SETTLE.\n if ((n.gen & SETTLE) === 0) settle(n);\n\n if (Object.is(value, n.value) === false) {\n n.value = value;\n n.ver = (n.ver + 1) & MASK;\n }\n}\n\n/**\n * A failed run: keep committed edges and this run's reads as the wake set,\n * drop unread edges earlier failed runs left behind, owe a run.\n */\nfunction fail(n: Node, base: number): void {\n if ((n.flags & Flag.Indexed) !== 0) unindex(n, base);\n\n n.flags &= ~(Flag.Busy | Flag.Indexed | Flag.Marked);\n\n if (n.fn === null) return detach(n);\n\n n.flags |= Flag.Dirty;\n const tentative = (n.gen + 1) & MASK;\n const last = n.last;\n\n for (let e = last === null ? n.deps : last.next; e !== null;) {\n const after: Edge | null = e.next;\n\n if (e.gen === tentative) {\n const before = e.prev;\n\n if (before !== null) before.next = after;\n else n.deps = after;\n\n if (after !== null) after.prev = before;\n\n unsub(e);\n e.prev = null;\n e.next = null;\n }\n e = after;\n }\n}\n\n/** Detach `n` from its sources for good; inside its own run, at its end. */\nexport function dispose(n: Node): void {\n if (n.fn === null) return;\n\n n.fn = null;\n\n if ((n.flags & Flag.Busy) === 0) detach(n);\n}\n\nfunction detach(n: Node): void {\n cut(n, null);\n n.flags &= ~(Flag.Stale | Flag.Dirty | Flag.Woken);\n}\n\n// ---------------------------------------------------------------- tracking\n\n/** Put every edge of `c` into its source's slot; mark the unread ones. */\nexport function index(c: Node, next: Edge | null): void {\n if (__STATS__) stats.indexes++;\n\n c.flags |= Flag.Indexed;\n let unread = false;\n\n for (let e = c.deps; e !== null; e = e.next) {\n if (__STATS__) stats.indexed++;\n\n if (e === next) unread = true;\n\n if (unread) e.ver = UNREAD;\n\n claim(e.from, e);\n }\n}\n\n/** Point the source's slot at `e`, keeping a displaced cell (an enclosing run's) to give back. */\nexport function claim(s: Node, e: Edge): void {\n if (s.slot !== null) {\n stack[top++] = s;\n stack[top++] = s.slot;\n }\n s.slot = e;\n}\n\n/** Clear the run's slots, give back the cells it displaced. */\nfunction unindex(n: Node, base: number): void {\n for (let e = n.deps; e !== null; e = e.next) e.from.slot = null;\n\n while (top > base) {\n const cell = stack[--top] as Edge;\n stack[top] = null;\n const s = stack[--top] as Node;\n stack[top] = null;\n s.slot = cell;\n }\n}\n\n/** A new edge at the cursor, appended to the source's subscribers. */\nexport function link(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n): void {\n if (__STATS__) stats.links++;\n\n const tail = s.lastSub;\n const e: Edge = {\n from: s,\n to: c,\n ver: s.ver,\n gen: (c.gen + 1) & MASK,\n prev: last,\n next,\n prevSub: tail,\n nextSub: null,\n };\n\n if (last !== null) last.next = e;\n else c.deps = e;\n\n if (next !== null) next.prev = e;\n\n if (tail !== null) tail.nextSub = e;\n else s.subs = e;\n s.lastSub = e;\n c.last = e;\n}\n\n// Exact dependency tracking: resolve a read outside the stable cursor path.\n// Proofs come cheapest first: the cursor (in `read`), the previous read, a\n// source nobody reads, bounded scans of this reader's list, then the source's\n// first subscribers. Only a source with more subscribers than the budget needs\n// the slot index. Slot walks and edge creation remain in the kernel because\n// they mutate its shared stack.\n\n/**\n * A read that is not the next edge in read order. Every answer is exact. A\n * repeated read keeps the version of the pass's first observation (P5): a\n * change between the two reads stays visible to the next validation.\n */\nfunction miss(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n if (last !== null && last.from === s) {\n if (__STATS__) stats.repeats++;\n\n return;\n }\n\n const f = c.flags;\n\n if ((f & Flag.Indexed) !== 0) return slot(c, s, last, next);\n /** The pair's edge through the source's subscribers; undefined: unknown. */\n let found: Edge | null | undefined;\n\n if ((f & Flag.Marked) === 0) {\n // A source without subscribers is absent.\n if (s.subs === null) return link(c, s, last, next);\n // An edge found by a scan is the pair's only one; absence needs one side\n // scanned completely (this reader's list, or the source's subscribers).\n let e = next !== null ? next.next : null;\n let budget = SCAN;\n\n while (e !== null && e.from !== s && --budget !== 0) e = e.next;\n\n if (e !== null && e.from === s) {\n if (__STATS__) stats.scans++;\n\n e.ver = s.ver;\n return move(c, e, last, next!);\n }\n let p = last !== null ? last.prev : null;\n budget = SCAN;\n\n while (p !== null && p.from !== s && --budget !== 0) p = p.prev;\n\n if (p !== null && p.from === s) {\n if (__STATS__) stats.dups++;\n\n return;\n }\n\n // Absent if this reader's whole list was scanned; otherwise the source's\n // first subscribers decide. Found as the first one: a lookup through the\n // subscribers costs no load beyond the read itself, so mark the unread\n // suffix and let the rest of the pass find its pairs that way, with no\n // slot to fill or clear. Found deeper: every lookup would walk other\n // readers' edges, so index; either way the found edge is taken at once.\n found = e === null && p === null ? null : pair(s, c);\n\n if (found !== null && found !== undefined) begin(c, s, found, next);\n } else found = pair(s, c);\n\n if (found === null) return link(c, s, last, next);\n\n if (found !== undefined) return take(c, found, s, last, next);\n // Past the budget: index the pass, and the slot decides from here on.\n index(c, next);\n slot(c, s, last, next);\n}\n\n/** An indexed pass's lookup: the source's slot holds the pair's edge, or the pair is absent. */\nfunction slot(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n if (__STATS__) stats.lookups++;\n\n const cell = s.slot;\n\n if (cell !== null && cell.to === c) return take(c, cell, s, last, next);\n link(c, s, last, next);\n claim(s, c.last as Edge);\n}\n\n/**\n * The pair's edge among the source's first SCAN subscribers: null if the list\n * ends first (absent), undefined if the budget runs out (unknown).\n */\nfunction pair(s: Node, c: Node): Edge | null | undefined {\n if (__STATS__) stats.lookups++;\n\n let budget = SCAN;\n\n for (let e = s.subs; e !== null; e = e.nextSub) {\n if (e.to === c) return e;\n\n if (--budget === 0) return undefined;\n }\n return null;\n}\n\n/**\n * The pass's lookup from here on, decided by the found edge's place: the\n * source's first subscriber marks the unread suffix, from `next` on (a walk\n * over edges, not sources); deeper, index.\n */\nfunction begin(c: Node, s: Node, e: Edge, next: Edge | null): void {\n if (e !== s.subs) return index(c, next);\n\n if (__STATS__) stats.sweeps++;\n\n c.flags |= Flag.Marked;\n\n for (let u = next; u !== null; u = u.next) {\n if (__STATS__) stats.indexed++;\n\n u.ver = UNREAD;\n }\n}\n\n/**\n * A found edge: an unread one is observed and moves to the cursor; a repeated\n * read keeps its place and its first observation's version (P5).\n */\nfunction take(\n c: Node,\n e: Edge,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n): void {\n if (e.ver !== UNREAD) {\n if (__STATS__) stats.dups++;\n\n return;\n }\n if (__STATS__) stats.moves++;\n\n e.ver = s.ver;\n move(c, e, last, next!);\n}\n", "// Policy around the kernel: the watcher lifecycle (check, consume the\n// cleanup, run), a FIFO queue for scheduled watchers, and batching.\nimport { Flag } from \"./graph\";\nimport type { Cleanup, Fn, Node } from \"./graph\";\nimport { check, dispose, exec, node, onWake, untracked } from \"./kernel\";\n\nconst queue: (Node | null)[] = [];\n// The host's registers. Exported so a write's caller can test for work\n// without a call into the host; ES bindings are read-only to importers, so\n// only this module writes them.\n/** Queued watchers. */\nexport let size = 0;\n/** Open batches. */\nexport let depth = 0;\n/** A drain loop is open. */\nexport let draining = false;\n\n/** Queue a scheduled watcher once; the kernel calls this when it wakes one. */\nexport function wake(w: Node): void {\n if ((w.flags & (Flag.Auto | Flag.Queued)) !== Flag.Auto) return;\n\n w.flags |= Flag.Queued;\n queue[size++] = w;\n}\n\nonWake(wake);\n\n/** A watcher runs `fn` and keeps a returned function as its cleanup. */\nexport function watcher(fn: Fn, auto: boolean): Node {\n return node(\n fn,\n undefined,\n Flag.Watch | Flag.Stale | Flag.Dirty | (auto ? Flag.Auto : 0),\n );\n}\n\n/**\n * Check every committed source unless only signals woke it, then, if a run\n * is owed, consume the previous cleanup and run. A watcher neither STALE,\n * WOKEN is clean, or cold after a failure until a source changes. A failed\n * check leaves it STALE, so the next run checks again (V1) and the next push\n * finds it queued or delivers it again.\n * Precondition: its own run is not on the stack (flush is not reentrant).\n */\nexport function run(w: Node): void {\n const flags = w.flags;\n\n if (w.fn === null || (flags & (Flag.Stale | Flag.Woken)) === 0) return;\n\n w.flags = flags & ~(Flag.Stale | Flag.Woken);\n\n if ((flags & Flag.Stale) !== 0) {\n try {\n check(w);\n } catch (error) {\n w.flags |= Flag.Stale;\n throw error;\n }\n }\n\n if ((w.flags & Flag.Dirty) === 0 || w.fn === null) return;\n\n const cleanup = w.value;\n\n if (typeof cleanup === \"function\") {\n w.value = undefined;\n untracked(cleanup as Cleanup);\n\n if (w.fn === null) return;\n }\n exec(w);\n}\n\n/** Terminal: detach, then run the last cleanup outside tracking. */\nexport function stop(w: Node): void {\n if (w.fn === null) return;\n\n const cleanup = w.value;\n w.value = undefined;\n dispose(w);\n\n if (typeof cleanup === \"function\") untracked(cleanup as Cleanup);\n}\n\n/** Run queued watchers until the queue drains; rethrow the first error. */\nexport function flush(): void {\n if (size === 0 || draining || depth !== 0) return;\n\n drainNow();\n}\n\n/**\n * `flush` with its guard at the call site: a write's caller tests\n * `size !== 0 && !draining && depth === 0` first (the queue first, so a write\n * that woke nothing costs one load), and calls this only when there is work.\n */\nexport function drainNow(): void {\n draining = true;\n drain(false, undefined);\n}\n\n/**\n * A new scheduled watcher's first run. With no drain open, no batch and an\n * empty queue this is `wake(w); flush()` with the queue slot skipped: the\n * drain opens on `w` (so its run stays inside the drain loop, LOG 11), and a\n * fresh watcher has no sources to check and no cleanup, so `run` is `exec`.\n */\nexport function start(w: Node): void {\n if (draining || depth !== 0 || size !== 0) {\n wake(w);\n return flush();\n }\n draining = true;\n\n try {\n exec(w);\n } catch (error) {\n return drain(true, error);\n }\n drain(false, undefined);\n}\n\n/** The drain loop, opened by the caller: FIFO, the first error rethrown at the end. */\nfunction drain(failed: boolean, first: unknown): void {\n for (let i = 0; i < size; i++) {\n const queuedWatcher = queue[i]!;\n queue[i] = null;\n queuedWatcher.flags &= ~Flag.Queued;\n\n try {\n run(queuedWatcher);\n } catch (error) {\n if (!failed) first = error;\n\n failed = true;\n }\n }\n size = 0;\n draining = false;\n\n if (failed) throw first;\n}\n\nexport function batch<T>(fn: () => T): T {\n depth++;\n\n try {\n return fn();\n } finally {\n if (--depth === 0) flush();\n }\n}\n", "// Public API: signal, computed, effect, get, peek, set, update, dispose,\n// batch, untracked. A handle is the node itself: nothing is allocated besides\n// the node, and handle <-> node conversions are type assertions only (no\n// runtime wrapper). Every operation here exposes existing kernel and host\n// semantics; none adds state.\nimport { Flag } from \"./graph\";\nimport { depth, drainNow, draining, size, start, stop, watcher } from \"./host\";\nimport {\n dispose as detach,\n node,\n peek as refresh,\n read,\n untracked,\n write,\n} from \"./kernel\";\nimport type { Fn, Node } from \"./graph\";\n\nexport { batch } from \"./host\";\nexport { untracked } from \"./kernel\";\n\n// Public handles: compile-time brands over the node, which is the runtime\n// handle. Variance is explicit: reading is covariant, a signal is also\n// written, so it is invariant.\ndeclare const READ: unique symbol;\ndeclare const WRITE: unique symbol;\ndeclare const COMPUTED: unique symbol;\ndeclare const EFFECT: unique symbol;\n\n/** Anything `get` accepts. */\nexport interface Readable<out T> {\n readonly [READ]: T;\n}\n\nexport interface Signal<in out T> extends Readable<T> {\n readonly [WRITE]: (value: T) => void;\n}\n\nexport interface Computed<out T> extends Readable<T> {\n readonly [COMPUTED]: true;\n}\n\nexport interface Effect {\n readonly [EFFECT]: true;\n}\n\nexport function signal<T>(value: T): Signal<T> {\n return node(null, value, 0) as unknown as Signal<T>;\n}\n\n/**\n * `fn` receives `prev`, the last successfully committed value: `initial`\n * (or undefined) before the first commit, unchanged by a failed run.\n * Returning `prev` itself is a cutoff: consumers do not rerun, so custom\n * equality is `(prev) => (equal(prev, next) ? prev : next)`.\n */\nexport function computed<T>(fn: (prev: T | undefined) => T): Computed<T>;\nexport function computed<T>(fn: (prev: T) => T, initial: T): Computed<T>;\nexport function computed<T>(\n fn: (prev: T | undefined) => T,\n initial?: T,\n): Computed<T> {\n return node(fn as Fn, initial, Flag.Dirty) as unknown as Computed<T>;\n}\n\n/** Runs now (or when the enclosing batch or drain ends), then on every change it read. */\nexport function effect(fn: () => void | (() => void)): Effect {\n const effectNode = watcher(fn, true);\n\n try {\n start(effectNode);\n } catch (error) {\n stop(effectNode);\n throw error;\n }\n\n return effectNode as unknown as Effect;\n}\n\n/**\n * Kernel `read` itself under the public type: a signal's flags are 0, so one\n * read path serves signals and computeds, and no surface function stands in\n * front of it.\n */\nexport const get: <T>(source: Readable<T>) => T = read as never;\n\n/** `get` without observation: up to date, but the running consumer does not depend on it. */\nexport const peek: <T>(source: Readable<T>) => T = refresh as never;\n\n/** Writes, then runs what the write scheduled; a write that woke nothing stops at one load. */\nexport function set<T>(source: Signal<T>, value: T): void {\n write(source as unknown as Node, value);\n\n if (size !== 0 && !draining && depth === 0) drainNow();\n}\n\n/**\n * `set(source, fn(current))`. An update is a write, not an observation:\n * `fn` runs untracked, so neither `source` nor what `fn` reads becomes a\n * dependency of the running consumer. If `fn` throws, nothing is written.\n */\nexport function update<T>(source: Signal<T>, fn: (value: T) => T): void {\n set(\n source,\n untracked(() => fn((source as unknown as Node).value as T)),\n );\n}\n\nexport function dispose(target: Computed<unknown> | Effect): void {\n const targetNode = target as unknown as Node;\n\n if ((targetNode.flags & Flag.Watch) !== 0) stop(targetNode);\n else detach(targetNode);\n}\n"],
5
- "mappings": ";;;AAkFO,IAAM,SAAS,IAET,OAAO,YAOP,SAAS,WAET,OAAO,GAMP,OAAO,KACP,OAAO;AAIb,SAAS,KAAK,IAAgB,OAAgB,OAAoB;AACvE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,K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KAAK,GAElC,SAAS,KAAK,CAAC,YAAY,UAAU,KAAG,SAAS;AACvD;AAOO,SAAS,OAAU,QAAmB,IAA2B;AACtE;AAAA,IACE;AAAA,IACA,UAAU,MAAM,GAAI,OAA2B,KAAU,CAAC;AAAA,EAC5D;AACF;AAEO,SAASC,SAAQ,QAA0C;AAChE,MAAM,aAAa;AAEnB,GAAK,WAAW,QAAQ,oBAAgB,IAAG,KAAK,UAAU,IACrD,QAAO,UAAU;AACxB;",
6
- "names": ["wake", "peek", "dispose"]
4
+ "sourcesContent": ["import { stats } from \"./instrumentation\";\n\n// Graph types, constants and intrusive list operations.\n\n// The aliases name different facts but do not brand numbers: counters wrap at\n// MASK and edge versions can carry UNREAD.\nexport type Flags = number;\nexport type Version = number;\nexport type Generation = number;\n\n/** A computed's or watcher's body; a signal has none. */\nexport type NodeFn = (prev: unknown) => unknown;\n/** A watcher's cleanup, run untracked. */\nexport type Cleanup = () => unknown;\n\nexport interface Node {\n flags: Flags;\n value: unknown;\n /** Bumps on every Object.is-visible change of value. */\n ver: Version;\n /** null for a signal and for a disposed node. */\n fn: NodeFn | null;\n /** First and last dependency edges, in read order. */\n firstDep: Edge | null;\n lastDep: Edge | null;\n /**\n * First subscriber edge, in birth order. Its prevSub is the LAST subscriber,\n * not null: the list is circular backwards only. Walk it forwards (nextSub\n * ends at null); a backward walk must stop at firstSub, or it loops.\n */\n firstSub: Edge | null;\n /** While a reader indexes: this node's edge into that reader. */\n slot: Edge | null;\n /** Successful runs; edges born since the last one are tentative. */\n gen: Generation;\n}\n\nexport interface Edge {\n readonly from: Node;\n readonly to: Node;\n /** from.ver when `to` read it; UNREAD in the pass's marked unread suffix. */\n ver: Version | typeof UNREAD | typeof SKIPPED;\n /** to.gen + 1 at birth: tentative while it still equals to.gen + 1. */\n gen: Generation;\n /** Neighbours in the consumer's dependency list. */\n prevDep: Edge | null;\n nextDep: Edge | null;\n /**\n * Neighbours in the source's subscriber list. prevSub is the predecessor,\n * except on the source's firstSub, where it is the last subscriber (the\n * tail: link appends there). Null only on a detached edge.\n */\n prevSub: Edge | null;\n nextSub: Edge | null;\n}\n\n/** Shared LIFO of the kernel's walks: resume edges and displaced slot cells. */\nexport type WorkStack = (Edge | null)[];\n\n// Flag layout and constants used by the kernel and host.\nexport const enum Flag {\n /** A source below may have changed; a watcher must validate. */\n Stale = 1 << 0,\n /** Must run: first run, failed run, or a direct source changed. */\n Dirty = 1 << 1,\n /** Its run is on the stack. */\n Busy = 1 << 2,\n /** A watcher: handed to the host, never read. */\n Watch = 1 << 4,\n /** Woken by signals only; computed sources need no validation. */\n Woken = 1 << 5,\n /**\n * Development builds only (C1 is a precondition): a computed whose\n * validation is on the stack, no longer STALE and not yet clean. WOKEN's\n * bit, so every mask stays a byte: WOKEN is a watcher's, CHECKING a\n * computed's, and no node is both. A production build never sets it, so\n * a mask that tests it is inert there.\n */\n Checking = 1 << 5,\n /** Host policy: scheduled by the reference host. */\n Auto = 1 << 6,\n /** Host policy: already in its queue. */\n Queued = 1 << 7,\n // Combined masks used when testing or clearing flags; all remain within a byte.\n Pending = Stale | Dirty,\n Active = Busy | Checking,\n Pull = Pending | Active,\n // Checking and Woken share a bit on computed nodes and watchers, respectively.\n PendingMarked = Pending | Checking,\n Wake = Stale | Woken,\n AutoQueued = Auto | Queued,\n}\n\n/** Counters wrap inside the SMI range. */\nexport const enum CounterLimit {\n Mask = 0x3fffffff,\n}\n\n/** edge.ver of an edge the marked or indexed run has not read yet. */\nexport const UNREAD = -1;\n/**\n * edge.ver of an unread edge a read has skipped once in this pass (`skip` in\n * the kernel). Like UNREAD it only stands where the old version is never\n * read: a read overwrites it, a successful run cuts what is left unread, and\n * a failed one leaves its node DIRTY.\n */\nexport const SKIPPED = -2;\n/**\n * A committed edge keeps its birth generation, and generations wrap: an edge\n * 2^30 - 1 commits old would read as born in the next run (tentative). So a\n * node restamps its edges with its own generation whenever a commit makes\n * `gen & SETTLE` zero, twice a cycle, and no edge falls that far behind.\n */\nexport const SETTLE = 0x1fffffff;\n/** Scan budget of every bounded search: a constant keeps a run linear. */\nexport const SCAN = 8;\n/**\n * Budget of the scan from the end of a reader's list (LOG 47). Skipped edges\n * go to the end in skip order, so the latest is last: a swap, a reversal and\n * a source moved to the front find theirs there. Each absent source pays the\n * whole budget, so it is small.\n */\nexport const TAIL = 2;\n/**\n * Work-stack (and host-queue) slots kept at rest, and the length past which the outermost\n * walk's end cuts the stack back to them. The gap keeps walks only a little\n * deeper than KEEP from cutting and regrowing on every pass.\n */\nexport const KEEP = 256;\nexport const TRIM = 512;\n\n// Intrusive graph operations independent of the execution context.\n\nexport function createNode(fn: Node[\"fn\"], value: unknown, flags: Flags): Node {\n return {\n flags,\n value,\n ver: 0,\n fn,\n firstDep: null,\n lastDep: null,\n firstSub: null,\n slot: null,\n gen: 0,\n };\n}\n\n/** Move an unread edge (strictly after `next`) up to the cursor. */\nexport function moveDep(c: Node, e: Edge, last: Edge | null, next: Edge): void {\n const before = e.prevDep!;\n const after = e.nextDep;\n before.nextDep = after;\n\n if (after !== null) after.prevDep = before;\n else c.lastDep = before;\n\n e.prevDep = last;\n e.nextDep = next;\n\n if (last !== null) last.nextDep = e;\n else c.firstDep = e;\n next.prevDep = e;\n}\n\n/**\n * A read found `e` past `next`, the edge under the cursor: `next` goes to the\n * end of the list (read later or never, see `miss`), and `e`, unless it was\n * right behind `next`, moves to the cursor, after `last`.\n */\nexport function skipDep(c: Node, last: Edge | null, next: Edge, e: Edge): void {\n const after = next.nextDep!;\n const tail = c.lastDep!;\n\n if (last !== null) last.nextDep = after;\n else c.firstDep = after;\n after.prevDep = last;\n\n next.prevDep = tail;\n next.nextDep = null;\n tail.nextDep = next;\n c.lastDep = next;\n // A failed marked pass can leave a marked suffix behind: stay inside it.\n if (tail.ver === UNREAD) next.ver = UNREAD;\n\n if (e !== after) moveDep(c, e, last, after);\n}\n\n/** Remove every edge of `c` after `last` (all of them when null). */\nexport function cutDeps(c: Node, last: Edge | null): void {\n let e = last === null ? c.firstDep : last.nextDep;\n\n if (e === null) return;\n\n if (last === null) c.firstDep = null;\n else last.nextDep = null;\n c.lastDep = last;\n // The cut head's back pointer would tie this garbage to the live list, and\n // so to garbage cut later: old garbage keeps newer garbage alive.\n e.prevDep = null;\n\n for (; e !== null; e = e.nextDep) unlinkSub(e);\n}\n\n/** Restamp every edge of `c`, all of them committed, with its generation (SETTLE). */\nexport function settleDeps(c: Node): void {\n const gen = c.gen;\n\n for (let e = c.firstDep; e !== null; e = e.nextDep) e.gen = gen;\n}\n\n/** Take an edge out of its source's subscriber list. */\nexport function unlinkSub(e: Edge): void {\n if (__STATS__) stats.unlinks++;\n\n const s = e.from;\n const before = e.prevSub!;\n const after = e.nextSub;\n\n if (e === s.firstSub) s.firstSub = after;\n else before.nextSub = after;\n\n if (after !== null) after.prevSub = before;\n else if (s.firstSub !== null) s.firstSub.prevSub = before;\n // Subscribers are in birth order, so an old removed edge would point at a\n // much younger one and keep it (and its watcher) alive across scavenges.\n e.prevSub = null;\n e.nextSub = null;\n}\n", "// Reactive kernel: tracking, propagation, validation and execution.\n// Detached edges must not retain pointers into live lists.\n// See research/LOG.md for representation rationale.\n\nimport {\n Flag,\n KEEP,\n CounterLimit,\n SCAN,\n SETTLE,\n SKIPPED,\n TAIL,\n TRIM,\n UNREAD,\n cutDeps,\n moveDep,\n settleDeps,\n skipDep,\n unlinkSub,\n} from \"./graph\";\nimport type { Edge, Flags, Node, WorkStack } from \"./graph\";\nimport { stats } from \"./instrumentation\";\n\nexport { createNode } from \"./graph\";\nexport { stats } from \"./instrumentation\";\n\nconst compare = Object.is;\n\n/** The running consumer, or null outside a tracking pass. */\nlet active: Node | null = null;\n/** Last accepted edge of the running pass; saved with `active` on nesting. */\nlet cursor: Edge | null = null;\n/**\n * One LIFO work stack shared by all walks: sibling edges to resume (mark),\n * edges to climb back through (pull), and slot cells an indexed run displaced.\n * Every walk pops back to its own base before returning. Once the stack is\n * empty, an oversized buffer is cut back (`trim`).\n */\nconst stack: WorkStack = new Array(256).fill(null);\n/** First free index of `stack`. */\nlet top = 0;\n/** Longest the work stack has been when `trim` cut it (research). */\nlet peak = 0;\nlet wake: (w: Node) => void = () => {};\n\n/**\n * The host is told about every watcher a write or mark reaches. It owns the\n * deduplication (a queued watcher is not queued again), so a watcher left\n * STALE by a failed check is delivered again by the next push.\n */\nexport function onWake(fn: (w: Node) => void): void {\n wake = fn;\n}\n\n/** No tracked consumer or occupied work-stack slot (tests; untracked suspends cursor). */\nexport function idle(): boolean {\n return active === null && top === 0;\n}\n\n/**\n * Deepest work-stack top reached so far (research). Walks null the slots\n * they pop and only `trim` shrinks the array, so the high-water mark is its\n * length or the longest length `trim` cut.\n */\nexport function stackHighWater(): number {\n return stack.length > peak ? stack.length : peak;\n}\n\n/** Slots the work stack holds now (tests). */\nexport function stackLength(): number {\n return stack.length;\n}\n\n/**\n * When empty, cut a stack that a deep walk grew past TRIM back to KEEP slots,\n * so one deep walk does not hold its depth in memory for good. Setting the\n * length right-trims V8's backing store in place: no allocation, and the\n * array stays packed.\n *\n * Only walks that push check at their exits: mark, verify (also on failure),\n * and unindex. An empty stack has no entries to preserve even if a user\n * callback or a graph cursor is suspended in local variables. `active`\n * is a tracking context, not a call-depth counter (untracked clears it).\n * The length test comes first: a small buffer pays no load of `top`.\n */\nfunction trim(): void {\n if (stack.length > TRIM && top === 0) {\n if (__STATS__ && stack.length > peak) peak = stack.length;\n\n stack.length = KEEP;\n }\n}\n\n// ------------------------------------------------------------------- write\n\nexport function write(s: Node, value: unknown): void {\n if (compare(s.value, value)) return;\n\n s.value = value;\n s.ver = (s.ver + 1) & CounterLimit.Mask;\n\n for (let e = s.firstSub; e !== null; e = e.nextSub) {\n const n = e.to;\n const f = n.flags;\n\n if (__STATS__) stats.marks++;\n\n if ((f & Flag.Busy) !== 0) {\n // Running: it may not have read s yet, so versions decide.\n if ((f & Flag.Stale) === 0) {\n n.flags = f | Flag.Stale;\n\n if ((f & Flag.Watch) !== 0) wake(n);\n else {\n const subs = n.firstSub;\n\n if (subs !== null) mark(subs);\n }\n }\n } else if ((f & Flag.Watch) !== 0) {\n n.flags = f | Flag.Dirty | Flag.Woken;\n\n wake(n);\n } else if ((f & Flag.Stale) !== 0) {\n n.flags = f | Flag.Dirty;\n } else {\n n.flags = f | Flag.Dirty | Flag.Stale;\n\n const subs = n.firstSub;\n\n if (subs !== null) mark(subs);\n }\n }\n}\n\n/** Mark everything below the subscriber list `first` STALE, depth first. */\nfunction mark(first: Edge): void {\n const base = top;\n let e: Edge | null = first;\n\n for (;;) {\n while (e !== null) {\n const n: Node = e.to;\n const f = n.flags;\n\n if (__STATS__) stats.marks++;\n // A watcher has no subscribers; the host deduplicates, so it is always told.\n if ((f & Flag.Watch) !== 0) {\n n.flags = f | Flag.Stale;\n wake(n);\n } else if ((f & Flag.Stale) === 0) {\n n.flags = f | Flag.Stale;\n\n const subs = n.firstSub;\n\n if (subs !== null) {\n const next = e.nextSub;\n\n if (next !== null) stack[top++] = next;\n\n e = subs;\n continue;\n }\n }\n e = e.nextSub;\n }\n\n if (top === base) {\n trim();\n return;\n }\n\n e = stack[--top] as Edge;\n stack[top] = null;\n }\n}\n\n// -------------------------------------------------------------------- read\n\n/** Bring `n` up to date if it is a stale computed, then track it. */\nexport function read(n: Node): unknown {\n const value = peek(n);\n const c = active;\n\n if (c !== null) {\n if (__STATS__) stats.reads++;\n\n const last = cursor;\n const next = last === null ? c.firstDep : last.nextDep;\n\n if (next !== null && next.from === n) {\n if (__STATS__) stats.hits++;\n\n cursor = next;\n next.ver = n.ver;\n } else if (last !== null) {\n // The cursor's own source again: a repeat keeps its first observation\n // (P5); anything else is resolved by `miss`.\n if (last.from !== n) miss(c, n, last, next);\n else if (__STATS__) stats.repeats++;\n } else if (next !== null) miss(c, n, last, next);\n // No relation yet: the first read of a first run links at once.\n else link(c, n, null, null);\n }\n return value;\n}\n\n/** `read` without its tracking half: bring `n` up to date, record no relation. */\nexport function peek(n: Node): unknown {\n if ((n.flags & Flag.Pull) !== 0) pull(n);\n\n return n.value;\n}\n\n/**\n * Pull a computed up to date. Existential, in read order: sources are\n * checked first to last and the first changed one makes the node run. A\n * STALE source is descended into (the stack keeps the edge to climb back\n * through); a DIRTY one runs. A throw leaves every node on the walk DIRTY.\n * A node whose run is on the stack is a cycle. A development build also\n * diagnoses a node whose validation is on the stack (CHECKING): C1 is a\n * precondition, so its committed value never answers such a demand there.\n */\nfunction pull(root: Node): void {\n const f = root.flags;\n\n if ((f & Flag.Active) !== 0) throw new Error(\"Cycle detected\");\n\n if ((f & Flag.Dirty) !== 0) return exec(root);\n\n verify(root, f);\n}\n\n/**\n * The walk of `pull` for a STALE node that is not DIRTY, BUSY or CHECKING;\n * kept apart so `pull` stays small. A node disposed during the walk is not\n * run (W3), nor left DIRTY.\n *\n * Development builds diagnose C1: a node on the walk is CHECKING until it is\n * clean or runs, and a source on the stack (BUSY or CHECKING) is a cycle\n * even when no push marked it again, since its version is not yet a fact.\n * CHECKING is set by the store that clears STALE and cleared by `exec` as it\n * sets BUSY; only a node found clean pays a store of its own. Production\n * builds compile all of it away.\n */\nfunction verify(root: Node, f: Flags): void {\n root.flags = __DEV__ ? (f & ~Flag.Stale) | Flag.Checking : f & ~Flag.Stale;\n const base = top;\n let n = root;\n let e = root.firstDep;\n\n try {\n for (;;) {\n settled: {\n while (e !== null) {\n const s: Node = e.from;\n const sf = s.flags;\n\n if (__STATS__) stats.checks++;\n\n if ((sf & (__DEV__ ? Flag.Pull : Flag.Pending)) !== 0) {\n if ((sf & Flag.Active) !== 0) throw new Error(\"Cycle detected\");\n\n if ((sf & Flag.Dirty) === 0) {\n s.flags = __DEV__\n ? (sf & ~Flag.Stale) | Flag.Checking\n : sf & ~Flag.Stale;\n stack[top++] = e;\n n = s;\n e = s.firstDep;\n continue;\n }\n exec(s);\n }\n\n if (s.ver !== e.ver) {\n if (n.fn !== null) exec(n);\n break settled;\n }\n e = e.nextDep;\n }\n // Every source unchanged: clean, and no longer on the walk.\n if (__DEV__) n.flags &= ~Flag.Checking;\n }\n\n // Climb; a parent whose child changed runs as well.\n for (;;) {\n if (top === base) {\n trim();\n\n return;\n }\n\n const up = stack[--top] as Edge;\n stack[top] = null;\n n = up.to;\n\n if (up.from.ver === up.ver) {\n e = up.nextDep;\n break;\n }\n\n if (n.fn !== null) exec(n);\n }\n }\n } catch (error) {\n if (n.fn !== null)\n n.flags = __DEV__\n ? (n.flags | Flag.Dirty) & ~Flag.Checking\n : n.flags | Flag.Dirty;\n\n while (top > base) {\n const p = (stack[--top] as Edge).to;\n\n if (p.fn !== null)\n p.flags = __DEV__\n ? (p.flags | Flag.Dirty) & ~Flag.Checking\n : p.flags | Flag.Dirty;\n stack[top] = null;\n }\n trim();\n throw error;\n }\n}\n\n/**\n * Universal check of a watcher: pull every committed source, so a throwing\n * one surfaces before any irreversible step. Marks DIRTY on change. Tentative\n * edges (reads of a failed run) only wake; they exist only while a run is\n * owed, and then versions need no comparison.\n */\nexport function check(w: Node): void {\n const tentative = (w.gen + 1) & CounterLimit.Mask;\n let e = w.firstDep;\n\n // Until a run is owed, versions decide; then only the pulls remain. A\n // development build pulls a source on the stack too, so the C1 diagnosis\n // fails here, before the cleanup (P4).\n if ((w.flags & Flag.Dirty) === 0) {\n for (; e !== null; e = e.nextDep) {\n const s = e.from;\n\n if (__STATS__) stats.checks++;\n\n if (\n (s.flags & (__DEV__ ? Flag.Pull : Flag.Pending)) !== 0 &&\n e.gen !== tentative\n )\n pull(s);\n\n if (s.ver !== e.ver) {\n w.flags |= Flag.Dirty;\n e = e.nextDep;\n break;\n }\n }\n }\n\n for (; e !== null; e = e.nextDep) {\n if (__STATS__) stats.checks++;\n\n const s = e.from;\n\n if (\n (s.flags & (__DEV__ ? Flag.Pull : Flag.Pending)) !== 0 &&\n e.gen !== tentative\n )\n pull(s);\n }\n}\n\nexport function untracked<T>(fn: () => T): T {\n const prev = active;\n active = null;\n\n try {\n return fn();\n } finally {\n active = prev;\n }\n}\n\n// --------------------------------------------------------------------- run\n\n/** Run `n.fn` as a tracking pass; commit value and edges on success. */\nexport function exec(n: Node): void {\n const prev = active;\n const prevCursor = cursor;\n const base = top;\n\n if (__STATS__) stats.runs++;\n // Cleared before the run: a push during it marks the node again. In a\n // development build a computed's validation ends here, BUSY taking over\n // from CHECKING; on a watcher the bit is WOKEN, which this run discharges.\n n.flags =\n (n.flags & ~(__DEV__ ? Flag.PendingMarked : Flag.Pending)) | Flag.Busy;\n active = n;\n cursor = null;\n let value: unknown;\n\n try {\n value = n.fn!(n.value);\n } catch (error) {\n const last = cursor as Edge | null;\n active = prev;\n cursor = prevCursor;\n fail(n, base, last);\n throw error;\n }\n const last = cursor as Edge | null;\n active = prev;\n cursor = prevCursor;\n const f = n.flags;\n\n if (last !== null && last.from.slot === last) unindex(n, base);\n\n n.flags = f & ~Flag.Busy;\n\n if (n.fn === null) return detach(n);\n // Commit only after a successful run. Dropping the unread suffix removes\n // sources that this pass no longer depends on.\n if ((last === null ? n.firstDep : last.nextDep) !== null) cutDeps(n, last);\n\n n.gen = (n.gen + 1) & CounterLimit.Mask;\n\n // Every edge is committed now; see SETTLE.\n if ((n.gen & SETTLE) === 0) settleDeps(n);\n\n if (compare(value, n.value) === false) {\n n.value = value;\n n.ver = (n.ver + 1) & CounterLimit.Mask;\n }\n}\n\n/**\n * A failed run: keep committed edges and this run's reads as the wake set,\n * drop unread edges earlier failed runs left behind, owe a run.\n */\nfunction fail(n: Node, base: number, last: Edge | null): void {\n if (last !== null && last.from.slot === last) unindex(n, base);\n\n n.flags &= ~Flag.Busy;\n\n if (n.fn === null) return detach(n);\n\n n.flags |= Flag.Dirty;\n const tentative = (n.gen + 1) & CounterLimit.Mask;\n for (let e = last === null ? n.firstDep : last.nextDep; e !== null;) {\n const after: Edge | null = e.nextDep;\n\n if (e.gen === tentative) {\n const before = e.prevDep;\n\n if (before !== null) before.nextDep = after;\n else n.firstDep = after;\n\n if (after !== null) after.prevDep = before;\n else n.lastDep = before;\n\n unlinkSub(e);\n e.prevDep = null;\n e.nextDep = null;\n }\n e = after;\n }\n}\n\n/** Detach `n` from its sources for good; inside its own run, at its end. */\nexport function dispose(n: Node): void {\n if (n.fn === null) return;\n\n n.fn = null;\n\n if ((n.flags & Flag.Busy) === 0) detach(n);\n}\n\nfunction detach(n: Node): void {\n cutDeps(n, null);\n n.flags &= ~Flag.PendingMarked;\n}\n\n// ---------------------------------------------------------------- tracking\n\n/** Put every edge of `c` into its source's slot; mark the unread ones. */\nexport function index(c: Node, next: Edge | null): void {\n if (__STATS__) stats.indexes++;\n\n let unread = false;\n\n for (let e = c.firstDep; e !== null; e = e.nextDep) {\n if (__STATS__) stats.indexed++;\n\n if (e === next) unread = true;\n\n if (unread) e.ver = UNREAD;\n\n claim(e.from, e);\n }\n}\n\n/**\n * Point the source's slot at `e`, keeping a displaced cell to give back.\n * A cell's immutable `from` is its source, so the cell alone is enough.\n */\nexport function claim(s: Node, e: Edge): void {\n const cell = s.slot;\n\n if (cell !== null) stack[top++] = cell;\n s.slot = e;\n}\n\n/** Clear the run's slots, give back the cells it displaced. */\nfunction unindex(n: Node, base: number): void {\n for (let e = n.firstDep; e !== null; e = e.nextDep) e.from.slot = null;\n\n while (top > base) {\n const cell = stack[--top] as Edge;\n stack[top] = null;\n cell.from.slot = cell;\n }\n trim();\n}\n\n/** A new edge at the cursor, appended to the source's subscribers. */\nexport function link(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n): void {\n if (__STATS__) stats.links++;\n\n const first = s.firstSub;\n const tail = first !== null ? first.prevSub : null;\n const e: Edge = {\n from: s,\n to: c,\n ver: s.ver,\n gen: (c.gen + 1) & CounterLimit.Mask,\n prevDep: last,\n nextDep: next,\n prevSub: tail,\n nextSub: null,\n };\n\n if (last !== null) last.nextDep = e;\n else c.firstDep = e;\n\n if (next !== null) next.prevDep = e;\n else c.lastDep = e;\n\n if (first !== null) {\n tail!.nextSub = e;\n first.prevSub = e;\n } else {\n s.firstSub = e;\n e.prevSub = e;\n }\n cursor = e;\n}\n\n// Exact dependency tracking: resolve a read outside the stable cursor path.\n// Proofs come cheapest first: in `read`, the edge after the cursor, the\n// cursor's own (a repeat) and an empty list (the first relation); then a\n// source nobody reads or whose at most two subscribers are other readers,\n// bounded scans of this reader's list, and the source's first subscribers.\n// Only a source with more subscribers than the budget needs the slot index. Slot walks and edge creation remain in the kernel because\n// they mutate its shared stack.\n\n/**\n * A read that is neither the next edge in read order, nor the cursor's, nor\n * the first relation of an empty list. Every answer is exact. A repeated read\n * keeps the version of the pass's first observation (P5): a change between\n * the two reads stays visible to the next validation.\n */\nfunction miss(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n // An indexed pass owns its cursor's source slot. Nested passes restore it.\n if (last !== null && last.from.slot === last) return slot(c, s, last, next);\n const first = s.firstSub;\n\n // Absent, whatever the unread suffix mode: a source nobody reads, or one\n // whose first and last subscribers, all it has, are other readers.\n if (first === null || alien(first, c)) return link(c, s, last, next);\n\n // Marking, moves and links preserve a continuous UNREAD suffix.\n if (next !== null && next.ver === UNREAD)\n return settle(c, s, last, next, pair(first, c));\n\n if (next !== null) {\n let e = next.nextDep;\n\n // One past `next`: the commonest skip (a swap, a rotation, a deletion).\n if (e !== null && e.from === s) {\n if (__STATS__) stats.scans++;\n\n return skip(c, s, last, next, e);\n }\n // The end of the list holds the edges reads skipped twice (`skip`), the\n // latest last: read after all, or a source moved to the front. A match\n // is the pair's only edge.\n let budget = TAIL;\n e = c.lastDep!;\n\n while (e !== next && e.from !== s && --budget !== 0) e = e.prevDep!;\n\n if (e.from === s) {\n if (__STATS__) stats.tails++;\n\n e.ver = s.ver;\n cursor = e;\n return moveDep(c, e, last, next);\n }\n }\n near(c, s, last, next, first);\n}\n\n/**\n * A miss that neither the source, a marked pass nor the end of the list\n * settles.\n */\nfunction near(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n first: Edge,\n): void {\n // Bounded scans of this reader's list: the unread suffix after `next` (a\n // match is the pair's only edge), the accepted prefix (a match is a\n // repeat). Absence needs one side scanned completely: this reader's list,\n // or the source's subscribers.\n let e: Edge | null = null;\n\n if (next !== null) {\n let budget = SCAN;\n e = next.nextDep;\n\n while (e !== null && e.from !== s && --budget !== 0) e = e.nextDep;\n\n if (e !== null && e.from === s) {\n if (__STATS__) stats.scans++;\n\n return skip(c, s, last, next, e);\n }\n }\n let p = last !== null ? last.prevDep : null;\n let budget = SCAN;\n\n while (p !== null && p.from !== s && --budget !== 0) p = p.prevDep;\n\n if (p !== null && p.from === s) {\n if (__STATS__) stats.dups++;\n\n return;\n }\n\n if (e === null && p === null) return link(c, s, last, next);\n\n lookup(c, s, last, next, first);\n}\n\n/**\n * A read found its edge `e` past `next`, which it skips. The first time,\n * `next` is most likely read next (a swap, a source moved earlier): `e` moves\n * to the cursor and `next` is marked. Skipped again, it is read later or\n * never (a rotation, a deletion, a later move); left in place it would stand\n * before every following read, so it goes to the end of the list, where the\n * tail scan in `miss` finds it if it is read after all.\n */\nfunction skip(c: Node, s: Node, last: Edge | null, next: Edge, e: Edge): void {\n e.ver = s.ver;\n cursor = e;\n\n if (next.ver === SKIPPED) return skipDep(c, last, next, e);\n\n next.ver = SKIPPED;\n moveDep(c, e, last, next);\n}\n\n/**\n * The source's first subscribers decide what the reader's list could not.\n * Found as the first one: a lookup through the subscribers costs no load\n * beyond the read itself, so mark the unread suffix and let the rest of the\n * pass find its pairs that way, with no slot to fill or clear. Found deeper:\n * every lookup would walk other readers' edges, so index; either way the\n * found edge is taken at once.\n */\nfunction lookup(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n first: Edge,\n): void {\n const found = pair(first, c);\n\n if (found !== null && found !== undefined) begin(c, found, first, next);\n\n settle(c, s, last, next, found);\n}\n\n/** A lookup's answer: absent links, found is taken, unknown indexes the pass. */\nfunction settle(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n found: Edge | null | undefined,\n): void {\n if (found === null) return link(c, s, last, next);\n\n if (found !== undefined) return take(c, found, s, last, next);\n // Past the budget: index the pass, and the slot decides from here on.\n index(c, next);\n slot(c, s, last, next);\n}\n\n/** An indexed pass's lookup: the source's slot holds the pair's edge, or the pair is absent. */\nfunction slot(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n if (__STATS__) stats.lookups++;\n\n const cell = s.slot;\n\n if (cell !== null && cell.to === c) return take(c, cell, s, last, next);\n link(c, s, last, next);\n claim(s, cursor as Edge);\n}\n\n/**\n * Whether the source's subscriber list, at most two edges long, holds no edge\n * to `c`: its first and last subscribers are one load apart (the first one's\n * prevSub), so this proves absence before the reader's list is scanned.\n */\nfunction alien(first: Edge, c: Node): boolean {\n const tail = first.prevSub!;\n\n return (\n first.to !== c &&\n tail.to !== c &&\n (tail === first || first.nextSub === tail)\n );\n}\n\n/**\n * The pair's edge among the source's first SCAN subscribers: null if the list\n * ends first (absent), undefined if the budget runs out (unknown).\n */\nfunction pair(first: Edge | null, c: Node): Edge | null | undefined {\n if (__STATS__) stats.lookups++;\n\n let budget = SCAN;\n\n for (let e = first; e !== null; e = e.nextSub) {\n if (e.to === c) return e;\n\n if (--budget === 0) return undefined;\n }\n return null;\n}\n\n/**\n * The pass's lookup from here on, decided by the found edge's place: the\n * source's first subscriber marks the unread suffix, from `next` on (a walk\n * over edges, not sources); deeper, index.\n */\nfunction begin(c: Node, e: Edge, first: Edge | null, next: Edge | null): void {\n if (next === null) return;\n\n if (e !== first) return index(c, next);\n\n if (__STATS__) stats.sweeps++;\n\n for (let u: Edge | null = next; u !== null; u = u.nextDep) {\n if (__STATS__) stats.indexed++;\n\n u.ver = UNREAD;\n }\n}\n\n/**\n * A found edge: an unread one is observed and moves to the cursor; a repeated\n * read keeps its place and its first observation's version (P5).\n */\nfunction take(\n c: Node,\n e: Edge,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n): void {\n if (e.ver !== UNREAD) {\n if (__STATS__) stats.dups++;\n\n return;\n }\n if (__STATS__) stats.moves++;\n\n e.ver = s.ver;\n moveDep(c, e, last, next!);\n cursor = e;\n}\n", "// Policy around the kernel: the watcher lifecycle (check, consume the\n// cleanup, run), a FIFO queue for scheduled watchers, and batching.\nimport { Flag, KEEP, TRIM } from \"./graph\";\nimport type { Cleanup, Flags, Node, NodeFn } from \"./graph\";\nimport { check, createNode, dispose, exec, onWake, untracked } from \"./kernel\";\n\n/**\n * The queue: a ring of `mask + 1` slots, a power of two, holding the `size`\n * queued watchers from `head` on. It doubles only when full, so it holds\n * fewer than 2W + KEEP slots for W watchers queued at once (S8), and a\n * delivery takes no slot of its own: a slot is free again once taken.\n */\nlet queue: (Node | null)[] = new Array<Node | null>(KEEP).fill(null);\nlet mask = KEEP - 1;\nlet head = 0;\n/**\n * Deliveries of the small drains since the last drain that needed the ring,\n * and the largest of them: the ring is given back once they add up to its\n * size (see `drain`).\n */\nlet spare = 0;\nlet calm = 0;\n// The host's registers. Exported so a write's caller can test for work\n// without a call into the host; ES bindings are read-only to importers, so\n// only this module writes them.\n/** Queued watchers. */\nexport let size = 0;\n/** Open batches, plus one while a drain loop is open: work waits while > 0. */\nexport let hold = 0;\n\n/** Queue a scheduled watcher once; the kernel calls this when it wakes one. */\nexport function wake(w: Node): void {\n const flags = w.flags;\n\n if ((flags & Flag.AutoQueued) !== Flag.Auto) return;\n\n w.flags = flags | Flag.Queued;\n\n if (size > mask) grow();\n\n queue[(head + size++) & mask] = w;\n}\n\nonWake(wake);\n\n/** A full ring doubles, its watchers moved to the front in queue order. */\nfunction grow(): void {\n const next = new Array<Node | null>(size + size).fill(null);\n\n for (let i = 0; i < size; i++) next[i] = queue[(head + i) & mask] as Node;\n\n queue = next;\n mask = size + size - 1;\n head = 0;\n}\n\n/** A watcher runs `fn` and keeps a returned function as its cleanup. */\nexport function watcher(fn: NodeFn, auto: boolean): Node {\n return createNode(\n fn,\n undefined,\n Flag.Watch | Flag.Stale | Flag.Dirty | (auto ? Flag.Auto : 0),\n );\n}\n\n/**\n * Check every committed source unless only signals woke it, then, if a run\n * is owed, consume the previous cleanup and run. A watcher neither STALE,\n * WOKEN is clean, or cold after a failure until a source changes. A failed\n * check leaves it STALE, so the next run checks again (V1) and the next push\n * finds it queued or delivers it again.\n * Precondition: its own run is not on the stack (flush is not reentrant).\n */\nexport function run(w: Node): void {\n deliver(w, w.flags);\n}\n\n/**\n * `run` with the watcher's flags already loaded: the drain clears QUEUED in\n * the same store that clears WAKE. WOKEN without STALE means only signals\n * woke it, and they made it DIRTY: no check, no reload.\n */\nfunction deliver(w: Node, flags: Flags): void {\n if (w.fn === null || (flags & Flag.Wake) === 0) {\n w.flags = flags;\n return;\n }\n w.flags = flags & ~Flag.Wake;\n\n if ((flags & Flag.Stale) !== 0) {\n try {\n check(w);\n } catch (error) {\n w.flags |= Flag.Stale;\n throw error;\n }\n\n if ((w.flags & Flag.Dirty) === 0 || w.fn === null) return;\n }\n const cleanup = w.value;\n\n if (typeof cleanup === \"function\") {\n w.value = undefined;\n untracked(cleanup as Cleanup);\n\n if (w.fn === null) return;\n }\n exec(w);\n}\n\n/** Terminal: detach, then run the last cleanup outside tracking. */\nexport function stop(w: Node): void {\n if (w.fn === null) return;\n\n const cleanup = w.value;\n w.value = undefined;\n dispose(w);\n\n if (typeof cleanup === \"function\") untracked(cleanup as Cleanup);\n}\n\n/** Run queued watchers until the queue drains; rethrow the first error. */\nexport function flush(): void {\n if (size === 0 || hold !== 0) return;\n\n drainNow();\n}\n\n/**\n * `flush` with its guard at the call site: a write's caller tests\n * `size !== 0 && hold === 0` first (the queue first, so a write that woke\n * nothing costs one load), and calls this only when there is work.\n */\nexport function drainNow(): void {\n hold = 1;\n drain(false, undefined);\n}\n\n/**\n * A new scheduled watcher's first run. With no drain open, no batch and an\n * empty queue this is `wake(w); flush()` with the queue slot skipped: the\n * drain opens on `w` (so its run stays inside the drain loop, LOG 11), and a\n * fresh watcher has no sources to check and no cleanup, so `run` is `exec`.\n */\nexport function start(w: Node): void {\n if (hold !== 0 || size !== 0) {\n wake(w);\n return flush();\n }\n hold = 1;\n\n try {\n exec(w);\n } catch (error) {\n return drain(true, error);\n }\n drain(false, undefined);\n}\n\n/**\n * The drain loop, opened by the caller (`hold` is 1): FIFO, the first error\n * rethrown at the end.\n *\n * A drain whose deliveries (which bound its watchers queued at once) fill\n * less than a quarter of the ring is small. The ring is cut back at rest,\n * to KEEP or to the power of two above twice the largest small drain, once\n * the small drains since the last large one have delivered as many watchers\n * as the ring holds. Growing back costs O(ring), so a give-back followed by\n * a burst is O(1) per delivery; a burst after every few small drains keeps\n * its ring, and a burst followed by small drains is still given back.\n */\nfunction drain(failed: boolean, first: unknown): void {\n let taken = 0;\n\n for (; size !== 0; taken++) {\n const queuedWatcher = queue[head]!;\n queue[head] = null;\n head = (head + 1) & mask;\n size--;\n\n try {\n deliver(queuedWatcher, queuedWatcher.flags & ~Flag.Queued);\n } catch (error) {\n if (!failed) first = error;\n\n failed = true;\n }\n }\n head = 0;\n\n if (mask >= TRIM) {\n if (taken + taken < mask >> 1) {\n if (taken > calm) calm = taken;\n\n if ((spare += taken) > mask) shrink(calm);\n } else spare = calm = 0;\n }\n hold = 0;\n\n if (failed) throw first;\n}\n\n/** Cut an empty ring to KEEP slots, or to the power of two above 2 * taken. */\nfunction shrink(taken: number): void {\n let length = KEEP;\n\n while (length < taken + taken) length += length;\n\n queue.length = length;\n mask = length - 1;\n spare = calm = 0;\n}\n\n/**\n * The outermost batch end runs what the body deferred, also when the body\n * threw; then the body's error is the batch's error (F5), and a deferred\n * watcher's failure leaves only that watcher cold (F3). Inside a drain the\n * drain runs it.\n */\nexport function batch<T>(fn: () => T): T {\n hold++;\n let value: T;\n\n try {\n value = fn();\n } catch (error) {\n if (--hold === 0) {\n try {\n flush();\n } catch {\n // F5: a later error does not replace the body's.\n }\n }\n throw error;\n }\n if (--hold === 0) flush();\n\n return value;\n}\n\n/** Slots the queue holds now (tests). */\nexport function queueLength(): number {\n return queue.length;\n}\n", "// Public API: signal, computed, effect, get, peek, set, update, dispose,\n// batch, untracked, typeOf. A handle is the node itself: nothing is allocated besides\n// the node, and handle <-> node conversions are type assertions only (no\n// runtime wrapper). Every operation here exposes existing kernel and host\n// semantics; none adds state.\nimport { Flag } from \"./graph\";\nimport { drainNow, hold, size, start, stop, watcher } from \"./host\";\nimport {\n dispose as detach,\n createNode,\n peek as refresh,\n read,\n untracked,\n write,\n} from \"./kernel\";\nimport type { Node, NodeFn } from \"./graph\";\n\nexport { batch } from \"./host\";\nexport { untracked } from \"./kernel\";\n\n// Public handles: compile-time brands over the node, which is the runtime\n// handle. Variance is explicit: reading is covariant, a signal is also\n// written, so it is invariant.\ndeclare const READ: unique symbol;\ndeclare const WRITE: unique symbol;\ndeclare const COMPUTED: unique symbol;\ndeclare const EFFECT: unique symbol;\n\n/** Anything `get` accepts. */\nexport interface Readable<out T> {\n readonly [READ]: T;\n}\n\nexport interface Signal<in out T> extends Readable<T> {\n readonly [WRITE]: (value: T) => void;\n}\n\nexport interface Computed<out T> extends Readable<T> {\n readonly [COMPUTED]: true;\n}\n\nexport interface Effect {\n readonly [EFFECT]: true;\n}\n\n/**\n * Identify a live handle without evaluating it. A disposed computed is no\n * longer distinguishable from a signal; passing one is invalid.\n */\nexport function typeOf<T>(target: Signal<T>): \"signal\";\nexport function typeOf(target: Computed<unknown>): \"computed\";\nexport function typeOf(target: Effect): \"effect\";\nexport function typeOf(\n target: Readable<unknown> | Effect,\n): \"signal\" | \"computed\" | \"effect\";\nexport function typeOf(target: unknown): \"signal\" | \"computed\" | \"effect\" {\n const node = target as Node;\n\n if ((node.flags & Flag.Watch) !== 0) return \"effect\";\n return node.fn === null ? \"signal\" : \"computed\";\n}\n\nexport function signal<T>(value: T): Signal<T> {\n return createNode(null, value, 0) as unknown as Signal<T>;\n}\n\n/**\n * `fn` receives `prev`, the last successfully committed value: `initial`\n * (or undefined) before the first commit, unchanged by a failed run.\n * Returning `prev` itself is a cutoff: consumers do not rerun, so custom\n * equality is `(prev) => (equal(prev, next) ? prev : next)`.\n */\nexport function computed<T>(fn: (prev: T | undefined) => T): Computed<T>;\nexport function computed<T>(fn: (prev: T) => T, initial: T): Computed<T>;\nexport function computed<T>(\n fn: (prev: T | undefined) => T,\n initial?: T,\n): Computed<T> {\n return createNode(\n fn as NodeFn,\n initial,\n Flag.Dirty,\n ) as unknown as Computed<T>;\n}\n\n/** Runs now (or when the enclosing batch or drain ends), then on every change it read. */\nexport function effect(fn: () => void | (() => void)): Effect {\n const effectNode = watcher(fn, true);\n\n try {\n start(effectNode);\n } catch (error) {\n // W5: roll the unpublished watcher back. The rollback detaches before it\n // runs the cleanup, so a throwing cleanup still leaves nothing live, and\n // its error does not replace the run's (F5).\n try {\n stop(effectNode);\n } catch {\n /** F5 */\n }\n throw error;\n }\n\n return effectNode as unknown as Effect;\n}\n\n/**\n * Kernel `read` itself under the public type: a signal's flags are 0, so one\n * read path serves signals and computeds, and no surface function stands in\n * front of it.\n */\nexport const get: <T>(source: Readable<T>) => T = read as never;\n\n/** `get` without observation: up to date, but the running consumer does not depend on it. */\nexport const peek: <T>(source: Readable<T>) => T = refresh as never;\n\n/** Writes, then runs what the write scheduled; a write that woke nothing stops at one load. */\nexport function set<T>(source: Signal<T>, value: T): void {\n write(source as unknown as Node, value);\n\n if (size !== 0 && hold === 0) drainNow();\n}\n\n/**\n * `set(source, fn(current))`. An update is a write, not an observation:\n * `fn` runs untracked, so neither `source` nor what `fn` reads becomes a\n * dependency of the running consumer. If `fn` throws, nothing is written.\n */\nexport function update<T>(source: Signal<T>, fn: (value: T) => T): void {\n set(\n source,\n untracked(() => fn((source as unknown as Node).value as T)),\n );\n}\n\nexport function dispose(target: Computed<unknown> | Effect): void {\n const targetNode = target as unknown as Node;\n\n if ((targetNode.flags & Flag.Watch) !== 0) stop(targetNode);\n else detach(targetNode);\n}\n"],
5
+ "mappings": ";;;AAmGO,IAAM,SAAS,IAOT,UAAU,IAOV,SAAS,WAET,OAAO,GAOP,OAAO,GAMP,OAAO,KACP,OAAO;AAIb,SAAS,WAAW,IAAgB,OAAgB,OAAoB;AAC7E,SAAO;AAAA,IACL;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O,WAAW,MAAM,OAAO,CAAC;AAClC;AAUO,SAAS,SACd,IACA,SACa;AACb,SAAO;AAAA,IACL;AAAA,IACA;AAAA;AAAA,EAEF;AACF;AAGO,SAAS,OAAO,IAAuC;AAC5D,MAAM,aAAa,QAAQ,IAAI,EAAI;AAEnC,MAAI;AACF,UAAM,UAAU;AAAA,EAClB,SAAS,OAAO;AAId,QAAI;AACF,WAAK,UAAU;AAAA,IACjB,QAAQ;AAAA,IAER;AACA,UAAM;AAAA,EACR;AAEA,SAAO;AACT;AAOO,IAAM,MAAqC,MAGrCC,QAAsC;AAG5C,SAAS,IAAO,QAAmB,OAAgB;AACxD,QAAM,QAA2B,KAAK,GAElC,SAAS,KAAK,SAAS,KAAG,SAAS;AACzC;AAOO,SAAS,OAAU,QAAmB,IAA2B;AACtE;AAAA,IACE;AAAA,IACA,UAAU,MAAM,GAAI,OAA2B,KAAU,CAAC;AAAA,EAC5D;AACF;AAEO,SAASC,SAAQ,QAA0C;AAChE,MAAM,aAAa;AAEnB,GAAK,WAAW,QAAQ,oBAAgB,IAAG,KAAK,UAAU,IACrD,QAAO,UAAU;AACxB;",
6
+ "names": ["last", "budget", "wake", "wake", "peek", "dispose"]
7
7
  }
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- /* reflex-quant 1.1.1 | MIT */
2
- var x=-1,d=1073741823,B=536870911,T=8,V=256,I=512;function _(e,n,t){return{flags:t,value:n,ver:0,fn:e,deps:null,last:null,subs:null,lastSub:null,slot:null,gen:0}}function b(e,n,t,l){let o=n.prev,r=n.next;o.next=r,r!==null&&(r.prev=o),n.prev=t,n.next=l,t!==null?t.next=n:e.deps=n,l.prev=n,e.last=n}function m(e,n){let t=n===null?e.deps:n.next;if(t!==null)for(n===null?e.deps=null:n.next=null,t.prev=null;t!==null;t=t.next)h(t)}function M(e){let n=e.gen;for(let t=e.deps;t!==null;t=t.next)t.gen=n}function h(e){let n=e.from,t=e.prevSub,l=e.nextSub;t!==null?t.nextSub=l:n.subs=l,l!==null?l.prevSub=t:n.lastSub=t,e.prevSub=null,e.nextSub=null}var s=null,i=new Array(256).fill(null),f=0;var k=()=>{};function O(e){k=e}function $(){i.length=V}function P(e,n){if(!Object.is(e.value,n)){e.value=n,e.ver=e.ver+1&d;for(let t=e.subs;t!==null;t=t.nextSub){let l=t.to,o=l.flags;(o&4)!==0?(o&1)===0&&(l.flags=o|1,(o&16)!==0?k(l):l.subs!==null&&q(l.subs)):(o&16)!==0?(l.flags=o|2|32,k(l)):(o&1)!==0?l.flags=o|2:(l.flags=o|2|1,l.subs!==null&&q(l.subs))}}}function q(e){let n=f,t=e;for(;;){for(;t!==null;){let l=t.to,o=l.flags;if((o&16)!==0)l.flags=o|1,k(l);else if((o&1)===0&&(l.flags=o|1,l.subs!==null)){t.nextSub!==null&&(i[f++]=t.nextSub),t=l.subs;continue}t=t.nextSub}if(f===n)return;t=i[--f],i[f]=null}}function Q(e){let n=A(e),t=s;if(t!==null){let l=t.last,o=l===null?t.deps:l.next;o!==null&&o.from===e?(t.last=o,o.ver=e.ver):te(t,e,l,o)}return n}function A(e){return(e.flags&39)!==0&&N(e),e.value}function N(e){let n=e.flags;if((n&36)!==0)throw new Error("Cycle detected");if((n&2)!==0)return c(e);ee(e,n)}function ee(e,n){e.flags=n&-2;let t=f,l=e,o=e.deps;try{for(;;){e:for(;o!==null;){let r=o.from,u=r.flags;if((u&3)!==0){if((u&36)!==0)throw new Error("Cycle detected");if((u&2)===0){r.flags=u&-2,i[f++]=o,l=r,o=r.deps;continue}c(r)}if(r.ver!==o.ver){l.fn!==null&&c(l);break e}o=o.next}for(;;){if(f===t){i.length>I&&t===0&&$();return}let r=i[--f];if(i[f]=null,l=r.to,r.from.ver===r.ver){o=r.next;break}l.fn!==null&&c(l)}}}catch(r){for(l.fn!==null&&(l.flags=l.flags|2);f>t;){let u=i[--f].to;u.fn!==null&&(u.flags=u.flags|2),i[f]=null}throw r}}function G(e){let n=e.gen+1&d,t=e.deps;if((e.flags&2)===0)for(;t!==null;t=t.next){let l=t.from;if((l.flags&3)!==0&&t.gen!==n&&N(l),l.ver!==t.ver){e.flags|=2,t=t.next;break}}for(;t!==null;t=t.next){let l=t.from;(l.flags&3)!==0&&t.gen!==n&&N(l)}}function v(e){let n=s;s=null;try{return e()}finally{s=n}}function c(e){let n=s,t=f;e.flags=e.flags&-4|4,e.last=null,s=e;let l;try{l=e.fn(e.value)}catch(u){throw s=n,ne(e,t),u}s=n;let o=e.flags;if((o&8)!==0&&z(e,t),e.flags=o&-269,e.fn===null)return C(e);let r=e.last;(r===null?e.deps:r.next)!==null&&m(e,r),e.gen=e.gen+1&d,(e.gen&B)===0&&M(e),Object.is(l,e.value)===!1&&(e.value=l,e.ver=e.ver+1&d)}function ne(e,n){if((e.flags&8)!==0&&z(e,n),e.flags&=-269,e.fn===null)return C(e);e.flags|=2;let t=e.gen+1&d,l=e.last;for(let o=l===null?e.deps:l.next;o!==null;){let r=o.next;if(o.gen===t){let u=o.prev;u!==null?u.next=r:e.deps=r,r!==null&&(r.prev=u),h(o),o.prev=null,o.next=null}o=r}}function E(e){e.fn!==null&&(e.fn=null,(e.flags&4)===0&&C(e))}function C(e){m(e,null),e.flags&=-36}function L(e,n){e.flags|=8;let t=!1;for(let l=e.deps;l!==null;l=l.next)l===n&&(t=!0),t&&(l.ver=x),j(l.from,l)}function j(e,n){e.slot!==null&&(i[f++]=e,i[f++]=e.slot),e.slot=n}function z(e,n){for(let t=e.deps;t!==null;t=t.next)t.from.slot=null;for(;f>n;){let t=i[--f];i[f]=null;let l=i[--f];i[f]=null,l.slot=t}}function D(e,n,t,l){let o=n.lastSub,r={from:n,to:e,ver:n.ver,gen:e.gen+1&d,prev:t,next:l,prevSub:o,nextSub:null};t!==null?t.next=r:e.deps=r,l!==null&&(l.prev=r),o!==null?o.nextSub=r:n.subs=r,n.lastSub=r,e.last=r}function te(e,n,t,l){if(t!==null&&t.from===n)return;let o=e.flags;if((o&8)!==0)return U(e,n,t,l);let r;if((o&256)===0){if(n.subs===null)return D(e,n,t,l);let u=l!==null?l.next:null,y=T;for(;u!==null&&u.from!==n&&--y!==0;)u=u.next;if(u!==null&&u.from===n)return u.ver=n.ver,b(e,u,t,l);let a=t!==null?t.prev:null;for(y=T;a!==null&&a.from!==n&&--y!==0;)a=a.prev;if(a!==null&&a.from===n)return;r=u===null&&a===null?null:K(n,e),r!=null&&le(e,n,r,l)}else r=K(n,e);if(r===null)return D(e,n,t,l);if(r!==void 0)return H(e,r,n,t,l);L(e,l),U(e,n,t,l)}function U(e,n,t,l){let o=n.slot;if(o!==null&&o.to===e)return H(e,o,n,t,l);D(e,n,t,l),j(n,e.last)}function K(e,n){let t=T;for(let l=e.subs;l!==null;l=l.nextSub){if(l.to===n)return l;if(--t===0)return}return null}function le(e,n,t,l){if(t!==n.subs)return L(e,l);e.flags|=256;for(let o=l;o!==null;o=o.next)o.ver=x}function H(e,n,t,l,o){n.ver===x&&(n.ver=t.ver,b(e,n,l,o))}var w=[],p=0,S=0,g=!1;function J(e){(e.flags&192)===64&&(e.flags|=128,w[p++]=e)}O(J);function X(e,n){return _(e,void 0,19|(n?64:0))}function oe(e){let n=e.flags;if(e.fn===null||(n&33)===0)return;if(e.flags=n&-34,(n&1)!==0)try{G(e)}catch(l){throw e.flags|=1,l}if((e.flags&2)===0||e.fn===null)return;let t=e.value;typeof t=="function"&&(e.value=void 0,v(t),e.fn===null)||c(e)}function W(e){if(e.fn===null)return;let n=e.value;e.value=void 0,E(e),typeof n=="function"&&v(n)}function Y(){p===0||g||S!==0||R()}function R(){g=!0,F(!1,void 0)}function Z(e){if(g||S!==0||p!==0)return J(e),Y();g=!0;try{c(e)}catch(n){return F(!0,n)}F(!1,void 0)}function F(e,n){for(let t=0;t<p;t++){let l=w[t];w[t]=null,l.flags&=-129;try{oe(l)}catch(o){e||(n=o),e=!0}}if(p=0,g=!1,e)throw n}function re(e){S++;try{return e()}finally{--S===0&&Y()}}function ve(e){return _(null,e,0)}function Se(e,n){return _(e,n,2)}function xe(e){let n=X(e,!0);try{Z(n)}catch(t){throw W(n),t}return n}var Te=Q,ke=A;function ue(e,n){P(e,n),p!==0&&!g&&S===0&&R()}function Ee(e,n){ue(e,v(()=>n(e.value)))}function ye(e){let n=e;(n.flags&16)!==0?W(n):E(n)}export{re as batch,Se as computed,ye as dispose,xe as effect,Te as get,ke as peek,ue as set,ve as signal,v as untracked,Ee as update};
1
+ /* reflex-quant 1.2.0 | MIT */
2
+ var v=-1,P=-2,L=536870911,N=8,Q=2,D=256,b=512;function S(e,n,t){return{flags:t,value:n,ver:0,fn:e,firstDep:null,lastDep:null,firstSub:null,slot:null,gen:0}}function x(e,n,t,l){let o=n.prevDep,r=n.nextDep;o.nextDep=r,r!==null?r.prevDep=o:e.lastDep=o,n.prevDep=t,n.nextDep=l,t!==null?t.nextDep=n:e.firstDep=n,l.prevDep=n}function U(e,n,t,l){let o=t.nextDep,r=e.lastDep;n!==null?n.nextDep=o:e.firstDep=o,o.prevDep=n,t.prevDep=r,t.nextDep=null,r.nextDep=t,e.lastDep=t,r.ver===v&&(t.ver=v),l!==o&&x(e,l,n,o)}function W(e,n){let t=n===null?e.firstDep:n.nextDep;if(t!==null)for(n===null?e.firstDep=null:n.nextDep=null,e.lastDep=n,t.prevDep=null;t!==null;t=t.nextDep)R(t)}function G(e){let n=e.gen;for(let t=e.firstDep;t!==null;t=t.nextDep)t.gen=n}function R(e){let n=e.from,t=e.prevSub,l=e.nextSub;e===n.firstSub?n.firstSub=l:t.nextSub=l,l!==null?l.prevSub=t:n.firstSub!==null&&(n.firstSub.prevSub=t),e.prevSub=null,e.nextSub=null}var H=Object.is,c=null,i=null,s=new Array(256).fill(null),f=0;var h=()=>{};function J(e){h=e}function y(){s.length>b&&f===0&&(s.length=D)}function X(e,n){if(!H(e.value,n)){e.value=n,e.ver=e.ver+1&1073741823;for(let t=e.firstSub;t!==null;t=t.nextSub){let l=t.to,o=l.flags;if((o&4)!==0){if((o&1)===0)if(l.flags=o|1,(o&16)!==0)h(l);else{let r=l.firstSub;r!==null&&z(r)}}else if((o&16)!==0)l.flags=o|2|32,h(l);else if((o&1)!==0)l.flags=o|2;else{l.flags=o|2|1;let r=l.firstSub;r!==null&&z(r)}}}}function z(e){let n=f,t=e;for(;;){for(;t!==null;){let l=t.to,o=l.flags;if((o&16)!==0)l.flags=o|1,h(l);else if((o&1)===0){l.flags=o|1;let r=l.firstSub;if(r!==null){let u=t.nextSub;u!==null&&(s[f++]=u),t=r;continue}}t=t.nextSub}if(f===n){y();return}t=s[--f],s[f]=null}}function Y(e){let n=V(e),t=c;if(t!==null){let l=i,o=l===null?t.firstDep:l.nextDep;o!==null&&o.from===e?(i=o,o.ver=e.ver):l!==null?l.from!==e&&j(t,e,l,o):o!==null?j(t,e,l,o):k(t,e,null,null)}return n}function V(e){return(e.flags&39)!==0&&M(e),e.value}function M(e){let n=e.flags;if((n&36)!==0)throw new Error("Cycle detected");if((n&2)!==0)return _(e);ae(e,n)}function ae(e,n){e.flags=n&-2;let t=f,l=e,o=e.firstDep;try{for(;;){e:for(;o!==null;){let r=o.from,u=r.flags;if((u&3)!==0){if((u&36)!==0)throw new Error("Cycle detected");if((u&2)===0){r.flags=u&-2,s[f++]=o,l=r,o=r.firstDep;continue}_(r)}if(r.ver!==o.ver){l.fn!==null&&_(l);break e}o=o.nextDep}for(;;){if(f===t){y();return}let r=s[--f];if(s[f]=null,l=r.to,r.from.ver===r.ver){o=r.nextDep;break}l.fn!==null&&_(l)}}}catch(r){for(l.fn!==null&&(l.flags=l.flags|2);f>t;){let u=s[--f].to;u.fn!==null&&(u.flags=u.flags|2),s[f]=null}throw y(),r}}function Z(e){let n=e.gen+1&1073741823,t=e.firstDep;if((e.flags&2)===0)for(;t!==null;t=t.nextDep){let l=t.from;if((l.flags&3)!==0&&t.gen!==n&&M(l),l.ver!==t.ver){e.flags|=2,t=t.nextDep;break}}for(;t!==null;t=t.nextDep){let l=t.from;(l.flags&3)!==0&&t.gen!==n&&M(l)}}function T(e){let n=c;c=null;try{return e()}finally{c=n}}function _(e){let n=c,t=i,l=f;e.flags=e.flags&-4|4,c=e,i=null;let o;try{o=e.fn(e.value)}catch(w){let C=i;throw c=n,i=t,pe(e,l,C),w}let r=i;c=n,i=t;let u=e.flags;if(r!==null&&r.from.slot===r&&ne(e,l),e.flags=u&-5,e.fn===null)return I(e);(r===null?e.firstDep:r.nextDep)!==null&&W(e,r),e.gen=e.gen+1&1073741823,(e.gen&L)===0&&G(e),H(o,e.value)===!1&&(e.value=o,e.ver=e.ver+1&1073741823)}function pe(e,n,t){if(t!==null&&t.from.slot===t&&ne(e,n),e.flags&=-5,e.fn===null)return I(e);e.flags|=2;let l=e.gen+1&1073741823;for(let o=t===null?e.firstDep:t.nextDep;o!==null;){let r=o.nextDep;if(o.gen===l){let u=o.prevDep;u!==null?u.nextDep=r:e.firstDep=r,r!==null?r.prevDep=u:e.lastDep=u,R(o),o.prevDep=null,o.nextDep=null}o=r}}function A(e){e.fn!==null&&(e.fn=null,(e.flags&4)===0&&I(e))}function I(e){W(e,null),e.flags&=-36}function $(e,n){let t=!1;for(let l=e.firstDep;l!==null;l=l.nextDep)l===n&&(t=!0),t&&(l.ver=v),ee(l.from,l)}function ee(e,n){let t=e.slot;t!==null&&(s[f++]=t),e.slot=n}function ne(e,n){for(let t=e.firstDep;t!==null;t=t.nextDep)t.from.slot=null;for(;f>n;){let t=s[--f];s[f]=null,t.from.slot=t}y()}function k(e,n,t,l){let o=n.firstSub,r=o!==null?o.prevSub:null,u={from:n,to:e,ver:n.ver,gen:e.gen+1&1073741823,prevDep:t,nextDep:l,prevSub:r,nextSub:null};t!==null?t.nextDep=u:e.firstDep=u,l!==null?l.prevDep=u:e.lastDep=u,o!==null?(r.nextSub=u,o.prevSub=u):(n.firstSub=u,u.prevSub=u),i=u}function j(e,n,t,l){if(t!==null&&t.from.slot===t)return oe(e,n,t,l);let o=n.firstSub;if(o===null||ve(o,e))return k(e,n,t,l);if(l!==null&&l.ver===v)return le(e,n,t,l,re(o,e));if(l!==null){let r=l.nextDep;if(r!==null&&r.from===n)return te(e,n,t,l,r);let u=Q;for(r=e.lastDep;r!==l&&r.from!==n&&--u!==0;)r=r.prevDep;if(r.from===n)return r.ver=n.ver,i=r,x(e,r,t,l)}ce(e,n,t,l,o)}function ce(e,n,t,l,o){let r=null;if(l!==null){let C=N;for(r=l.nextDep;r!==null&&r.from!==n&&--C!==0;)r=r.nextDep;if(r!==null&&r.from===n)return te(e,n,t,l,r)}let u=t!==null?t.prevDep:null,w=N;for(;u!==null&&u.from!==n&&--w!==0;)u=u.prevDep;if(!(u!==null&&u.from===n)){if(r===null&&u===null)return k(e,n,t,l);ge(e,n,t,l,o)}}function te(e,n,t,l,o){if(o.ver=n.ver,i=o,l.ver===P)return U(e,t,l,o);l.ver=P,x(e,o,t,l)}function ge(e,n,t,l,o){let r=re(o,e);r!=null&&_e(e,r,o,l),le(e,n,t,l,r)}function le(e,n,t,l,o){if(o===null)return k(e,n,t,l);if(o!==void 0)return ue(e,o,n,t,l);$(e,l),oe(e,n,t,l)}function oe(e,n,t,l){let o=n.slot;if(o!==null&&o.to===e)return ue(e,o,n,t,l);k(e,n,t,l),ee(n,i)}function ve(e,n){let t=e.prevSub;return e.to!==n&&t.to!==n&&(t===e||e.nextSub===t)}function re(e,n){let t=N;for(let l=e;l!==null;l=l.nextSub){if(l.to===n)return l;if(--t===0)return}return null}function _e(e,n,t,l){if(l!==null){if(n!==t)return $(e,l);for(let o=l;o!==null;o=o.nextDep)o.ver=v}}function ue(e,n,t,l,o){n.ver===v&&(n.ver=t.ver,x(e,n,l,o),i=n)}var E=new Array(D).fill(null),p=D-1,g=0,O=0,m=0,d=0,a=0;function fe(e){let n=e.flags;(n&192)===64&&(e.flags=n|128,d>p&&De(),E[g+d++&p]=e)}J(fe);function De(){let e=new Array(d+d).fill(null);for(let n=0;n<d;n++)e[n]=E[g+n&p];E=e,p=d+d-1,g=0}function ie(e,n){return S(e,void 0,19|(n?64:0))}function Se(e,n){if(e.fn===null||(n&33)===0){e.flags=n;return}if(e.flags=n&-34,(n&1)!==0){try{Z(e)}catch(l){throw e.flags|=1,l}if((e.flags&2)===0||e.fn===null)return}let t=e.value;typeof t=="function"&&(e.value=void 0,T(t),e.fn===null)||_(e)}function K(e){if(e.fn===null)return;let n=e.value;e.value=void 0,A(e),typeof n=="function"&&T(n)}function q(){d===0||a!==0||F()}function F(){a=1,B(!1,void 0)}function se(e){if(a!==0||d!==0)return fe(e),q();a=1;try{_(e)}catch(n){return B(!0,n)}B(!1,void 0)}function B(e,n){let t=0;for(;d!==0;t++){let l=E[g];E[g]=null,g=g+1&p,d--;try{Se(l,l.flags&-129)}catch(o){e||(n=o),e=!0}}if(g=0,p>=b&&(t+t<p>>1?(t>m&&(m=t),(O+=t)>p&&Te(m)):O=m=0),a=0,e)throw n}function Te(e){let n=D;for(;n<e+e;)n+=n;E.length=n,p=n-1,O=m=0}function Ee(e){a++;let n;try{n=e()}catch(t){if(--a===0)try{q()}catch{}throw t}return--a===0&&q(),n}function We(e){let n=e;return(n.flags&16)!==0?"effect":n.fn===null?"signal":"computed"}function Re(e){return S(null,e,0)}function Me(e,n){return S(e,n,2)}function Ve(e){let n=ie(e,!0);try{se(n)}catch(t){try{K(n)}catch{}throw t}return n}var Ie=Y,Oe=V;function xe(e,n){X(e,n),d!==0&&a===0&&F()}function qe(e,n){xe(e,T(()=>n(e.value)))}function Be(e){let n=e;(n.flags&16)!==0?K(n):A(n)}export{Ee as batch,Me as computed,Be as dispose,Ve as effect,Ie as get,Oe as peek,xe as set,Re as signal,We as typeOf,T as untracked,qe as update};
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/graph.ts", "../src/kernel.ts", "../src/host.ts", "../src/index.ts"],
4
- "sourcesContent": ["import { stats } from \"./instrumentation\";\n\n// Compile-time vocabulary of the runtime graph. Nothing here exists at runtime.\n\n// The aliases name different facts but do not brand numbers: counters wrap at\n// MASK and edge versions can carry UNREAD.\nexport type Flags = number;\nexport type Version = number;\nexport type Generation = number;\n\n/** A computed's or watcher's body; a signal has none. */\nexport type Fn = (prev: unknown) => unknown;\n/** A watcher's cleanup, run untracked. */\nexport type Cleanup = () => unknown;\n\nexport interface Node {\n flags: Flags;\n value: unknown;\n /** Bumps on every Object.is-visible change of value. */\n ver: Version;\n /** null for a signal and for a disposed node. */\n fn: Fn | null;\n /** Sources, in read order. */\n deps: Edge | null;\n /** The running pass's last accepted source edge. */\n last: Edge | null;\n /** Subscribers, in birth order. */\n subs: Edge | null;\n lastSub: Edge | null;\n /** While a reader indexes: this node's edge into that reader. */\n slot: Edge | null;\n /** Successful runs; edges born since the last one are tentative. */\n gen: Generation;\n}\n\nexport interface Edge {\n readonly from: Node;\n readonly to: Node;\n /** from.ver when `to` read it; UNREAD while indexed and not yet read. */\n ver: Version | typeof UNREAD;\n /** to.gen + 1 at birth: tentative while it still equals to.gen + 1. */\n gen: Generation;\n prev: Edge | null;\n next: Edge | null;\n prevSub: Edge | null;\n nextSub: Edge | null;\n}\n\n/** Shared LIFO of the kernel's walks: edges, and (source, cell) pairs. */\nexport type WorkStack = (Node | Edge | null)[];\n\n// Flag layout and constants used by the kernel and host.\nexport const enum Flag {\n /** A source below may have changed; a watcher must validate. */\n Stale = 1 << 0,\n /** Must run: first run, failed run, or a direct source changed. */\n Dirty = 1 << 1,\n /** Its run is on the stack. */\n Busy = 1 << 2,\n /** Its run put its edges into the sources' slots. */\n Indexed = 1 << 3,\n /** A watcher: handed to the host, never read. */\n Watch = 1 << 4,\n /** Woken by signals only; computed sources need no validation. */\n Woken = 1 << 5,\n /**\n * Development builds only (C1 is a precondition): a computed whose\n * validation is on the stack, no longer STALE and not yet clean. WOKEN's\n * bit, so every mask stays a byte: WOKEN is a watcher's, CHECKING a\n * computed's, and no node is both. A production build never sets it, so\n * a mask that tests it is inert there.\n */\n Checking = 1 << 5,\n /** Host policy: scheduled by the reference host. */\n Auto = 1 << 6,\n /** Host policy: already in its queue. */\n Queued = 1 << 7,\n /** Its run marked its unread edges UNREAD; pairs are found through subscribers. */\n Marked = 1 << 8,\n}\n\n/** edge.ver of an edge the marked or indexed run has not read yet. */\nexport const UNREAD = -1;\n/** Counters wrap inside the SMI range. */\nexport const MASK = 0x3fffffff;\n/**\n * A committed edge keeps its birth generation, and generations wrap: an edge\n * 2^30 - 1 commits old would read as born in the next run (tentative). So a\n * node restamps its edges with its own generation whenever a commit makes\n * `gen & SETTLE` zero, twice a cycle, and no edge falls that far behind.\n */\nexport const SETTLE = 0x1fffffff;\n/** Scan budget of every bounded search: a constant keeps a run linear. */\nexport const SCAN = 8;\n/**\n * Work-stack slots kept at rest, and the length past which the outermost\n * walk's end cuts the stack back to them. The gap keeps walks only a little\n * deeper than KEEP from cutting and regrowing on every pass.\n */\nexport const KEEP = 256;\nexport const TRIM = 512;\n\n// Intrusive graph operations independent of the execution context.\n\nexport function node(fn: Node[\"fn\"], value: unknown, flags: Flags): Node {\n return {\n flags,\n value,\n ver: 0,\n fn,\n deps: null,\n last: null,\n subs: null,\n lastSub: null,\n slot: null,\n gen: 0,\n };\n}\n\n/** Move an unread edge (strictly after `next`) up to the cursor. */\nexport function move(c: Node, e: Edge, last: Edge | null, next: Edge): void {\n const before = e.prev!;\n const after = e.next;\n before.next = after;\n\n if (after !== null) after.prev = before;\n\n e.prev = last;\n e.next = next;\n\n if (last !== null) last.next = e;\n else c.deps = e;\n next.prev = e;\n c.last = e;\n}\n\n/** Remove every edge of `c` after `last` (all of them when null). */\nexport function cut(c: Node, last: Edge | null): void {\n let e = last === null ? c.deps : last.next;\n\n if (e === null) return;\n\n if (last === null) c.deps = null;\n else last.next = null;\n // The cut head's back pointer would tie this garbage to the live list, and\n // so to garbage cut later: old garbage keeps newer garbage alive.\n e.prev = null;\n\n for (; e !== null; e = e.next) unsub(e);\n}\n\n/** Restamp every edge of `c`, all of them committed, with its generation (SETTLE). */\nexport function settle(c: Node): void {\n const gen = c.gen;\n\n for (let e = c.deps; e !== null; e = e.next) e.gen = gen;\n}\n\n/** Take an edge out of its source's subscriber list. */\nexport function unsub(e: Edge): void {\n if (__STATS__) stats.unlinks++;\n\n const s = e.from;\n const before = e.prevSub;\n const after = e.nextSub;\n\n if (before !== null) before.nextSub = after;\n else s.subs = after;\n\n if (after !== null) after.prevSub = before;\n else s.lastSub = before;\n // Subscribers are in birth order, so an old removed edge would point at a\n // much younger one and keep it (and its watcher) alive across scavenges.\n e.prevSub = null;\n e.nextSub = null;\n}\n", "// Reactive kernel: tracking, propagation, validation and execution.\n// Detached edges must not retain pointers into live lists.\n// See research/LOG.md for representation rationale.\n\nimport {\n Flag,\n KEEP,\n MASK,\n SCAN,\n SETTLE,\n TRIM,\n UNREAD,\n cut,\n move,\n settle,\n unsub,\n} from \"./graph\";\nimport type { Edge, Flags, Node, WorkStack } from \"./graph\";\nimport { stats } from \"./instrumentation\";\n\nexport { node } from \"./graph\";\nexport { stats } from \"./instrumentation\";\n\n/** The running consumer, or null outside a tracking pass. */\nlet active: Node | null = null;\n/**\n * One LIFO work stack shared by all walks: sibling edges to resume (mark),\n * edges to climb back through (pull), and (source, cell) pairs an indexed run\n * displaced. Every walk pops back to its own base before returning, and the\n * outermost one gives back what a deep walk grew (`trim`).\n */\nconst stack: WorkStack = new Array(256).fill(null);\n/** First free index of `stack`. */\nlet top = 0;\n/** Longest the work stack has been when `trim` cut it (research). */\nlet peak = 0;\nlet wake: (w: Node) => void = () => {};\n\n/**\n * The host is told about every watcher a write or mark reaches. It owns the\n * deduplication (a queued watcher is not queued again), so a watcher left\n * STALE by a failed check is delivered again by the next push.\n */\nexport function onWake(fn: (w: Node) => void): void {\n wake = fn;\n}\n\n/** Nothing running, the work stack empty (tests). */\nexport function idle(): boolean {\n return active === null && top === 0;\n}\n\n/**\n * Deepest work-stack top reached so far (research). Walks null the slots\n * they pop and only `trim` shrinks the array, so the high-water mark is its\n * length or the longest length `trim` cut.\n */\nexport function stackHighWater(): number {\n return stack.length > peak ? stack.length : peak;\n}\n\n/** Slots the work stack holds now (tests). */\nexport function stackLength(): number {\n return stack.length;\n}\n\n/**\n * At rest, cut a stack that a deep walk grew past TRIM back to KEEP slots,\n * so one deep walk does not hold its depth in memory for good. Setting the\n * length right-trims V8's backing store in place: no allocation, and the\n * array stays packed.\n *\n * Only the end of an outermost validation calls it (top 0), whichever walk\n * grew the stack. A deep mark walk runs through computeds that are STALE\n * afterwards, so their next demand is such a validation; `write` and `mark`\n * stay as they were. The guard costs one length load and one compare per\n * validation, nothing per node.\n */\nfunction trim(): void {\n if (__STATS__ && stack.length > peak) peak = stack.length;\n\n stack.length = KEEP;\n}\n\n// ------------------------------------------------------------------- write\n\nexport function write(s: Node, value: unknown): void {\n if (Object.is(s.value, value)) return;\n\n s.value = value;\n s.ver = (s.ver + 1) & MASK;\n\n for (let e = s.subs; e !== null; e = e.nextSub) {\n const n = e.to;\n const f = n.flags;\n\n if (__STATS__) stats.marks++;\n\n if ((f & Flag.Busy) !== 0) {\n // Running: it may not have read s yet, so versions decide.\n if ((f & Flag.Stale) === 0) {\n n.flags = f | Flag.Stale;\n\n if ((f & Flag.Watch) !== 0) wake(n);\n else if (n.subs !== null) mark(n.subs);\n }\n } else if ((f & Flag.Watch) !== 0) {\n n.flags = f | Flag.Dirty | Flag.Woken;\n\n wake(n);\n } else if ((f & Flag.Stale) !== 0) {\n n.flags = f | Flag.Dirty;\n } else {\n n.flags = f | Flag.Dirty | Flag.Stale;\n\n if (n.subs !== null) mark(n.subs);\n }\n }\n}\n\n/** Mark everything below the subscriber list `first` STALE, depth first. */\nfunction mark(first: Edge): void {\n const base = top;\n let e: Edge | null = first;\n\n for (;;) {\n while (e !== null) {\n const n: Node = e.to;\n const f = n.flags;\n\n if (__STATS__) stats.marks++;\n // A watcher has no subscribers; the host deduplicates, so it is always told.\n if ((f & Flag.Watch) !== 0) {\n n.flags = f | Flag.Stale;\n wake(n);\n } else if ((f & Flag.Stale) === 0) {\n n.flags = f | Flag.Stale;\n\n if (n.subs !== null) {\n if (e.nextSub !== null) stack[top++] = e.nextSub;\n\n e = n.subs;\n continue;\n }\n }\n e = e.nextSub;\n }\n\n if (top === base) return;\n\n e = stack[--top] as Edge;\n stack[top] = null;\n }\n}\n\n// -------------------------------------------------------------------- read\n\n/** Bring `n` up to date if it is a stale computed, then track it. */\nexport function read(n: Node): unknown {\n const value = peek(n);\n const c = active;\n\n if (c !== null) {\n if (__STATS__) stats.reads++;\n\n const last = c.last;\n const next = last === null ? c.deps : last.next;\n\n if (next !== null && next.from === n) {\n if (__STATS__) stats.hits++;\n\n c.last = next;\n next.ver = n.ver;\n } else miss(c, n, last, next);\n }\n return value;\n}\n\n/** `read` without its tracking half: bring `n` up to date, record no relation. */\nexport function peek(n: Node): unknown {\n if ((n.flags & (Flag.Stale | Flag.Dirty | Flag.Busy | Flag.Checking)) !== 0)\n pull(n);\n\n return n.value;\n}\n\n/**\n * Pull a computed up to date. Existential, in read order: sources are\n * checked first to last and the first changed one makes the node run. A\n * STALE source is descended into (the stack keeps the edge to climb back\n * through); a DIRTY one runs. A throw leaves every node on the walk DIRTY.\n * A node whose run is on the stack is a cycle. A development build also\n * diagnoses a node whose validation is on the stack (CHECKING): C1 is a\n * precondition, so its committed value never answers such a demand there.\n */\nfunction pull(root: Node): void {\n const f = root.flags;\n\n if ((f & (Flag.Busy | Flag.Checking)) !== 0)\n throw new Error(\"Cycle detected\");\n\n if ((f & Flag.Dirty) !== 0) return exec(root);\n\n verify(root, f);\n}\n\n/**\n * The walk of `pull` for a STALE node that is not DIRTY, BUSY or CHECKING;\n * kept apart so `pull` stays small. A node disposed during the walk is not\n * run (W3), nor left DIRTY.\n *\n * Development builds diagnose C1: a node on the walk is CHECKING until it is\n * clean or runs, and a source on the stack (BUSY or CHECKING) is a cycle\n * even when no push marked it again, since its version is not yet a fact.\n * CHECKING is set by the store that clears STALE and cleared by `exec` as it\n * sets BUSY; only a node found clean pays a store of its own. Production\n * builds compile all of it away.\n */\nfunction verify(root: Node, f: Flags): void {\n root.flags = __DEV__ ? (f & ~Flag.Stale) | Flag.Checking : f & ~Flag.Stale;\n const base = top;\n let n = root;\n let e = root.deps;\n\n try {\n for (;;) {\n settled: {\n while (e !== null) {\n const s: Node = e.from;\n const sf = s.flags;\n\n if (__STATS__) stats.checks++;\n\n if (\n (sf &\n (__DEV__\n ? Flag.Stale | Flag.Dirty | Flag.Busy | Flag.Checking\n : Flag.Stale | Flag.Dirty)) !==\n 0\n ) {\n if ((sf & (Flag.Busy | Flag.Checking)) !== 0)\n throw new Error(\"Cycle detected\");\n\n if ((sf & Flag.Dirty) === 0) {\n s.flags = __DEV__\n ? (sf & ~Flag.Stale) | Flag.Checking\n : sf & ~Flag.Stale;\n stack[top++] = e;\n n = s;\n e = s.deps;\n continue;\n }\n exec(s);\n }\n\n if (s.ver !== e.ver) {\n if (n.fn !== null) exec(n);\n break settled;\n }\n e = e.next;\n }\n // Every source unchanged: clean, and no longer on the walk.\n if (__DEV__) n.flags &= ~Flag.Checking;\n }\n\n // Climb; a parent whose child changed runs as well.\n for (;;) {\n if (top === base) {\n if (stack.length > TRIM && base === 0) trim();\n\n return;\n }\n\n const up = stack[--top] as Edge;\n stack[top] = null;\n n = up.to;\n\n if (up.from.ver === up.ver) {\n e = up.next;\n break;\n }\n\n if (n.fn !== null) exec(n);\n }\n }\n } catch (error) {\n if (n.fn !== null)\n n.flags = __DEV__\n ? (n.flags | Flag.Dirty) & ~Flag.Checking\n : n.flags | Flag.Dirty;\n\n while (top > base) {\n const p = (stack[--top] as Edge).to;\n\n if (p.fn !== null)\n p.flags = __DEV__\n ? (p.flags | Flag.Dirty) & ~Flag.Checking\n : p.flags | Flag.Dirty;\n stack[top] = null;\n }\n throw error;\n }\n}\n\n/**\n * Universal check of a watcher: pull every committed source, so a throwing\n * one surfaces before any irreversible step. Marks DIRTY on change. Tentative\n * edges (reads of a failed run) only wake; they exist only while a run is\n * owed, and then versions need no comparison.\n */\nexport function check(w: Node): void {\n const tentative = (w.gen + 1) & MASK;\n let e = w.deps;\n\n // Until a run is owed, versions decide; then only the pulls remain. A\n // development build pulls a source on the stack too, so the C1 diagnosis\n // fails here, before the cleanup (P4).\n if ((w.flags & Flag.Dirty) === 0) {\n for (; e !== null; e = e.next) {\n const s = e.from;\n\n if (__STATS__) stats.checks++;\n\n if (\n (s.flags &\n (__DEV__\n ? Flag.Stale | Flag.Dirty | Flag.Busy | Flag.Checking\n : Flag.Stale | Flag.Dirty)) !==\n 0 &&\n e.gen !== tentative\n )\n pull(s);\n\n if (s.ver !== e.ver) {\n w.flags |= Flag.Dirty;\n e = e.next;\n break;\n }\n }\n }\n\n for (; e !== null; e = e.next) {\n if (__STATS__) stats.checks++;\n\n const s = e.from;\n\n if (\n (s.flags &\n (__DEV__\n ? Flag.Stale | Flag.Dirty | Flag.Busy | Flag.Checking\n : Flag.Stale | Flag.Dirty)) !==\n 0 &&\n e.gen !== tentative\n )\n pull(s);\n }\n}\n\nexport function untracked<T>(fn: () => T): T {\n const prev = active;\n active = null;\n\n try {\n return fn();\n } finally {\n active = prev;\n }\n}\n\n// --------------------------------------------------------------------- run\n\n/** Run `n.fn` as a tracking pass; commit value and edges on success. */\nexport function exec(n: Node): void {\n const prev = active;\n const base = top;\n\n if (__STATS__) stats.runs++;\n // Cleared before the run: a push during it marks the node again. In a\n // development build a computed's validation ends here, BUSY taking over\n // from CHECKING; on a watcher the bit is WOKEN, which this run discharges.\n n.flags =\n (n.flags &\n ~(__DEV__\n ? Flag.Stale | Flag.Dirty | Flag.Checking\n : Flag.Stale | Flag.Dirty)) |\n Flag.Busy;\n n.last = null;\n active = n;\n let value: unknown;\n\n try {\n value = n.fn!(n.value);\n } catch (error) {\n active = prev;\n fail(n, base);\n throw error;\n }\n active = prev;\n const f = n.flags;\n\n if ((f & Flag.Indexed) !== 0) unindex(n, base);\n\n n.flags = f & ~(Flag.Busy | Flag.Indexed | Flag.Marked);\n\n if (n.fn === null) return detach(n);\n // Commit only after a successful run. Dropping the unread suffix removes\n // sources that this pass no longer depends on.\n const last = n.last as Edge | null;\n\n if ((last === null ? n.deps : last.next) !== null) cut(n, last);\n\n n.gen = (n.gen + 1) & MASK;\n\n // Every edge is committed now; see SETTLE.\n if ((n.gen & SETTLE) === 0) settle(n);\n\n if (Object.is(value, n.value) === false) {\n n.value = value;\n n.ver = (n.ver + 1) & MASK;\n }\n}\n\n/**\n * A failed run: keep committed edges and this run's reads as the wake set,\n * drop unread edges earlier failed runs left behind, owe a run.\n */\nfunction fail(n: Node, base: number): void {\n if ((n.flags & Flag.Indexed) !== 0) unindex(n, base);\n\n n.flags &= ~(Flag.Busy | Flag.Indexed | Flag.Marked);\n\n if (n.fn === null) return detach(n);\n\n n.flags |= Flag.Dirty;\n const tentative = (n.gen + 1) & MASK;\n const last = n.last;\n\n for (let e = last === null ? n.deps : last.next; e !== null;) {\n const after: Edge | null = e.next;\n\n if (e.gen === tentative) {\n const before = e.prev;\n\n if (before !== null) before.next = after;\n else n.deps = after;\n\n if (after !== null) after.prev = before;\n\n unsub(e);\n e.prev = null;\n e.next = null;\n }\n e = after;\n }\n}\n\n/** Detach `n` from its sources for good; inside its own run, at its end. */\nexport function dispose(n: Node): void {\n if (n.fn === null) return;\n\n n.fn = null;\n\n if ((n.flags & Flag.Busy) === 0) detach(n);\n}\n\nfunction detach(n: Node): void {\n cut(n, null);\n n.flags &= ~(Flag.Stale | Flag.Dirty | Flag.Woken);\n}\n\n// ---------------------------------------------------------------- tracking\n\n/** Put every edge of `c` into its source's slot; mark the unread ones. */\nexport function index(c: Node, next: Edge | null): void {\n if (__STATS__) stats.indexes++;\n\n c.flags |= Flag.Indexed;\n let unread = false;\n\n for (let e = c.deps; e !== null; e = e.next) {\n if (__STATS__) stats.indexed++;\n\n if (e === next) unread = true;\n\n if (unread) e.ver = UNREAD;\n\n claim(e.from, e);\n }\n}\n\n/** Point the source's slot at `e`, keeping a displaced cell (an enclosing run's) to give back. */\nexport function claim(s: Node, e: Edge): void {\n if (s.slot !== null) {\n stack[top++] = s;\n stack[top++] = s.slot;\n }\n s.slot = e;\n}\n\n/** Clear the run's slots, give back the cells it displaced. */\nfunction unindex(n: Node, base: number): void {\n for (let e = n.deps; e !== null; e = e.next) e.from.slot = null;\n\n while (top > base) {\n const cell = stack[--top] as Edge;\n stack[top] = null;\n const s = stack[--top] as Node;\n stack[top] = null;\n s.slot = cell;\n }\n}\n\n/** A new edge at the cursor, appended to the source's subscribers. */\nexport function link(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n): void {\n if (__STATS__) stats.links++;\n\n const tail = s.lastSub;\n const e: Edge = {\n from: s,\n to: c,\n ver: s.ver,\n gen: (c.gen + 1) & MASK,\n prev: last,\n next,\n prevSub: tail,\n nextSub: null,\n };\n\n if (last !== null) last.next = e;\n else c.deps = e;\n\n if (next !== null) next.prev = e;\n\n if (tail !== null) tail.nextSub = e;\n else s.subs = e;\n s.lastSub = e;\n c.last = e;\n}\n\n// Exact dependency tracking: resolve a read outside the stable cursor path.\n// Proofs come cheapest first: the cursor (in `read`), the previous read, a\n// source nobody reads, bounded scans of this reader's list, then the source's\n// first subscribers. Only a source with more subscribers than the budget needs\n// the slot index. Slot walks and edge creation remain in the kernel because\n// they mutate its shared stack.\n\n/**\n * A read that is not the next edge in read order. Every answer is exact. A\n * repeated read keeps the version of the pass's first observation (P5): a\n * change between the two reads stays visible to the next validation.\n */\nfunction miss(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n if (last !== null && last.from === s) {\n if (__STATS__) stats.repeats++;\n\n return;\n }\n\n const f = c.flags;\n\n if ((f & Flag.Indexed) !== 0) return slot(c, s, last, next);\n /** The pair's edge through the source's subscribers; undefined: unknown. */\n let found: Edge | null | undefined;\n\n if ((f & Flag.Marked) === 0) {\n // A source without subscribers is absent.\n if (s.subs === null) return link(c, s, last, next);\n // An edge found by a scan is the pair's only one; absence needs one side\n // scanned completely (this reader's list, or the source's subscribers).\n let e = next !== null ? next.next : null;\n let budget = SCAN;\n\n while (e !== null && e.from !== s && --budget !== 0) e = e.next;\n\n if (e !== null && e.from === s) {\n if (__STATS__) stats.scans++;\n\n e.ver = s.ver;\n return move(c, e, last, next!);\n }\n let p = last !== null ? last.prev : null;\n budget = SCAN;\n\n while (p !== null && p.from !== s && --budget !== 0) p = p.prev;\n\n if (p !== null && p.from === s) {\n if (__STATS__) stats.dups++;\n\n return;\n }\n\n // Absent if this reader's whole list was scanned; otherwise the source's\n // first subscribers decide. Found as the first one: a lookup through the\n // subscribers costs no load beyond the read itself, so mark the unread\n // suffix and let the rest of the pass find its pairs that way, with no\n // slot to fill or clear. Found deeper: every lookup would walk other\n // readers' edges, so index; either way the found edge is taken at once.\n found = e === null && p === null ? null : pair(s, c);\n\n if (found !== null && found !== undefined) begin(c, s, found, next);\n } else found = pair(s, c);\n\n if (found === null) return link(c, s, last, next);\n\n if (found !== undefined) return take(c, found, s, last, next);\n // Past the budget: index the pass, and the slot decides from here on.\n index(c, next);\n slot(c, s, last, next);\n}\n\n/** An indexed pass's lookup: the source's slot holds the pair's edge, or the pair is absent. */\nfunction slot(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n if (__STATS__) stats.lookups++;\n\n const cell = s.slot;\n\n if (cell !== null && cell.to === c) return take(c, cell, s, last, next);\n link(c, s, last, next);\n claim(s, c.last as Edge);\n}\n\n/**\n * The pair's edge among the source's first SCAN subscribers: null if the list\n * ends first (absent), undefined if the budget runs out (unknown).\n */\nfunction pair(s: Node, c: Node): Edge | null | undefined {\n if (__STATS__) stats.lookups++;\n\n let budget = SCAN;\n\n for (let e = s.subs; e !== null; e = e.nextSub) {\n if (e.to === c) return e;\n\n if (--budget === 0) return undefined;\n }\n return null;\n}\n\n/**\n * The pass's lookup from here on, decided by the found edge's place: the\n * source's first subscriber marks the unread suffix, from `next` on (a walk\n * over edges, not sources); deeper, index.\n */\nfunction begin(c: Node, s: Node, e: Edge, next: Edge | null): void {\n if (e !== s.subs) return index(c, next);\n\n if (__STATS__) stats.sweeps++;\n\n c.flags |= Flag.Marked;\n\n for (let u = next; u !== null; u = u.next) {\n if (__STATS__) stats.indexed++;\n\n u.ver = UNREAD;\n }\n}\n\n/**\n * A found edge: an unread one is observed and moves to the cursor; a repeated\n * read keeps its place and its first observation's version (P5).\n */\nfunction take(\n c: Node,\n e: Edge,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n): void {\n if (e.ver !== UNREAD) {\n if (__STATS__) stats.dups++;\n\n return;\n }\n if (__STATS__) stats.moves++;\n\n e.ver = s.ver;\n move(c, e, last, next!);\n}\n", "// Policy around the kernel: the watcher lifecycle (check, consume the\n// cleanup, run), a FIFO queue for scheduled watchers, and batching.\nimport { Flag } from \"./graph\";\nimport type { Cleanup, Fn, Node } from \"./graph\";\nimport { check, dispose, exec, node, onWake, untracked } from \"./kernel\";\n\nconst queue: (Node | null)[] = [];\n// The host's registers. Exported so a write's caller can test for work\n// without a call into the host; ES bindings are read-only to importers, so\n// only this module writes them.\n/** Queued watchers. */\nexport let size = 0;\n/** Open batches. */\nexport let depth = 0;\n/** A drain loop is open. */\nexport let draining = false;\n\n/** Queue a scheduled watcher once; the kernel calls this when it wakes one. */\nexport function wake(w: Node): void {\n if ((w.flags & (Flag.Auto | Flag.Queued)) !== Flag.Auto) return;\n\n w.flags |= Flag.Queued;\n queue[size++] = w;\n}\n\nonWake(wake);\n\n/** A watcher runs `fn` and keeps a returned function as its cleanup. */\nexport function watcher(fn: Fn, auto: boolean): Node {\n return node(\n fn,\n undefined,\n Flag.Watch | Flag.Stale | Flag.Dirty | (auto ? Flag.Auto : 0),\n );\n}\n\n/**\n * Check every committed source unless only signals woke it, then, if a run\n * is owed, consume the previous cleanup and run. A watcher neither STALE,\n * WOKEN is clean, or cold after a failure until a source changes. A failed\n * check leaves it STALE, so the next run checks again (V1) and the next push\n * finds it queued or delivers it again.\n * Precondition: its own run is not on the stack (flush is not reentrant).\n */\nexport function run(w: Node): void {\n const flags = w.flags;\n\n if (w.fn === null || (flags & (Flag.Stale | Flag.Woken)) === 0) return;\n\n w.flags = flags & ~(Flag.Stale | Flag.Woken);\n\n if ((flags & Flag.Stale) !== 0) {\n try {\n check(w);\n } catch (error) {\n w.flags |= Flag.Stale;\n throw error;\n }\n }\n\n if ((w.flags & Flag.Dirty) === 0 || w.fn === null) return;\n\n const cleanup = w.value;\n\n if (typeof cleanup === \"function\") {\n w.value = undefined;\n untracked(cleanup as Cleanup);\n\n if (w.fn === null) return;\n }\n exec(w);\n}\n\n/** Terminal: detach, then run the last cleanup outside tracking. */\nexport function stop(w: Node): void {\n if (w.fn === null) return;\n\n const cleanup = w.value;\n w.value = undefined;\n dispose(w);\n\n if (typeof cleanup === \"function\") untracked(cleanup as Cleanup);\n}\n\n/** Run queued watchers until the queue drains; rethrow the first error. */\nexport function flush(): void {\n if (size === 0 || draining || depth !== 0) return;\n\n drainNow();\n}\n\n/**\n * `flush` with its guard at the call site: a write's caller tests\n * `size !== 0 && !draining && depth === 0` first (the queue first, so a write\n * that woke nothing costs one load), and calls this only when there is work.\n */\nexport function drainNow(): void {\n draining = true;\n drain(false, undefined);\n}\n\n/**\n * A new scheduled watcher's first run. With no drain open, no batch and an\n * empty queue this is `wake(w); flush()` with the queue slot skipped: the\n * drain opens on `w` (so its run stays inside the drain loop, LOG 11), and a\n * fresh watcher has no sources to check and no cleanup, so `run` is `exec`.\n */\nexport function start(w: Node): void {\n if (draining || depth !== 0 || size !== 0) {\n wake(w);\n return flush();\n }\n draining = true;\n\n try {\n exec(w);\n } catch (error) {\n return drain(true, error);\n }\n drain(false, undefined);\n}\n\n/** The drain loop, opened by the caller: FIFO, the first error rethrown at the end. */\nfunction drain(failed: boolean, first: unknown): void {\n for (let i = 0; i < size; i++) {\n const queuedWatcher = queue[i]!;\n queue[i] = null;\n queuedWatcher.flags &= ~Flag.Queued;\n\n try {\n run(queuedWatcher);\n } catch (error) {\n if (!failed) first = error;\n\n failed = true;\n }\n }\n size = 0;\n draining = false;\n\n if (failed) throw first;\n}\n\nexport function batch<T>(fn: () => T): T {\n depth++;\n\n try {\n return fn();\n } finally {\n if (--depth === 0) flush();\n }\n}\n", "// Public API: signal, computed, effect, get, peek, set, update, dispose,\n// batch, untracked. A handle is the node itself: nothing is allocated besides\n// the node, and handle <-> node conversions are type assertions only (no\n// runtime wrapper). Every operation here exposes existing kernel and host\n// semantics; none adds state.\nimport { Flag } from \"./graph\";\nimport { depth, drainNow, draining, size, start, stop, watcher } from \"./host\";\nimport {\n dispose as detach,\n node,\n peek as refresh,\n read,\n untracked,\n write,\n} from \"./kernel\";\nimport type { Fn, Node } from \"./graph\";\n\nexport { batch } from \"./host\";\nexport { untracked } from \"./kernel\";\n\n// Public handles: compile-time brands over the node, which is the runtime\n// handle. Variance is explicit: reading is covariant, a signal is also\n// written, so it is invariant.\ndeclare const READ: unique symbol;\ndeclare const WRITE: unique symbol;\ndeclare const COMPUTED: unique symbol;\ndeclare const EFFECT: unique symbol;\n\n/** Anything `get` accepts. */\nexport interface Readable<out T> {\n readonly [READ]: T;\n}\n\nexport interface Signal<in out T> extends Readable<T> {\n readonly [WRITE]: (value: T) => void;\n}\n\nexport interface Computed<out T> extends Readable<T> {\n readonly [COMPUTED]: true;\n}\n\nexport interface Effect {\n readonly [EFFECT]: true;\n}\n\nexport function signal<T>(value: T): Signal<T> {\n return node(null, value, 0) as unknown as Signal<T>;\n}\n\n/**\n * `fn` receives `prev`, the last successfully committed value: `initial`\n * (or undefined) before the first commit, unchanged by a failed run.\n * Returning `prev` itself is a cutoff: consumers do not rerun, so custom\n * equality is `(prev) => (equal(prev, next) ? prev : next)`.\n */\nexport function computed<T>(fn: (prev: T | undefined) => T): Computed<T>;\nexport function computed<T>(fn: (prev: T) => T, initial: T): Computed<T>;\nexport function computed<T>(\n fn: (prev: T | undefined) => T,\n initial?: T,\n): Computed<T> {\n return node(fn as Fn, initial, Flag.Dirty) as unknown as Computed<T>;\n}\n\n/** Runs now (or when the enclosing batch or drain ends), then on every change it read. */\nexport function effect(fn: () => void | (() => void)): Effect {\n const effectNode = watcher(fn, true);\n\n try {\n start(effectNode);\n } catch (error) {\n stop(effectNode);\n throw error;\n }\n\n return effectNode as unknown as Effect;\n}\n\n/**\n * Kernel `read` itself under the public type: a signal's flags are 0, so one\n * read path serves signals and computeds, and no surface function stands in\n * front of it.\n */\nexport const get: <T>(source: Readable<T>) => T = read as never;\n\n/** `get` without observation: up to date, but the running consumer does not depend on it. */\nexport const peek: <T>(source: Readable<T>) => T = refresh as never;\n\n/** Writes, then runs what the write scheduled; a write that woke nothing stops at one load. */\nexport function set<T>(source: Signal<T>, value: T): void {\n write(source as unknown as Node, value);\n\n if (size !== 0 && !draining && depth === 0) drainNow();\n}\n\n/**\n * `set(source, fn(current))`. An update is a write, not an observation:\n * `fn` runs untracked, so neither `source` nor what `fn` reads becomes a\n * dependency of the running consumer. If `fn` throws, nothing is written.\n */\nexport function update<T>(source: Signal<T>, fn: (value: T) => T): void {\n set(\n source,\n untracked(() => fn((source as unknown as Node).value as T)),\n );\n}\n\nexport function dispose(target: Computed<unknown> | Effect): void {\n const targetNode = target as unknown as Node;\n\n if ((targetNode.flags & Flag.Watch) !== 0) stop(targetNode);\n else detach(targetNode);\n}\n"],
5
- "mappings": ";AAkFO,IAAMA,EAAS,GAETC,EAAO,WAOPC,EAAS,UAETC,EAAO,EAMPC,EAAO,IACPC,EAAO,IAIb,SAASC,EAAKC,EAAgBC,EAAgBC,EAAoB,CACvE,MAAO,CACL,MAAAA,EACA,MAAAD,EACA,IAAK,EACL,GAAAD,EACA,KAAM,KACN,KAAM,KACN,KAAM,KACN,QAAS,KACT,KAAM,KACN,IAAK,CACP,CACF,CAGO,SAASG,EAAKC,EAASC,EAASC,EAAmBC,EAAkB,CAC1E,IAAMC,EAASH,EAAE,KACXI,EAAQJ,EAAE,KAChBG,EAAO,KAAOC,EAEVA,IAAU,OAAMA,EAAM,KAAOD,GAEjCH,EAAE,KAAOC,EACTD,EAAE,KAAOE,EAELD,IAAS,KAAMA,E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ACFK,EAAMF,CAAU,CAClB,OAASG,EAAO,CACd,MAAAC,EAAKJ,CAAU,EACTG,CACR,CAEA,OAAOH,CACT,CAOO,IAAMK,GAAqCC,EAGrCC,GAAsCA,EAG5C,SAASC,GAAOC,EAAmBf,EAAgB,CACxDgB,EAAMD,EAA2Bf,CAAK,EAElCiB,IAAS,GAAK,CAACC,GAAYC,IAAU,GAAGC,EAAS,CACvD,CAOO,SAASC,GAAUN,EAAmBZ,EAA2B,CACtEW,GACEC,EACAO,EAAU,IAAMnB,EAAIY,EAA2B,KAAU,CAAC,CAC5D,CACF,CAEO,SAASQ,GAAQC,EAA0C,CAChE,IAAMC,EAAaD,GAEdC,EAAW,MAAQ,MAAgB,EAAGf,EAAKe,CAAU,EACrDF,EAAOE,CAAU,CACxB",
6
- "names": ["UNREAD", "MASK", "SETTLE", "SCAN", "KEEP", "TRIM", "node", "fn", "value", "flags", "move", "c", "e", "last", "next", "before", "after", "cut", "unsub", "settle", "gen", "s", "active", "stack", "top", "wake", "onWake", "fn", "trim", "stack", "KEEP", "write", "s", "value", "MASK", "e", "n", "f", "wake", "mark", "first", "base", "top", "read", "peek", "c", "active", "last", "next", "miss", "pull", "root", "exec", "verify", "settled", "sf", "TRIM", "up", "error", "p", "check", "w", "tentative", "untracked", "fn", "prev", "fail", "unindex", "detach", "cut", "SETTLE", "settle", "after", "before", "unsub", "dispose", "index", "unread", "UNREAD", "claim", "cell", "link", "tail", "slot", "found", "budget", "SCAN", "move", "pair", "begin", "take", "u", "queue", "size", "depth", "draining", "wake", "w", "onWake", "watcher", "fn", "auto", "node", "run", "flags", "check", "error", "cleanup", "untracked", "exec", "stop", "dispose", "flush", "drainNow", "drain", "start", "failed", "first", "i", "queuedWatcher", "batch", "signal", "value", "node", "computed", "fn", "initial", "effect", "effectNode", "watcher", "start", "error", "stop", "get", "read", "peek", "set", "source", "write", "size", "draining", "depth", "drainNow", "update", "untracked", "dispose", "target", "targetNode"]
4
+ "sourcesContent": ["import { stats } from \"./instrumentation\";\n\n// Graph types, constants and intrusive list operations.\n\n// The aliases name different facts but do not brand numbers: counters wrap at\n// MASK and edge versions can carry UNREAD.\nexport type Flags = number;\nexport type Version = number;\nexport type Generation = number;\n\n/** A computed's or watcher's body; a signal has none. */\nexport type NodeFn = (prev: unknown) => unknown;\n/** A watcher's cleanup, run untracked. */\nexport type Cleanup = () => unknown;\n\nexport interface Node {\n flags: Flags;\n value: unknown;\n /** Bumps on every Object.is-visible change of value. */\n ver: Version;\n /** null for a signal and for a disposed node. */\n fn: NodeFn | null;\n /** First and last dependency edges, in read order. */\n firstDep: Edge | null;\n lastDep: Edge | null;\n /**\n * First subscriber edge, in birth order. Its prevSub is the LAST subscriber,\n * not null: the list is circular backwards only. Walk it forwards (nextSub\n * ends at null); a backward walk must stop at firstSub, or it loops.\n */\n firstSub: Edge | null;\n /** While a reader indexes: this node's edge into that reader. */\n slot: Edge | null;\n /** Successful runs; edges born since the last one are tentative. */\n gen: Generation;\n}\n\nexport interface Edge {\n readonly from: Node;\n readonly to: Node;\n /** from.ver when `to` read it; UNREAD in the pass's marked unread suffix. */\n ver: Version | typeof UNREAD | typeof SKIPPED;\n /** to.gen + 1 at birth: tentative while it still equals to.gen + 1. */\n gen: Generation;\n /** Neighbours in the consumer's dependency list. */\n prevDep: Edge | null;\n nextDep: Edge | null;\n /**\n * Neighbours in the source's subscriber list. prevSub is the predecessor,\n * except on the source's firstSub, where it is the last subscriber (the\n * tail: link appends there). Null only on a detached edge.\n */\n prevSub: Edge | null;\n nextSub: Edge | null;\n}\n\n/** Shared LIFO of the kernel's walks: resume edges and displaced slot cells. */\nexport type WorkStack = (Edge | null)[];\n\n// Flag layout and constants used by the kernel and host.\nexport const enum Flag {\n /** A source below may have changed; a watcher must validate. */\n Stale = 1 << 0,\n /** Must run: first run, failed run, or a direct source changed. */\n Dirty = 1 << 1,\n /** Its run is on the stack. */\n Busy = 1 << 2,\n /** A watcher: handed to the host, never read. */\n Watch = 1 << 4,\n /** Woken by signals only; computed sources need no validation. */\n Woken = 1 << 5,\n /**\n * Development builds only (C1 is a precondition): a computed whose\n * validation is on the stack, no longer STALE and not yet clean. WOKEN's\n * bit, so every mask stays a byte: WOKEN is a watcher's, CHECKING a\n * computed's, and no node is both. A production build never sets it, so\n * a mask that tests it is inert there.\n */\n Checking = 1 << 5,\n /** Host policy: scheduled by the reference host. */\n Auto = 1 << 6,\n /** Host policy: already in its queue. */\n Queued = 1 << 7,\n // Combined masks used when testing or clearing flags; all remain within a byte.\n Pending = Stale | Dirty,\n Active = Busy | Checking,\n Pull = Pending | Active,\n // Checking and Woken share a bit on computed nodes and watchers, respectively.\n PendingMarked = Pending | Checking,\n Wake = Stale | Woken,\n AutoQueued = Auto | Queued,\n}\n\n/** Counters wrap inside the SMI range. */\nexport const enum CounterLimit {\n Mask = 0x3fffffff,\n}\n\n/** edge.ver of an edge the marked or indexed run has not read yet. */\nexport const UNREAD = -1;\n/**\n * edge.ver of an unread edge a read has skipped once in this pass (`skip` in\n * the kernel). Like UNREAD it only stands where the old version is never\n * read: a read overwrites it, a successful run cuts what is left unread, and\n * a failed one leaves its node DIRTY.\n */\nexport const SKIPPED = -2;\n/**\n * A committed edge keeps its birth generation, and generations wrap: an edge\n * 2^30 - 1 commits old would read as born in the next run (tentative). So a\n * node restamps its edges with its own generation whenever a commit makes\n * `gen & SETTLE` zero, twice a cycle, and no edge falls that far behind.\n */\nexport const SETTLE = 0x1fffffff;\n/** Scan budget of every bounded search: a constant keeps a run linear. */\nexport const SCAN = 8;\n/**\n * Budget of the scan from the end of a reader's list (LOG 47). Skipped edges\n * go to the end in skip order, so the latest is last: a swap, a reversal and\n * a source moved to the front find theirs there. Each absent source pays the\n * whole budget, so it is small.\n */\nexport const TAIL = 2;\n/**\n * Work-stack (and host-queue) slots kept at rest, and the length past which the outermost\n * walk's end cuts the stack back to them. The gap keeps walks only a little\n * deeper than KEEP from cutting and regrowing on every pass.\n */\nexport const KEEP = 256;\nexport const TRIM = 512;\n\n// Intrusive graph operations independent of the execution context.\n\nexport function createNode(fn: Node[\"fn\"], value: unknown, flags: Flags): Node {\n return {\n flags,\n value,\n ver: 0,\n fn,\n firstDep: null,\n lastDep: null,\n firstSub: null,\n slot: null,\n gen: 0,\n };\n}\n\n/** Move an unread edge (strictly after `next`) up to the cursor. */\nexport function moveDep(c: Node, e: Edge, last: Edge | null, next: Edge): void {\n const before = e.prevDep!;\n const after = e.nextDep;\n before.nextDep = after;\n\n if (after !== null) after.prevDep = before;\n else c.lastDep = before;\n\n e.prevDep = last;\n e.nextDep = next;\n\n if (last !== null) last.nextDep = e;\n else c.firstDep = e;\n next.prevDep = e;\n}\n\n/**\n * A read found `e` past `next`, the edge under the cursor: `next` goes to the\n * end of the list (read later or never, see `miss`), and `e`, unless it was\n * right behind `next`, moves to the cursor, after `last`.\n */\nexport function skipDep(c: Node, last: Edge | null, next: Edge, e: Edge): void {\n const after = next.nextDep!;\n const tail = c.lastDep!;\n\n if (last !== null) last.nextDep = after;\n else c.firstDep = after;\n after.prevDep = last;\n\n next.prevDep = tail;\n next.nextDep = null;\n tail.nextDep = next;\n c.lastDep = next;\n // A failed marked pass can leave a marked suffix behind: stay inside it.\n if (tail.ver === UNREAD) next.ver = UNREAD;\n\n if (e !== after) moveDep(c, e, last, after);\n}\n\n/** Remove every edge of `c` after `last` (all of them when null). */\nexport function cutDeps(c: Node, last: Edge | null): void {\n let e = last === null ? c.firstDep : last.nextDep;\n\n if (e === null) return;\n\n if (last === null) c.firstDep = null;\n else last.nextDep = null;\n c.lastDep = last;\n // The cut head's back pointer would tie this garbage to the live list, and\n // so to garbage cut later: old garbage keeps newer garbage alive.\n e.prevDep = null;\n\n for (; e !== null; e = e.nextDep) unlinkSub(e);\n}\n\n/** Restamp every edge of `c`, all of them committed, with its generation (SETTLE). */\nexport function settleDeps(c: Node): void {\n const gen = c.gen;\n\n for (let e = c.firstDep; e !== null; e = e.nextDep) e.gen = gen;\n}\n\n/** Take an edge out of its source's subscriber list. */\nexport function unlinkSub(e: Edge): void {\n if (__STATS__) stats.unlinks++;\n\n const s = e.from;\n const before = e.prevSub!;\n const after = e.nextSub;\n\n if (e === s.firstSub) s.firstSub = after;\n else before.nextSub = after;\n\n if (after !== null) after.prevSub = before;\n else if (s.firstSub !== null) s.firstSub.prevSub = before;\n // Subscribers are in birth order, so an old removed edge would point at a\n // much younger one and keep it (and its watcher) alive across scavenges.\n e.prevSub = null;\n e.nextSub = null;\n}\n", "// Reactive kernel: tracking, propagation, validation and execution.\n// Detached edges must not retain pointers into live lists.\n// See research/LOG.md for representation rationale.\n\nimport {\n Flag,\n KEEP,\n CounterLimit,\n SCAN,\n SETTLE,\n SKIPPED,\n TAIL,\n TRIM,\n UNREAD,\n cutDeps,\n moveDep,\n settleDeps,\n skipDep,\n unlinkSub,\n} from \"./graph\";\nimport type { Edge, Flags, Node, WorkStack } from \"./graph\";\nimport { stats } from \"./instrumentation\";\n\nexport { createNode } from \"./graph\";\nexport { stats } from \"./instrumentation\";\n\nconst compare = Object.is;\n\n/** The running consumer, or null outside a tracking pass. */\nlet active: Node | null = null;\n/** Last accepted edge of the running pass; saved with `active` on nesting. */\nlet cursor: Edge | null = null;\n/**\n * One LIFO work stack shared by all walks: sibling edges to resume (mark),\n * edges to climb back through (pull), and slot cells an indexed run displaced.\n * Every walk pops back to its own base before returning. Once the stack is\n * empty, an oversized buffer is cut back (`trim`).\n */\nconst stack: WorkStack = new Array(256).fill(null);\n/** First free index of `stack`. */\nlet top = 0;\n/** Longest the work stack has been when `trim` cut it (research). */\nlet peak = 0;\nlet wake: (w: Node) => void = () => {};\n\n/**\n * The host is told about every watcher a write or mark reaches. It owns the\n * deduplication (a queued watcher is not queued again), so a watcher left\n * STALE by a failed check is delivered again by the next push.\n */\nexport function onWake(fn: (w: Node) => void): void {\n wake = fn;\n}\n\n/** No tracked consumer or occupied work-stack slot (tests; untracked suspends cursor). */\nexport function idle(): boolean {\n return active === null && top === 0;\n}\n\n/**\n * Deepest work-stack top reached so far (research). Walks null the slots\n * they pop and only `trim` shrinks the array, so the high-water mark is its\n * length or the longest length `trim` cut.\n */\nexport function stackHighWater(): number {\n return stack.length > peak ? stack.length : peak;\n}\n\n/** Slots the work stack holds now (tests). */\nexport function stackLength(): number {\n return stack.length;\n}\n\n/**\n * When empty, cut a stack that a deep walk grew past TRIM back to KEEP slots,\n * so one deep walk does not hold its depth in memory for good. Setting the\n * length right-trims V8's backing store in place: no allocation, and the\n * array stays packed.\n *\n * Only walks that push check at their exits: mark, verify (also on failure),\n * and unindex. An empty stack has no entries to preserve even if a user\n * callback or a graph cursor is suspended in local variables. `active`\n * is a tracking context, not a call-depth counter (untracked clears it).\n * The length test comes first: a small buffer pays no load of `top`.\n */\nfunction trim(): void {\n if (stack.length > TRIM && top === 0) {\n if (__STATS__ && stack.length > peak) peak = stack.length;\n\n stack.length = KEEP;\n }\n}\n\n// ------------------------------------------------------------------- write\n\nexport function write(s: Node, value: unknown): void {\n if (compare(s.value, value)) return;\n\n s.value = value;\n s.ver = (s.ver + 1) & CounterLimit.Mask;\n\n for (let e = s.firstSub; e !== null; e = e.nextSub) {\n const n = e.to;\n const f = n.flags;\n\n if (__STATS__) stats.marks++;\n\n if ((f & Flag.Busy) !== 0) {\n // Running: it may not have read s yet, so versions decide.\n if ((f & Flag.Stale) === 0) {\n n.flags = f | Flag.Stale;\n\n if ((f & Flag.Watch) !== 0) wake(n);\n else {\n const subs = n.firstSub;\n\n if (subs !== null) mark(subs);\n }\n }\n } else if ((f & Flag.Watch) !== 0) {\n n.flags = f | Flag.Dirty | Flag.Woken;\n\n wake(n);\n } else if ((f & Flag.Stale) !== 0) {\n n.flags = f | Flag.Dirty;\n } else {\n n.flags = f | Flag.Dirty | Flag.Stale;\n\n const subs = n.firstSub;\n\n if (subs !== null) mark(subs);\n }\n }\n}\n\n/** Mark everything below the subscriber list `first` STALE, depth first. */\nfunction mark(first: Edge): void {\n const base = top;\n let e: Edge | null = first;\n\n for (;;) {\n while (e !== null) {\n const n: Node = e.to;\n const f = n.flags;\n\n if (__STATS__) stats.marks++;\n // A watcher has no subscribers; the host deduplicates, so it is always told.\n if ((f & Flag.Watch) !== 0) {\n n.flags = f | Flag.Stale;\n wake(n);\n } else if ((f & Flag.Stale) === 0) {\n n.flags = f | Flag.Stale;\n\n const subs = n.firstSub;\n\n if (subs !== null) {\n const next = e.nextSub;\n\n if (next !== null) stack[top++] = next;\n\n e = subs;\n continue;\n }\n }\n e = e.nextSub;\n }\n\n if (top === base) {\n trim();\n return;\n }\n\n e = stack[--top] as Edge;\n stack[top] = null;\n }\n}\n\n// -------------------------------------------------------------------- read\n\n/** Bring `n` up to date if it is a stale computed, then track it. */\nexport function read(n: Node): unknown {\n const value = peek(n);\n const c = active;\n\n if (c !== null) {\n if (__STATS__) stats.reads++;\n\n const last = cursor;\n const next = last === null ? c.firstDep : last.nextDep;\n\n if (next !== null && next.from === n) {\n if (__STATS__) stats.hits++;\n\n cursor = next;\n next.ver = n.ver;\n } else if (last !== null) {\n // The cursor's own source again: a repeat keeps its first observation\n // (P5); anything else is resolved by `miss`.\n if (last.from !== n) miss(c, n, last, next);\n else if (__STATS__) stats.repeats++;\n } else if (next !== null) miss(c, n, last, next);\n // No relation yet: the first read of a first run links at once.\n else link(c, n, null, null);\n }\n return value;\n}\n\n/** `read` without its tracking half: bring `n` up to date, record no relation. */\nexport function peek(n: Node): unknown {\n if ((n.flags & Flag.Pull) !== 0) pull(n);\n\n return n.value;\n}\n\n/**\n * Pull a computed up to date. Existential, in read order: sources are\n * checked first to last and the first changed one makes the node run. A\n * STALE source is descended into (the stack keeps the edge to climb back\n * through); a DIRTY one runs. A throw leaves every node on the walk DIRTY.\n * A node whose run is on the stack is a cycle. A development build also\n * diagnoses a node whose validation is on the stack (CHECKING): C1 is a\n * precondition, so its committed value never answers such a demand there.\n */\nfunction pull(root: Node): void {\n const f = root.flags;\n\n if ((f & Flag.Active) !== 0) throw new Error(\"Cycle detected\");\n\n if ((f & Flag.Dirty) !== 0) return exec(root);\n\n verify(root, f);\n}\n\n/**\n * The walk of `pull` for a STALE node that is not DIRTY, BUSY or CHECKING;\n * kept apart so `pull` stays small. A node disposed during the walk is not\n * run (W3), nor left DIRTY.\n *\n * Development builds diagnose C1: a node on the walk is CHECKING until it is\n * clean or runs, and a source on the stack (BUSY or CHECKING) is a cycle\n * even when no push marked it again, since its version is not yet a fact.\n * CHECKING is set by the store that clears STALE and cleared by `exec` as it\n * sets BUSY; only a node found clean pays a store of its own. Production\n * builds compile all of it away.\n */\nfunction verify(root: Node, f: Flags): void {\n root.flags = __DEV__ ? (f & ~Flag.Stale) | Flag.Checking : f & ~Flag.Stale;\n const base = top;\n let n = root;\n let e = root.firstDep;\n\n try {\n for (;;) {\n settled: {\n while (e !== null) {\n const s: Node = e.from;\n const sf = s.flags;\n\n if (__STATS__) stats.checks++;\n\n if ((sf & (__DEV__ ? Flag.Pull : Flag.Pending)) !== 0) {\n if ((sf & Flag.Active) !== 0) throw new Error(\"Cycle detected\");\n\n if ((sf & Flag.Dirty) === 0) {\n s.flags = __DEV__\n ? (sf & ~Flag.Stale) | Flag.Checking\n : sf & ~Flag.Stale;\n stack[top++] = e;\n n = s;\n e = s.firstDep;\n continue;\n }\n exec(s);\n }\n\n if (s.ver !== e.ver) {\n if (n.fn !== null) exec(n);\n break settled;\n }\n e = e.nextDep;\n }\n // Every source unchanged: clean, and no longer on the walk.\n if (__DEV__) n.flags &= ~Flag.Checking;\n }\n\n // Climb; a parent whose child changed runs as well.\n for (;;) {\n if (top === base) {\n trim();\n\n return;\n }\n\n const up = stack[--top] as Edge;\n stack[top] = null;\n n = up.to;\n\n if (up.from.ver === up.ver) {\n e = up.nextDep;\n break;\n }\n\n if (n.fn !== null) exec(n);\n }\n }\n } catch (error) {\n if (n.fn !== null)\n n.flags = __DEV__\n ? (n.flags | Flag.Dirty) & ~Flag.Checking\n : n.flags | Flag.Dirty;\n\n while (top > base) {\n const p = (stack[--top] as Edge).to;\n\n if (p.fn !== null)\n p.flags = __DEV__\n ? (p.flags | Flag.Dirty) & ~Flag.Checking\n : p.flags | Flag.Dirty;\n stack[top] = null;\n }\n trim();\n throw error;\n }\n}\n\n/**\n * Universal check of a watcher: pull every committed source, so a throwing\n * one surfaces before any irreversible step. Marks DIRTY on change. Tentative\n * edges (reads of a failed run) only wake; they exist only while a run is\n * owed, and then versions need no comparison.\n */\nexport function check(w: Node): void {\n const tentative = (w.gen + 1) & CounterLimit.Mask;\n let e = w.firstDep;\n\n // Until a run is owed, versions decide; then only the pulls remain. A\n // development build pulls a source on the stack too, so the C1 diagnosis\n // fails here, before the cleanup (P4).\n if ((w.flags & Flag.Dirty) === 0) {\n for (; e !== null; e = e.nextDep) {\n const s = e.from;\n\n if (__STATS__) stats.checks++;\n\n if (\n (s.flags & (__DEV__ ? Flag.Pull : Flag.Pending)) !== 0 &&\n e.gen !== tentative\n )\n pull(s);\n\n if (s.ver !== e.ver) {\n w.flags |= Flag.Dirty;\n e = e.nextDep;\n break;\n }\n }\n }\n\n for (; e !== null; e = e.nextDep) {\n if (__STATS__) stats.checks++;\n\n const s = e.from;\n\n if (\n (s.flags & (__DEV__ ? Flag.Pull : Flag.Pending)) !== 0 &&\n e.gen !== tentative\n )\n pull(s);\n }\n}\n\nexport function untracked<T>(fn: () => T): T {\n const prev = active;\n active = null;\n\n try {\n return fn();\n } finally {\n active = prev;\n }\n}\n\n// --------------------------------------------------------------------- run\n\n/** Run `n.fn` as a tracking pass; commit value and edges on success. */\nexport function exec(n: Node): void {\n const prev = active;\n const prevCursor = cursor;\n const base = top;\n\n if (__STATS__) stats.runs++;\n // Cleared before the run: a push during it marks the node again. In a\n // development build a computed's validation ends here, BUSY taking over\n // from CHECKING; on a watcher the bit is WOKEN, which this run discharges.\n n.flags =\n (n.flags & ~(__DEV__ ? Flag.PendingMarked : Flag.Pending)) | Flag.Busy;\n active = n;\n cursor = null;\n let value: unknown;\n\n try {\n value = n.fn!(n.value);\n } catch (error) {\n const last = cursor as Edge | null;\n active = prev;\n cursor = prevCursor;\n fail(n, base, last);\n throw error;\n }\n const last = cursor as Edge | null;\n active = prev;\n cursor = prevCursor;\n const f = n.flags;\n\n if (last !== null && last.from.slot === last) unindex(n, base);\n\n n.flags = f & ~Flag.Busy;\n\n if (n.fn === null) return detach(n);\n // Commit only after a successful run. Dropping the unread suffix removes\n // sources that this pass no longer depends on.\n if ((last === null ? n.firstDep : last.nextDep) !== null) cutDeps(n, last);\n\n n.gen = (n.gen + 1) & CounterLimit.Mask;\n\n // Every edge is committed now; see SETTLE.\n if ((n.gen & SETTLE) === 0) settleDeps(n);\n\n if (compare(value, n.value) === false) {\n n.value = value;\n n.ver = (n.ver + 1) & CounterLimit.Mask;\n }\n}\n\n/**\n * A failed run: keep committed edges and this run's reads as the wake set,\n * drop unread edges earlier failed runs left behind, owe a run.\n */\nfunction fail(n: Node, base: number, last: Edge | null): void {\n if (last !== null && last.from.slot === last) unindex(n, base);\n\n n.flags &= ~Flag.Busy;\n\n if (n.fn === null) return detach(n);\n\n n.flags |= Flag.Dirty;\n const tentative = (n.gen + 1) & CounterLimit.Mask;\n for (let e = last === null ? n.firstDep : last.nextDep; e !== null;) {\n const after: Edge | null = e.nextDep;\n\n if (e.gen === tentative) {\n const before = e.prevDep;\n\n if (before !== null) before.nextDep = after;\n else n.firstDep = after;\n\n if (after !== null) after.prevDep = before;\n else n.lastDep = before;\n\n unlinkSub(e);\n e.prevDep = null;\n e.nextDep = null;\n }\n e = after;\n }\n}\n\n/** Detach `n` from its sources for good; inside its own run, at its end. */\nexport function dispose(n: Node): void {\n if (n.fn === null) return;\n\n n.fn = null;\n\n if ((n.flags & Flag.Busy) === 0) detach(n);\n}\n\nfunction detach(n: Node): void {\n cutDeps(n, null);\n n.flags &= ~Flag.PendingMarked;\n}\n\n// ---------------------------------------------------------------- tracking\n\n/** Put every edge of `c` into its source's slot; mark the unread ones. */\nexport function index(c: Node, next: Edge | null): void {\n if (__STATS__) stats.indexes++;\n\n let unread = false;\n\n for (let e = c.firstDep; e !== null; e = e.nextDep) {\n if (__STATS__) stats.indexed++;\n\n if (e === next) unread = true;\n\n if (unread) e.ver = UNREAD;\n\n claim(e.from, e);\n }\n}\n\n/**\n * Point the source's slot at `e`, keeping a displaced cell to give back.\n * A cell's immutable `from` is its source, so the cell alone is enough.\n */\nexport function claim(s: Node, e: Edge): void {\n const cell = s.slot;\n\n if (cell !== null) stack[top++] = cell;\n s.slot = e;\n}\n\n/** Clear the run's slots, give back the cells it displaced. */\nfunction unindex(n: Node, base: number): void {\n for (let e = n.firstDep; e !== null; e = e.nextDep) e.from.slot = null;\n\n while (top > base) {\n const cell = stack[--top] as Edge;\n stack[top] = null;\n cell.from.slot = cell;\n }\n trim();\n}\n\n/** A new edge at the cursor, appended to the source's subscribers. */\nexport function link(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n): void {\n if (__STATS__) stats.links++;\n\n const first = s.firstSub;\n const tail = first !== null ? first.prevSub : null;\n const e: Edge = {\n from: s,\n to: c,\n ver: s.ver,\n gen: (c.gen + 1) & CounterLimit.Mask,\n prevDep: last,\n nextDep: next,\n prevSub: tail,\n nextSub: null,\n };\n\n if (last !== null) last.nextDep = e;\n else c.firstDep = e;\n\n if (next !== null) next.prevDep = e;\n else c.lastDep = e;\n\n if (first !== null) {\n tail!.nextSub = e;\n first.prevSub = e;\n } else {\n s.firstSub = e;\n e.prevSub = e;\n }\n cursor = e;\n}\n\n// Exact dependency tracking: resolve a read outside the stable cursor path.\n// Proofs come cheapest first: in `read`, the edge after the cursor, the\n// cursor's own (a repeat) and an empty list (the first relation); then a\n// source nobody reads or whose at most two subscribers are other readers,\n// bounded scans of this reader's list, and the source's first subscribers.\n// Only a source with more subscribers than the budget needs the slot index. Slot walks and edge creation remain in the kernel because\n// they mutate its shared stack.\n\n/**\n * A read that is neither the next edge in read order, nor the cursor's, nor\n * the first relation of an empty list. Every answer is exact. A repeated read\n * keeps the version of the pass's first observation (P5): a change between\n * the two reads stays visible to the next validation.\n */\nfunction miss(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n // An indexed pass owns its cursor's source slot. Nested passes restore it.\n if (last !== null && last.from.slot === last) return slot(c, s, last, next);\n const first = s.firstSub;\n\n // Absent, whatever the unread suffix mode: a source nobody reads, or one\n // whose first and last subscribers, all it has, are other readers.\n if (first === null || alien(first, c)) return link(c, s, last, next);\n\n // Marking, moves and links preserve a continuous UNREAD suffix.\n if (next !== null && next.ver === UNREAD)\n return settle(c, s, last, next, pair(first, c));\n\n if (next !== null) {\n let e = next.nextDep;\n\n // One past `next`: the commonest skip (a swap, a rotation, a deletion).\n if (e !== null && e.from === s) {\n if (__STATS__) stats.scans++;\n\n return skip(c, s, last, next, e);\n }\n // The end of the list holds the edges reads skipped twice (`skip`), the\n // latest last: read after all, or a source moved to the front. A match\n // is the pair's only edge.\n let budget = TAIL;\n e = c.lastDep!;\n\n while (e !== next && e.from !== s && --budget !== 0) e = e.prevDep!;\n\n if (e.from === s) {\n if (__STATS__) stats.tails++;\n\n e.ver = s.ver;\n cursor = e;\n return moveDep(c, e, last, next);\n }\n }\n near(c, s, last, next, first);\n}\n\n/**\n * A miss that neither the source, a marked pass nor the end of the list\n * settles.\n */\nfunction near(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n first: Edge,\n): void {\n // Bounded scans of this reader's list: the unread suffix after `next` (a\n // match is the pair's only edge), the accepted prefix (a match is a\n // repeat). Absence needs one side scanned completely: this reader's list,\n // or the source's subscribers.\n let e: Edge | null = null;\n\n if (next !== null) {\n let budget = SCAN;\n e = next.nextDep;\n\n while (e !== null && e.from !== s && --budget !== 0) e = e.nextDep;\n\n if (e !== null && e.from === s) {\n if (__STATS__) stats.scans++;\n\n return skip(c, s, last, next, e);\n }\n }\n let p = last !== null ? last.prevDep : null;\n let budget = SCAN;\n\n while (p !== null && p.from !== s && --budget !== 0) p = p.prevDep;\n\n if (p !== null && p.from === s) {\n if (__STATS__) stats.dups++;\n\n return;\n }\n\n if (e === null && p === null) return link(c, s, last, next);\n\n lookup(c, s, last, next, first);\n}\n\n/**\n * A read found its edge `e` past `next`, which it skips. The first time,\n * `next` is most likely read next (a swap, a source moved earlier): `e` moves\n * to the cursor and `next` is marked. Skipped again, it is read later or\n * never (a rotation, a deletion, a later move); left in place it would stand\n * before every following read, so it goes to the end of the list, where the\n * tail scan in `miss` finds it if it is read after all.\n */\nfunction skip(c: Node, s: Node, last: Edge | null, next: Edge, e: Edge): void {\n e.ver = s.ver;\n cursor = e;\n\n if (next.ver === SKIPPED) return skipDep(c, last, next, e);\n\n next.ver = SKIPPED;\n moveDep(c, e, last, next);\n}\n\n/**\n * The source's first subscribers decide what the reader's list could not.\n * Found as the first one: a lookup through the subscribers costs no load\n * beyond the read itself, so mark the unread suffix and let the rest of the\n * pass find its pairs that way, with no slot to fill or clear. Found deeper:\n * every lookup would walk other readers' edges, so index; either way the\n * found edge is taken at once.\n */\nfunction lookup(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n first: Edge,\n): void {\n const found = pair(first, c);\n\n if (found !== null && found !== undefined) begin(c, found, first, next);\n\n settle(c, s, last, next, found);\n}\n\n/** A lookup's answer: absent links, found is taken, unknown indexes the pass. */\nfunction settle(\n c: Node,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n found: Edge | null | undefined,\n): void {\n if (found === null) return link(c, s, last, next);\n\n if (found !== undefined) return take(c, found, s, last, next);\n // Past the budget: index the pass, and the slot decides from here on.\n index(c, next);\n slot(c, s, last, next);\n}\n\n/** An indexed pass's lookup: the source's slot holds the pair's edge, or the pair is absent. */\nfunction slot(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n if (__STATS__) stats.lookups++;\n\n const cell = s.slot;\n\n if (cell !== null && cell.to === c) return take(c, cell, s, last, next);\n link(c, s, last, next);\n claim(s, cursor as Edge);\n}\n\n/**\n * Whether the source's subscriber list, at most two edges long, holds no edge\n * to `c`: its first and last subscribers are one load apart (the first one's\n * prevSub), so this proves absence before the reader's list is scanned.\n */\nfunction alien(first: Edge, c: Node): boolean {\n const tail = first.prevSub!;\n\n return (\n first.to !== c &&\n tail.to !== c &&\n (tail === first || first.nextSub === tail)\n );\n}\n\n/**\n * The pair's edge among the source's first SCAN subscribers: null if the list\n * ends first (absent), undefined if the budget runs out (unknown).\n */\nfunction pair(first: Edge | null, c: Node): Edge | null | undefined {\n if (__STATS__) stats.lookups++;\n\n let budget = SCAN;\n\n for (let e = first; e !== null; e = e.nextSub) {\n if (e.to === c) return e;\n\n if (--budget === 0) return undefined;\n }\n return null;\n}\n\n/**\n * The pass's lookup from here on, decided by the found edge's place: the\n * source's first subscriber marks the unread suffix, from `next` on (a walk\n * over edges, not sources); deeper, index.\n */\nfunction begin(c: Node, e: Edge, first: Edge | null, next: Edge | null): void {\n if (next === null) return;\n\n if (e !== first) return index(c, next);\n\n if (__STATS__) stats.sweeps++;\n\n for (let u: Edge | null = next; u !== null; u = u.nextDep) {\n if (__STATS__) stats.indexed++;\n\n u.ver = UNREAD;\n }\n}\n\n/**\n * A found edge: an unread one is observed and moves to the cursor; a repeated\n * read keeps its place and its first observation's version (P5).\n */\nfunction take(\n c: Node,\n e: Edge,\n s: Node,\n last: Edge | null,\n next: Edge | null,\n): void {\n if (e.ver !== UNREAD) {\n if (__STATS__) stats.dups++;\n\n return;\n }\n if (__STATS__) stats.moves++;\n\n e.ver = s.ver;\n moveDep(c, e, last, next!);\n cursor = e;\n}\n", "// Policy around the kernel: the watcher lifecycle (check, consume the\n// cleanup, run), a FIFO queue for scheduled watchers, and batching.\nimport { Flag, KEEP, TRIM } from \"./graph\";\nimport type { Cleanup, Flags, Node, NodeFn } from \"./graph\";\nimport { check, createNode, dispose, exec, onWake, untracked } from \"./kernel\";\n\n/**\n * The queue: a ring of `mask + 1` slots, a power of two, holding the `size`\n * queued watchers from `head` on. It doubles only when full, so it holds\n * fewer than 2W + KEEP slots for W watchers queued at once (S8), and a\n * delivery takes no slot of its own: a slot is free again once taken.\n */\nlet queue: (Node | null)[] = new Array<Node | null>(KEEP).fill(null);\nlet mask = KEEP - 1;\nlet head = 0;\n/**\n * Deliveries of the small drains since the last drain that needed the ring,\n * and the largest of them: the ring is given back once they add up to its\n * size (see `drain`).\n */\nlet spare = 0;\nlet calm = 0;\n// The host's registers. Exported so a write's caller can test for work\n// without a call into the host; ES bindings are read-only to importers, so\n// only this module writes them.\n/** Queued watchers. */\nexport let size = 0;\n/** Open batches, plus one while a drain loop is open: work waits while > 0. */\nexport let hold = 0;\n\n/** Queue a scheduled watcher once; the kernel calls this when it wakes one. */\nexport function wake(w: Node): void {\n const flags = w.flags;\n\n if ((flags & Flag.AutoQueued) !== Flag.Auto) return;\n\n w.flags = flags | Flag.Queued;\n\n if (size > mask) grow();\n\n queue[(head + size++) & mask] = w;\n}\n\nonWake(wake);\n\n/** A full ring doubles, its watchers moved to the front in queue order. */\nfunction grow(): void {\n const next = new Array<Node | null>(size + size).fill(null);\n\n for (let i = 0; i < size; i++) next[i] = queue[(head + i) & mask] as Node;\n\n queue = next;\n mask = size + size - 1;\n head = 0;\n}\n\n/** A watcher runs `fn` and keeps a returned function as its cleanup. */\nexport function watcher(fn: NodeFn, auto: boolean): Node {\n return createNode(\n fn,\n undefined,\n Flag.Watch | Flag.Stale | Flag.Dirty | (auto ? Flag.Auto : 0),\n );\n}\n\n/**\n * Check every committed source unless only signals woke it, then, if a run\n * is owed, consume the previous cleanup and run. A watcher neither STALE,\n * WOKEN is clean, or cold after a failure until a source changes. A failed\n * check leaves it STALE, so the next run checks again (V1) and the next push\n * finds it queued or delivers it again.\n * Precondition: its own run is not on the stack (flush is not reentrant).\n */\nexport function run(w: Node): void {\n deliver(w, w.flags);\n}\n\n/**\n * `run` with the watcher's flags already loaded: the drain clears QUEUED in\n * the same store that clears WAKE. WOKEN without STALE means only signals\n * woke it, and they made it DIRTY: no check, no reload.\n */\nfunction deliver(w: Node, flags: Flags): void {\n if (w.fn === null || (flags & Flag.Wake) === 0) {\n w.flags = flags;\n return;\n }\n w.flags = flags & ~Flag.Wake;\n\n if ((flags & Flag.Stale) !== 0) {\n try {\n check(w);\n } catch (error) {\n w.flags |= Flag.Stale;\n throw error;\n }\n\n if ((w.flags & Flag.Dirty) === 0 || w.fn === null) return;\n }\n const cleanup = w.value;\n\n if (typeof cleanup === \"function\") {\n w.value = undefined;\n untracked(cleanup as Cleanup);\n\n if (w.fn === null) return;\n }\n exec(w);\n}\n\n/** Terminal: detach, then run the last cleanup outside tracking. */\nexport function stop(w: Node): void {\n if (w.fn === null) return;\n\n const cleanup = w.value;\n w.value = undefined;\n dispose(w);\n\n if (typeof cleanup === \"function\") untracked(cleanup as Cleanup);\n}\n\n/** Run queued watchers until the queue drains; rethrow the first error. */\nexport function flush(): void {\n if (size === 0 || hold !== 0) return;\n\n drainNow();\n}\n\n/**\n * `flush` with its guard at the call site: a write's caller tests\n * `size !== 0 && hold === 0` first (the queue first, so a write that woke\n * nothing costs one load), and calls this only when there is work.\n */\nexport function drainNow(): void {\n hold = 1;\n drain(false, undefined);\n}\n\n/**\n * A new scheduled watcher's first run. With no drain open, no batch and an\n * empty queue this is `wake(w); flush()` with the queue slot skipped: the\n * drain opens on `w` (so its run stays inside the drain loop, LOG 11), and a\n * fresh watcher has no sources to check and no cleanup, so `run` is `exec`.\n */\nexport function start(w: Node): void {\n if (hold !== 0 || size !== 0) {\n wake(w);\n return flush();\n }\n hold = 1;\n\n try {\n exec(w);\n } catch (error) {\n return drain(true, error);\n }\n drain(false, undefined);\n}\n\n/**\n * The drain loop, opened by the caller (`hold` is 1): FIFO, the first error\n * rethrown at the end.\n *\n * A drain whose deliveries (which bound its watchers queued at once) fill\n * less than a quarter of the ring is small. The ring is cut back at rest,\n * to KEEP or to the power of two above twice the largest small drain, once\n * the small drains since the last large one have delivered as many watchers\n * as the ring holds. Growing back costs O(ring), so a give-back followed by\n * a burst is O(1) per delivery; a burst after every few small drains keeps\n * its ring, and a burst followed by small drains is still given back.\n */\nfunction drain(failed: boolean, first: unknown): void {\n let taken = 0;\n\n for (; size !== 0; taken++) {\n const queuedWatcher = queue[head]!;\n queue[head] = null;\n head = (head + 1) & mask;\n size--;\n\n try {\n deliver(queuedWatcher, queuedWatcher.flags & ~Flag.Queued);\n } catch (error) {\n if (!failed) first = error;\n\n failed = true;\n }\n }\n head = 0;\n\n if (mask >= TRIM) {\n if (taken + taken < mask >> 1) {\n if (taken > calm) calm = taken;\n\n if ((spare += taken) > mask) shrink(calm);\n } else spare = calm = 0;\n }\n hold = 0;\n\n if (failed) throw first;\n}\n\n/** Cut an empty ring to KEEP slots, or to the power of two above 2 * taken. */\nfunction shrink(taken: number): void {\n let length = KEEP;\n\n while (length < taken + taken) length += length;\n\n queue.length = length;\n mask = length - 1;\n spare = calm = 0;\n}\n\n/**\n * The outermost batch end runs what the body deferred, also when the body\n * threw; then the body's error is the batch's error (F5), and a deferred\n * watcher's failure leaves only that watcher cold (F3). Inside a drain the\n * drain runs it.\n */\nexport function batch<T>(fn: () => T): T {\n hold++;\n let value: T;\n\n try {\n value = fn();\n } catch (error) {\n if (--hold === 0) {\n try {\n flush();\n } catch {\n // F5: a later error does not replace the body's.\n }\n }\n throw error;\n }\n if (--hold === 0) flush();\n\n return value;\n}\n\n/** Slots the queue holds now (tests). */\nexport function queueLength(): number {\n return queue.length;\n}\n", "// Public API: signal, computed, effect, get, peek, set, update, dispose,\n// batch, untracked, typeOf. A handle is the node itself: nothing is allocated besides\n// the node, and handle <-> node conversions are type assertions only (no\n// runtime wrapper). Every operation here exposes existing kernel and host\n// semantics; none adds state.\nimport { Flag } from \"./graph\";\nimport { drainNow, hold, size, start, stop, watcher } from \"./host\";\nimport {\n dispose as detach,\n createNode,\n peek as refresh,\n read,\n untracked,\n write,\n} from \"./kernel\";\nimport type { Node, NodeFn } from \"./graph\";\n\nexport { batch } from \"./host\";\nexport { untracked } from \"./kernel\";\n\n// Public handles: compile-time brands over the node, which is the runtime\n// handle. Variance is explicit: reading is covariant, a signal is also\n// written, so it is invariant.\ndeclare const READ: unique symbol;\ndeclare const WRITE: unique symbol;\ndeclare const COMPUTED: unique symbol;\ndeclare const EFFECT: unique symbol;\n\n/** Anything `get` accepts. */\nexport interface Readable<out T> {\n readonly [READ]: T;\n}\n\nexport interface Signal<in out T> extends Readable<T> {\n readonly [WRITE]: (value: T) => void;\n}\n\nexport interface Computed<out T> extends Readable<T> {\n readonly [COMPUTED]: true;\n}\n\nexport interface Effect {\n readonly [EFFECT]: true;\n}\n\n/**\n * Identify a live handle without evaluating it. A disposed computed is no\n * longer distinguishable from a signal; passing one is invalid.\n */\nexport function typeOf<T>(target: Signal<T>): \"signal\";\nexport function typeOf(target: Computed<unknown>): \"computed\";\nexport function typeOf(target: Effect): \"effect\";\nexport function typeOf(\n target: Readable<unknown> | Effect,\n): \"signal\" | \"computed\" | \"effect\";\nexport function typeOf(target: unknown): \"signal\" | \"computed\" | \"effect\" {\n const node = target as Node;\n\n if ((node.flags & Flag.Watch) !== 0) return \"effect\";\n return node.fn === null ? \"signal\" : \"computed\";\n}\n\nexport function signal<T>(value: T): Signal<T> {\n return createNode(null, value, 0) as unknown as Signal<T>;\n}\n\n/**\n * `fn` receives `prev`, the last successfully committed value: `initial`\n * (or undefined) before the first commit, unchanged by a failed run.\n * Returning `prev` itself is a cutoff: consumers do not rerun, so custom\n * equality is `(prev) => (equal(prev, next) ? prev : next)`.\n */\nexport function computed<T>(fn: (prev: T | undefined) => T): Computed<T>;\nexport function computed<T>(fn: (prev: T) => T, initial: T): Computed<T>;\nexport function computed<T>(\n fn: (prev: T | undefined) => T,\n initial?: T,\n): Computed<T> {\n return createNode(\n fn as NodeFn,\n initial,\n Flag.Dirty,\n ) as unknown as Computed<T>;\n}\n\n/** Runs now (or when the enclosing batch or drain ends), then on every change it read. */\nexport function effect(fn: () => void | (() => void)): Effect {\n const effectNode = watcher(fn, true);\n\n try {\n start(effectNode);\n } catch (error) {\n // W5: roll the unpublished watcher back. The rollback detaches before it\n // runs the cleanup, so a throwing cleanup still leaves nothing live, and\n // its error does not replace the run's (F5).\n try {\n stop(effectNode);\n } catch {\n /** F5 */\n }\n throw error;\n }\n\n return effectNode as unknown as Effect;\n}\n\n/**\n * Kernel `read` itself under the public type: a signal's flags are 0, so one\n * read path serves signals and computeds, and no surface function stands in\n * front of it.\n */\nexport const get: <T>(source: Readable<T>) => T = read as never;\n\n/** `get` without observation: up to date, but the running consumer does not depend on it. */\nexport const peek: <T>(source: Readable<T>) => T = refresh as never;\n\n/** Writes, then runs what the write scheduled; a write that woke nothing stops at one load. */\nexport function set<T>(source: Signal<T>, value: T): void {\n write(source as unknown as Node, value);\n\n if (size !== 0 && hold === 0) drainNow();\n}\n\n/**\n * `set(source, fn(current))`. An update is a write, not an observation:\n * `fn` runs untracked, so neither `source` nor what `fn` reads becomes a\n * dependency of the running consumer. If `fn` throws, nothing is written.\n */\nexport function update<T>(source: Signal<T>, fn: (value: T) => T): void {\n set(\n source,\n untracked(() => fn((source as unknown as Node).value as T)),\n );\n}\n\nexport function dispose(target: Computed<unknown> | Effect): void {\n const targetNode = target as unknown as Node;\n\n if ((targetNode.flags & Flag.Watch) !== 0) stop(targetNode);\n else detach(targetNode);\n}\n"],
5
+ "mappings": ";AAmGO,IAAMA,EAAS,GAOTC,EAAU,GAOVC,EAAS,UAETC,EAAO,EAOPC,EAAO,EAMPC,EAAO,IACPC,EAAO,IAIb,SAASC,EAAWC,EAAgBC,EAAgBC,EAAoB,CAC7E,MAAO,CACL,MAAAA,EACA,MAAAD,EACA,IAAK,EACL,GAAAD,EACA,SAAU,KACV,QAAS,KACT,SAAU,KACV,KAAM,KACN,IAAK,CACP,CACF,CAGO,SAASG,EAAQC,EAASC,EAASC,EAAmBC,EAAkB,CAC7E,IAAMC,EAASH,EAAE,QACXI,EAAQJ,EAAE,QAChBG,EAAO,QAAUC,EAEbA,IAAU,KAAMA,EAAM,QAAUD,EAC/BJ,EAAE,QAAUI,EAEjBH,EAAE,QAAUC,EACZD,EAAE,QAAUE,EAERD,IAAS,KAAMA,EAAK,QAAUD,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ACb,OAAS3B,EAAO,CACd,GAAI,EAAEQ,IAAS,EACb,GAAI,CACFF,EAAM,CACR,MAAQ,CAER,CAEF,MAAMN,CACR,CACA,MAAI,EAAEQ,IAAS,GAAGF,EAAM,EAEjBsB,CACT,CCvLO,SAASC,GAAOC,EAAmD,CACxE,IAAMC,EAAOD,EAEb,OAAKC,EAAK,MAAQ,MAAgB,EAAU,SACrCA,EAAK,KAAO,KAAO,SAAW,UACvC,CAEO,SAASC,GAAUC,EAAqB,CAC7C,OAAOC,EAAW,KAAMD,EAAO,CAAC,CAClC,CAUO,SAASE,GACdC,EACAC,EACa,CACb,OAAOH,EACLE,EACAC,GAEF,CACF,CAGO,SAASC,GAAOF,EAAuC,CAC5D,IAAMG,EAAaC,GAAQJ,EAAI,EAAI,EAEnC,GAAI,CACFK,GAAMF,CAAU,CAClB,OAASG,EAAO,CAId,GAAI,CACFC,EAAKJ,CAAU,CACjB,MAAQ,CAER,CACA,MAAMG,CACR,CAEA,OAAOH,CACT,CAOO,IAAMK,GAAqCC,EAGrCC,GAAsCA,EAG5C,SAASC,GAAOC,EAAmBf,EAAgB,CACxDgB,EAAMD,EAA2Bf,CAAK,EAElCiB,IAAS,GAAKC,IAAS,GAAGC,EAAS,CACzC,CAOO,SAASC,GAAUL,EAAmBZ,EAA2B,CACtEW,GACEC,EACAM,EAAU,IAAMlB,EAAIY,EAA2B,KAAU,CAAC,CAC5D,CACF,CAEO,SAASO,GAAQzB,EAA0C,CAChE,IAAM0B,EAAa1B,GAEd0B,EAAW,MAAQ,MAAgB,EAAGb,EAAKa,CAAU,EACrDD,EAAOC,CAAU,CACxB",
6
+ "names": ["UNREAD", "SKIPPED", "SETTLE", "SCAN", "TAIL", "KEEP", "TRIM", "createNode", "fn", "value", "flags", "moveDep", "c", "e", "last", "next", "before", "after", "skipDep", "tail", "cutDeps", "unlinkSub", "settleDeps", "gen", "s", "compare", "active", "cursor", "stack", "top", "wake", "onWake", "fn", "trim", "stack", "TRIM", "top", "KEEP", "write", "s", "value", "compare", "e", "n", "f", "wake", "subs", "mark", "first", "base", "next", "read", "peek", "c", "active", "last", "cursor", "miss", "link", "pull", "root", "exec", "verify", "settled", "sf", "up", "error", "p", "check", "w", "tentative", "untracked", "fn", "prev", "prevCursor", "fail", "unindex", "detach", "cutDeps", "SETTLE", "settleDeps", "after", "before", "unlinkSub", "dispose", "index", "unread", "UNREAD", "claim", "cell", "tail", "slot", "alien", "settle", "pair", "skip", "budget", "TAIL", "moveDep", "near", "SCAN", "lookup", "SKIPPED", "skipDep", "found", "begin", "take", "u", "queue", "KEEP", "mask", "head", "spare", "calm", "size", "hold", "wake", "w", "flags", "grow", "onWake", "next", "i", "watcher", "fn", "auto", "createNode", "deliver", "w", "flags", "check", "error", "cleanup", "untracked", "exec", "stop", "dispose", "flush", "size", "hold", "drainNow", "drain", "start", "wake", "failed", "first", "taken", "queuedWatcher", "queue", "head", "mask", "TRIM", "calm", "spare", "shrink", "length", "KEEP", "batch", "fn", "value", "typeOf", "target", "node", "signal", "value", "createNode", "computed", "fn", "initial", "effect", "effectNode", "watcher", "start", "error", "stop", "get", "read", "peek", "set", "source", "write", "size", "hold", "drainNow", "update", "untracked", "dispose", "targetNode"]
7
7
  }