reflex-quant 1.2.0 → 1.3.1

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// 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;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL;AAAA,IACA,UAAU;AAAA,IACV,SAAS;AAAA,IACT,UAAU;AAAA,IACV,MAAM;AAAA,IACN,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GO,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"]
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 tracking and expiration markers.\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 /** Observed version, EXPIRED after wrap, or an unread tracking marker. */\n ver: Version | typeof UNREAD | typeof SKIPPED | typeof EXPIRED;\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: attach 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 /** Interrupted computed validation. A demand rechecks it and a push passes through. */\n Unverified = 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 // Pull masks. Computed push suppression tests STALE alone.\n Validate = Stale | Unverified,\n Pending = Validate | 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/** An observation from before the producer's current version cycle. */\nexport const EXPIRED = -3;\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 EXPIRED,\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 deduplicates notifications for watchers a write or mark reaches.\n * A push can stop at an already stale computed before reaching a watcher\n * whose previous check failed (D7).\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\n/**\n * Store a changed value; true if a subscriber was reached. A source without\n * subscribers keeps its version: only an edge holds an observation, and an\n * edge attached later records the version current then. Skipping the bump\n * also keeps the version out of a loop-carried read-modify-write.\n */\nexport function write(s: Node, value: unknown): boolean {\n const old = s.value;\n\n // `compare` (P1), spelled out here: V8 compiles Object.is on untyped\n // values to a SameValue builtin call, while this site's `===` keeps the\n // feedback of what is written. Equal operands differ only as +0 and -0,\n // unequal ones are the same only as two NaNs. The commit in `exec` keeps\n // Object.is: it sees `undefined` first and watchers' cleanups, and the\n // spelled form measured slower there.\n if (\n old === value\n ? value !== 0 || 1 / (old as number) === 1 / (value as number)\n : old !== old && value !== value\n )\n return false;\n\n s.value = value;\n\n let e = s.firstSub;\n\n if (e === null) return false;\n bump(s);\n\n for (; 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 | Flag.Stale)) === Flag.Busy) {\n // Running: it may not have read s yet, so versions decide.\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 } 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 return true;\n}\n\n/**\n * A committed change: the next producer version. Versions wrap, so at zero\n * every observation that could alias a later version expires (RQ5): EXPIRED\n * equals no version. Tracking markers (UNREAD, SKIPPED) are negative and\n * stay. O(out-degree) once per 2^30 changes.\n */\nfunction bump(n: Node): void {\n const version = (n.ver + 1) & CounterLimit.Mask;\n\n if (version === 0) expire(n);\n n.ver = version;\n}\n\n/** The wrap's scan, kept out of `bump` so that `bump` stays inlinable. */\nfunction expire(n: Node): void {\n for (let e = n.firstSub; e !== null; e = e.nextSub)\n if (e.ver >= 0) e.ver = EXPIRED;\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/**\n * Bring `n` up to date if it is a stale computed, then track it. Each\n * outcome returns on its own and loads the value last: tracking runs no user\n * code, and V8 then keeps no value in a stack slot across `miss`.\n */\nexport function read(n: Node): unknown {\n if ((n.flags & Flag.Pull) !== 0) pull(n);\n\n const c = active;\n\n if (c === null) return n.value;\n\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\n return n.value;\n }\n\n 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) {\n if (__STATS__) stats.repeats++;\n\n return n.value;\n }\n miss(c, n, last, next);\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 attach(c, n, null, null);\n\n return n.value;\n}\n\n/**\n * `read` for a node that needs no pull: a signal (`readSignal`). The same\n * tracking body as `read`, kept as its own copy so that `read` stays the\n * single function of 1.x and a signal read carries no call to `pull`: when\n * a caller inlines one entry for both kinds, feedback warmed by computed\n * reads makes that call keep the caller's loop values in stack slots\n * (track.duplicate-64). Change both copies together.\n */\nexport function track(n: Node): unknown {\n const c = active;\n\n if (c === null) return n.value;\n\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\n return n.value;\n }\n\n 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) {\n if (__STATS__) stats.repeats++;\n\n return n.value;\n }\n miss(c, n, last, next);\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 attach(c, n, null, null);\n\n return n.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 or UNVERIFIED source is descended into (the stack keeps the edge to\n * climb back through). A DIRTY source runs.\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 (__DEV__ && (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 pending validation, kept apart so `pull` stays\n * small. Disposing a node during the walk clears its pending flags (W3).\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 * The store that consumes the validation flags sets CHECKING. `exec` clears\n * CHECKING as it sets BUSY. Production builds omit this active marker.\n */\nfunction verify(root: Node, f: Flags): void {\n root.flags = __DEV__\n ? (f & ~Flag.Validate) | Flag.Checking\n : f & ~Flag.Validate;\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 // A settled, unchanged source loops back on its own edge: had it\n // shared the comparison after `exec`, V8 would reload the walk's\n // edge from a stack slot on every source.\n if ((sf & (__DEV__ ? Flag.Pull : Flag.Pending)) === 0) {\n if (s.ver === e.ver) {\n e = e.nextDep;\n continue;\n }\n } else {\n if (__DEV__ && (sf & Flag.Active) !== 0)\n throw new Error(\"Cycle detected\");\n\n if ((sf & Flag.Dirty) === 0) {\n s.flags = __DEV__\n ? (sf & ~Flag.Validate) | Flag.Checking\n : sf & ~Flag.Validate;\n stack[top++] = e;\n n = s;\n e = s.firstDep;\n continue;\n }\n exec(s);\n\n if (s.ver === e.ver) {\n e = e.nextDep;\n continue;\n }\n }\n if (n.fn !== null) exec(n);\n break settled;\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 for (;;) {\n // D8: reopen this path to a later push. A direct write during\n // validation or a failed execution can already have established DIRTY.\n if (n.fn !== null) {\n const flags = n.flags & ~(Flag.Validate | Flag.Checking);\n n.flags = (flags & Flag.Dirty) === 0 ? flags | Flag.Unverified : flags;\n }\n if (top === base) break;\n n = (stack[--top] as Edge).to;\n stack[top] = null;\n }\n trim();\n throw error;\n }\n}\n\n/**\n * Validate a watcher's committed frontier before any lifecycle step (P4).\n * A fresh STALE mark restarts the pass. Return the final flags or zero if\n * the watcher was disposed. Tentative edges from failed runs only wake.\n */\nexport function check(w: Node, flags: Flags): Flags {\n const tentative = (w.gen + 1) & CounterLimit.Mask;\n\n for (;;) {\n let e = w.firstDep;\n\n // A watcher without an execution obligation has only committed edges.\n if ((flags & Flag.Dirty) === 0) {\n while (e !== null) {\n const s = e.from;\n\n if (__STATS__) stats.checks++;\n\n // Separate back edges for a settled and a pulled source (see verify).\n if ((s.flags & (__DEV__ ? Flag.Pull : Flag.Pending)) === 0) {\n if (s.ver === e.ver) {\n e = e.nextDep;\n continue;\n }\n } else {\n pull(s);\n\n if (s.ver === e.ver) {\n e = e.nextDep;\n continue;\n }\n }\n w.flags |= Flag.Dirty;\n e = e.nextDep;\n break;\n }\n }\n\n while (e !== null) {\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 e = e.nextDep;\n continue;\n }\n pull(s);\n e = e.nextDep;\n }\n\n if (w.fn === null) return 0;\n flags = w.flags;\n\n if ((flags & Flag.Stale) === 0) return flags;\n w.flags = flags & ~Flag.Stale;\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 // Also consume a watcher's pre-run WOKEN in production. A cleanup write\n // preceded this attempt; retaining its wake would hot-retry a failed body.\n // Writes during the body set a fresh wake and still survive (W2/F4).\n n.flags = (n.flags & ~Flag.PendingMarked) | 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 // The activation has ended: BUSY goes and the owed run is stored here,\n // so the flags are true before `fail` cleans up (truthful state).\n n.flags = (n.flags & ~Flag.Busy) | (n.fn !== null ? Flag.Dirty : 0);\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 disposed(n, value);\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 bump(n);\n }\n}\n\n/**\n * The end of a successful run that disposed its node (W3). The relations are\n * detached, not committed. A computed's value still commits; a watcher's\n * returned cleanup is dropped, as disposal already consumed the last one.\n * Kept out of `exec` so that the live path keeps its shape.\n */\nfunction disposed(n: Node, value: unknown): void {\n detach(n);\n\n if ((n.flags & Flag.Watch) !== 0) return;\n\n if (compare(value, n.value) === false) {\n n.value = value;\n bump(n);\n }\n}\n\n/**\n * A failed run's cleanup, after `exec` ended the activation and owed a run:\n * keep committed edges and this run's reads as the wake set, drop unread\n * edges earlier failed runs left behind.\n */\nfunction fail(n: Node, base: number, last: Edge | null): void {\n if (last !== null && last.from.slot === last) unindex(n, base);\n\n if (n.fn === null) return detach(n);\n\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\n/**\n * Disposal's teardown. A watcher's also clears each removed edge's\n * `nextDep`, so a `check` walking the list ends after the pull that disposed\n * it and starts no further pulls for its delivery (W3). A computed keeps the\n * chain: the walk belongs to the demand in progress, which goes on (W3).\n */\nfunction detach(n: Node): void {\n if ((n.flags & Flag.Watch) === 0) cutDeps(n, null);\n else {\n let e = n.firstDep;\n\n n.firstDep = n.lastDep = null;\n\n while (e !== null) {\n const next: Edge | null = e.nextDep;\n\n unlinkSub(e);\n e.prevDep = e.nextDep = null;\n e = next;\n }\n }\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/** Attach a new observation after a successful peek. */\nfunction attach(c: Node, s: Node, last: Edge | null, next: Edge | null): void {\n if (__STATS__) stats.links++;\n\n const first = s.firstSub;\n const tail = first !== null ? first.prevSub : null;\n // Field order is the object layout: what each walk reads sits together.\n const e: Edge = {\n from: s,\n ver: s.ver,\n nextDep: next,\n to: c,\n nextSub: null,\n gen: (c.gen + 1) & CounterLimit.Mask,\n prevDep: last,\n prevSub: tail,\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 // If the source is still STALE after peek, its push preceded this edge.\n // Pass that pending validation to the new subscriber (P5).\n if ((s.flags & Flag.Stale) !== 0) mark(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 attach(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 attach(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 * A found SKIPPED edge already proves it is unread, even after a failure or\n * its source's wrap (CONTRACT, SKIPPED lemma), so the suffix holds it and\n * `next` is an edge. For other matches, the first subscriber selects a suffix mark. A deeper\n * subscriber selects an index to avoid walking other readers on every lookup.\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) {\n if (found.ver === SKIPPED) {\n if (__STATS__) stats.moves++;\n found.ver = s.ver;\n cursor = found;\n return moveDep(c, found, last, next!);\n }\n begin(c, found, first, next);\n }\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 attach(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 attach(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 // QUEUED means the watcher holds a slot: grow, take the slot, then flag.\n if (size > mask) grow();\n\n queue[(head + size++) & mask] = w;\n w.flags = flags | Flag.Queued;\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 failed check leaves the\n * watcher STALE. A later delivered invalidation checks the committed sources\n * again. Already coalesced invalidations need not reschedule it (D7).\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 if ((check(w, flags) & Flag.Dirty) === 0) return;\n } catch (error) {\n w.flags |= Flag.Stale;\n throw error;\n }\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. It closes the drain itself.\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 // Off the ring means not QUEUED, before the delivery runs user code.\n const flags = queuedWatcher.flags & ~Flag.Queued;\n queuedWatcher.flags = flags;\n\n try {\n deliver(queuedWatcher, flags);\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, read (get), readSignal, compute, peek,\n// set, update, dispose, 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 as readNode,\n track,\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 `read` and `peek` accept: a signal or a computed. */\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 * Read a signal or a computed and, inside a computed or effect, depend on\n * it; a stale computed is brought up to date first. Kernel `read` itself\n * under the public type: one entry serves both kinds, as `get` has since\n * 1.0, and no surface function stands in front of it.\n */\nexport const read: <T>(source: Readable<T>) => T = readNode as never;\n\n/** The 1.x name of `read`: the same function. */\nexport const get: <T>(source: Readable<T>) => T = read;\n\n/**\n * `read` for a signal only, without the computed path: kernel `track` (a\n * copy of `read`'s tracking body, without its pull) under the public type.\n * A signal never needs a pull, so this entry has no path into user code,\n * and a caller that inlines it keeps its own loop values in registers\n * (through `read`, the computed path's call spilled them:\n * track.duplicate-64). The type admits signals only. A computed passed past\n * the types would not be brought up to date: development builds throw,\n * production builds return its last value.\n */\nexport const readSignal: <T>(source: Signal<T>) => T = (\n __DEV__ ? checkedReadSignal : track\n) as never;\n\nfunction checkedReadSignal(n: Node): unknown {\n if (n.fn !== null)\n throw new TypeError(\n \"readSignal() takes a signal; read a computed with read() or compute()\",\n );\n return track(n);\n}\n\n/** `read` for a computed only: the same function, narrowed by type. */\nexport const compute: <T>(source: Computed<T>) => T = read;\n\n/** A read 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/**\n * Writes, then runs what the write scheduled. A write that reached no\n * subscriber scheduled nothing, and outside a batch or drain the queue is\n * already empty (every drain runs until it is), so it skips the host test.\n */\nexport function set<T>(source: Signal<T>, value: T): void {\n if (write(source as unknown as Node, value) && size !== 0 && hold === 0)\n 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": ";;;AAsGO,IAAM,SAAS,IAOT,UAAU,IAEV,UAAU,IAOV,SAAS,WAET,OAAO,GAOP,OAAO,GAMP,OAAO,KACP,OAAO;AAIb,SAAS,WAAW,IAAgB,OAAgB,OAAoB;A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,KACpE,SAAS;AACb;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", "read", "peek", "dispose"]
7
7
  }
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
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};
1
+ /* reflex-quant 1.3.1 | MIT */
2
+ var T=-1,y=-2,G=-3,X=536870911,x=8,z=2,g=256,b=512;function k(e,n,t){return{e:t,l:n,n:0,r:e,u:null,c:null,f:null,a:null,d:0}}function S(e,n,t,o){let l=n.i,u=n.t;l.t=u,u!==null?u.i=l:e.c=l,n.i=t,n.t=o,t!==null?t.t=n:e.u=n,o.i=n}function j(e,n,t,o){let l=t.t,u=e.c;n!==null?n.t=l:e.u=l,l.i=n,t.i=u,t.t=null,u.t=t,e.c=t,u.n===T&&(t.n=T),o!==l&&S(e,o,n,l)}function M(e,n){let t=n===null?e.u:n.t;if(t!==null)for(n===null?e.u=null:n.t=null,e.c=n,t.i=null;t!==null;t=t.t)A(t)}function H(e){let n=e.d;for(let t=e.u;t!==null;t=t.t)t.d=n}function A(e){let n=e.o,t=e.p,o=e.s;e===n.f?n.f=o:t.s=o,o!==null?o.p=t:n.f!==null&&(n.f.p=t),e.p=null,e.s=null}var F=Object.is,a=null,f=null,d=new Array(256).fill(null),i=0;var D=()=>{};function J(e){D=e}function w(){d.length>b&&i===0&&(d.length=g)}function Y(e,n){let t=e.l;if(t===n?n!==0||1/t===1/n:t!==t&&n!==n)return!1;e.l=n;let o=e.f;if(o===null)return!1;for(O(e);o!==null;o=o.s){let l=o._,u=l.e;if((u&5)===4)if(l.e=u|1,(u&16)!==0)D(l);else{let r=l.f;r!==null&&I(r)}else if((u&16)!==0)l.e=u|2|32,D(l);else if((u&1)!==0)l.e=u|2;else{l.e=u|2|1;let r=l.f;r!==null&&I(r)}}return!0}function O(e){let n=e.n+1&1073741823;n===0&&Te(e),e.n=n}function Te(e){for(let n=e.f;n!==null;n=n.s)n.n>=0&&(n.n=G)}function I(e){let n=i,t=e;for(;;){for(;t!==null;){let o=t._,l=o.e;if((l&16)!==0)o.e=l|1,D(o);else if((l&1)===0){o.e=l|1;let u=o.f;if(u!==null){let r=t.s;r!==null&&(d[i++]=r),t=u;continue}}t=t.s}if(i===n){w();return}t=d[--i],d[i]=null}}function Z(e){(e.e&47)!==0&&P(e);let n=a;if(n===null)return e.l;let t=f,o=t===null?n.u:t.t;if(o!==null&&o.o===e)return f=o,o.n=e.n,e.l;if(t!==null){if(t.o===e)return e.l;C(n,e,t,o)}else o!==null?C(n,e,t,o):h(n,e,null,null);return e.l}function $(e){let n=a;if(n===null)return e.l;let t=f,o=t===null?n.u:t.t;if(o!==null&&o.o===e)return f=o,o.n=e.n,e.l;if(t!==null){if(t.o===e)return e.l;C(n,e,t,o)}else o!==null?C(n,e,t,o):h(n,e,null,null);return e.l}function ee(e){return(e.e&47)!==0&&P(e),e.l}function P(e){let n=e.e;if((n&2)!==0)return E(e);Ee(e,n)}function Ee(e,n){e.e=n&-10;let t=i,o=e,l=e.u;try{for(;;){e:for(;l!==null;){let u=l.o,r=u.e;if((r&11)===0){if(u.n===l.n){l=l.t;continue}}else{if((r&2)===0){u.e=r&-10,d[i++]=l,o=u,l=u.u;continue}if(E(u),u.n===l.n){l=l.t;continue}}o.r!==null&&E(o);break e}for(;;){if(i===t){w();return}let u=d[--i];if(d[i]=null,o=u._,u.o.n===u.n){l=u.t;break}o.r!==null&&E(o)}}}catch(u){for(;;){if(o.r!==null){let r=o.e&-42;o.e=(r&2)===0?r|8:r}if(i===t)break;o=d[--i]._,d[i]=null}throw w(),u}}function ne(e,n){let t=e.d+1&1073741823;for(;;){let o=e.u;if((n&2)===0)for(;o!==null;){let l=o.o;if((l.e&11)===0){if(l.n===o.n){o=o.t;continue}}else if(P(l),l.n===o.n){o=o.t;continue}e.e|=2,o=o.t;break}for(;o!==null;){let l=o.o;if((l.e&11)===0||o.d===t){o=o.t;continue}P(l),o=o.t}if(e.r===null)return 0;if(n=e.e,(n&1)===0)return n;e.e=n&-2}}function N(e){let n=a;a=null;try{return e()}finally{a=n}}function E(e){let n=a,t=f,o=i;e.e=e.e&-44|4,a=e,f=null;let l;try{l=e.r(e.l)}catch(R){let V=f;throw a=n,f=t,e.e=e.e&-5|(e.r!==null?2:0),ke(e,o,V),R}let u=f;a=n,f=t;let r=e.e;if(u!==null&&u.o.a===u&&le(e,o),e.e=r&-5,e.r===null)return ge(e,l);(u===null?e.u:u.t)!==null&&M(e,u),e.d=e.d+1&1073741823,(e.d&X)===0&&H(e),F(l,e.l)===!1&&(e.l=l,O(e))}function ge(e,n){q(e),(e.e&16)===0&&F(n,e.l)===!1&&(e.l=n,O(e))}function ke(e,n,t){if(t!==null&&t.o.a===t&&le(e,n),e.r===null)return q(e);let o=e.d+1&1073741823;for(let l=t===null?e.u:t.t;l!==null;){let u=l.t;if(l.d===o){let r=l.i;r!==null?r.t=u:e.u=u,u!==null?u.i=r:e.c=r,A(l),l.i=null,l.t=null}l=u}}function W(e){e.r!==null&&(e.r=null,(e.e&4)===0&&q(e))}function q(e){if((e.e&16)===0)M(e,null);else{let n=e.u;for(e.u=e.c=null;n!==null;){let t=n.t;A(n),n.i=n.t=null,n=t}}e.e&=-44}function te(e,n){let t=!1;for(let o=e.u;o!==null;o=o.t)o===n&&(t=!0),t&&(o.n=T),oe(o.o,o)}function oe(e,n){let t=e.a;t!==null&&(d[i++]=t),e.a=n}function le(e,n){for(let t=e.u;t!==null;t=t.t)t.o.a=null;for(;i>n;){let t=d[--i];d[i]=null,t.o.a=t}w()}function h(e,n,t,o){let l=n.f,u=l!==null?l.p:null,r={o:n,n:n.n,t:o,_:e,s:null,d:e.d+1&1073741823,i:t,p:u};t!==null?t.t=r:e.u=r,o!==null?o.i=r:e.c=r,l!==null?(u.s=r,l.p=r):(n.f=r,r.p=r),f=r,(n.e&1)!==0&&I(r)}function C(e,n,t,o){if(t!==null&&t.o.a===t)return ie(e,n,t,o);let l=n.f;if(l===null||he(l,e))return h(e,n,t,o);if(o!==null&&o.n===T)return re(e,n,t,o,fe(l,e));if(o!==null){let u=o.t;if(u!==null&&u.o===n)return ue(e,n,t,o,u);let r=z;for(u=e.c;u!==o&&u.o!==n&&--r!==0;)u=u.i;if(u.o===n)return u.n=n.n,f=u,S(e,u,t,o)}Se(e,n,t,o,l)}function Se(e,n,t,o,l){let u=null;if(o!==null){let V=x;for(u=o.t;u!==null&&u.o!==n&&--V!==0;)u=u.t;if(u!==null&&u.o===n)return ue(e,n,t,o,u)}let r=t!==null?t.i:null,R=x;for(;r!==null&&r.o!==n&&--R!==0;)r=r.i;if(!(r!==null&&r.o===n)){if(u===null&&r===null)return h(e,n,t,o);Ne(e,n,t,o,l)}}function ue(e,n,t,o,l){if(l.n=n.n,f=l,o.n===y)return j(e,t,o,l);o.n=y,S(e,l,t,o)}function Ne(e,n,t,o,l){let u=fe(l,e);if(u!=null){if(u.n===y)return u.n=n.n,f=u,S(e,u,t,o);me(e,u,l,o)}re(e,n,t,o,u)}function re(e,n,t,o,l){if(l===null)return h(e,n,t,o);if(l!==void 0)return de(e,l,n,t,o);te(e,o),ie(e,n,t,o)}function ie(e,n,t,o){let l=n.a;if(l!==null&&l._===e)return de(e,l,n,t,o);h(e,n,t,o),oe(n,f)}function he(e,n){let t=e.p;return e._!==n&&t._!==n&&(t===e||e.s===t)}function fe(e,n){let t=x;for(let o=e;o!==null;o=o.s){if(o._===n)return o;if(--t===0)return}return null}function me(e,n,t,o){if(o!==null){if(n!==t)return te(e,o);for(let l=o;l!==null;l=l.t)l.n=T}}function de(e,n,t,o,l){n.n===T&&(n.n=t.n,S(e,n,o,l),f=n)}var m=new Array(g).fill(null),p=g-1,_=0,B=0,v=0,s=0,c=0;function se(e){let n=e.e;(n&192)===64&&(s>p&&ve(),m[_+s++&p]=e,e.e=n|128)}J(se);function ve(){let e=new Array(s+s).fill(null);for(let n=0;n<s;n++)e[n]=m[_+n&p];m=e,p=s+s-1,_=0}function ce(e,n){return k(e,void 0,19|(n?64:0))}function ye(e,n){if(e.r===null||(n&33)===0){e.e=n;return}if(e.e=n&-34,(n&1)!==0)try{if((ne(e,n)&2)===0)return}catch(o){throw e.e|=1,o}let t=e.l;typeof t=="function"&&(e.l=void 0,N(t),e.r===null)||E(e)}function L(e){if(e.r===null)return;let n=e.l;e.l=void 0,W(e),typeof n=="function"&&N(n)}function U(){s===0||c!==0||Q()}function Q(){c=1,K(!1,void 0)}function ae(e){if(c!==0||s!==0)return se(e),U();c=1;try{E(e)}catch(n){return K(!0,n)}K(!1,void 0)}function K(e,n){let t=0;for(;s!==0;t++){let o=m[_];m[_]=null,_=_+1&p,s--;let l=o.e&-129;o.e=l;try{ye(o,l)}catch(u){e||(n=u),e=!0}}if(_=0,p>=b&&(t+t<p>>1?(t>v&&(v=t),(B+=t)>p&&xe(v)):B=v=0),c=0,e)throw n}function xe(e){let n=g;for(;n<e+e;)n+=n;m.length=n,p=n-1,B=v=0}function be(e){c++;let n;try{n=e()}catch(t){if(--c===0)try{U()}catch{}throw t}return--c===0&&U(),n}function qe(e){let n=e;return(n.e&16)!==0?"effect":n.r===null?"signal":"computed"}function Be(e){return k(null,e,0)}function Ue(e,n){return k(e,n,2)}function Ke(e){let n=ce(e,!0);try{ae(n)}catch(t){try{L(n)}catch{}throw t}return n}var pe=Z,Le=pe,Qe=$;var Ge=pe,Xe=ee;function Ae(e,n){Y(e,n)&&s!==0&&c===0&&Q()}function ze(e,n){Ae(e,N(()=>n(e.l)))}function je(e){let n=e;(n.e&16)!==0?L(n):W(n)}export{be as batch,Ge as compute,Ue as computed,je as dispose,Ke as effect,Le as get,Xe as peek,pe as read,Qe as readSignal,Ae as set,Be as signal,qe as typeOf,N as untracked,ze as update};
3
3
  //# sourceMappingURL=index.js.map