@solidjs/signals 2.0.0-rc.2 → 2.0.0-rc.20
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.
- package/dist/dev-shared.js +6505 -0
- package/dist/dev.attribution.js +3484 -0
- package/dist/dev.js +10227 -9508
- package/dist/observe/affects-marks.js +86 -0
- package/dist/observe/affects.js +112 -0
- package/dist/observe/attribution.js +7 -0
- package/dist/observe/boundaries.js +696 -0
- package/dist/observe/core/action.js +182 -0
- package/dist/observe/core/async.js +824 -0
- package/dist/observe/core/attribution-costs.js +66 -0
- package/dist/observe/core/attribution-feedback.js +280 -0
- package/dist/observe/core/attribution-hooks.js +83 -0
- package/dist/observe/core/attribution-queries.js +43 -0
- package/dist/observe/core/attribution.js +3079 -0
- package/dist/observe/core/constants.js +269 -0
- package/dist/observe/core/context.js +63 -0
- package/dist/observe/core/copies.js +10 -0
- package/dist/observe/core/core.js +1707 -0
- package/dist/observe/core/dev.js +394 -0
- package/dist/observe/core/effect.js +193 -0
- package/dist/observe/core/error-hooks.js +71 -0
- package/dist/observe/core/error.js +82 -0
- package/dist/observe/core/external.js +97 -0
- package/dist/observe/core/graph.js +162 -0
- package/dist/observe/core/heap.js +124 -0
- package/dist/observe/core/identities.js +62 -0
- package/dist/observe/core/invariants.js +12 -0
- package/dist/observe/core/lanes.js +972 -0
- package/dist/observe/core/owner.js +371 -0
- package/dist/observe/core/scheduler.js +1157 -0
- package/dist/observe/core/truth.js +47 -0
- package/dist/observe/core/verdict.js +470 -0
- package/dist/observe/deferred.js +186 -0
- package/dist/observe/flatten.js +79 -0
- package/dist/observe/from.js +248 -0
- package/dist/observe/index.js +71 -0
- package/dist/observe/map.js +593 -0
- package/dist/observe/reveal.js +212 -0
- package/dist/observe/signals.js +717 -0
- package/dist/observe/store/affects.js +142 -0
- package/dist/observe/store/edges.js +39 -0
- package/dist/observe/store/hooks.js +16 -0
- package/dist/observe/store/index.js +47 -0
- package/dist/observe/store/optimistic.js +713 -0
- package/dist/observe/store/projection.js +345 -0
- package/dist/observe/store/reconcile.js +281 -0
- package/dist/observe/store/store.js +2127 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/target.js +46 -0
- package/dist/observe/store/types.js +83 -0
- package/dist/observe/store/utils.js +1063 -0
- package/dist/prod/affects-marks.js +86 -0
- package/dist/prod/affects.js +98 -112
- package/dist/prod/attribution.js +45 -0
- package/dist/prod/boundaries.js +578 -468
- package/dist/prod/core/action.js +92 -59
- package/dist/prod/core/async.js +522 -336
- package/dist/prod/core/attribution-hooks.js +3 -0
- package/dist/prod/core/constants.js +168 -44
- package/dist/prod/core/context.js +12 -16
- package/dist/prod/core/copies.js +10 -0
- package/dist/prod/core/core.js +1345 -627
- package/dist/prod/core/dev.js +123 -1
- package/dist/prod/core/effect.js +113 -80
- package/dist/prod/core/error-hooks.js +71 -0
- package/dist/prod/core/error.js +18 -4
- package/dist/prod/core/external.js +6 -7
- package/dist/prod/core/graph.js +119 -72
- package/dist/prod/core/heap.js +85 -109
- package/dist/prod/core/identities.js +62 -0
- package/dist/prod/core/invariants.js +1 -32
- package/dist/prod/core/lanes.js +931 -132
- package/dist/prod/core/owner.js +192 -129
- package/dist/prod/core/scheduler.js +948 -642
- package/dist/prod/core/truth.js +47 -0
- package/dist/prod/core/verdict.js +409 -420
- package/dist/prod/deferred.js +184 -0
- package/dist/prod/flatten.js +77 -0
- package/dist/prod/from.js +248 -0
- package/dist/prod/index.js +40 -16
- package/dist/prod/map.js +481 -211
- package/dist/prod/reveal.js +212 -0
- package/dist/prod/signals.js +401 -84
- package/dist/prod/store/affects.js +142 -0
- package/dist/prod/store/edges.js +39 -0
- package/dist/prod/store/hooks.js +16 -0
- package/dist/prod/store/index.js +27 -18
- package/dist/prod/store/optimistic.js +707 -0
- package/dist/prod/store/projection.js +331 -0
- package/dist/prod/store/reconcile.js +281 -0
- package/dist/prod/store/store.js +1952 -267
- package/dist/prod/store/storePath.js +1 -1
- package/dist/prod/store/target.js +43 -0
- package/dist/prod/store/types.js +83 -0
- package/dist/prod/store/utils.js +997 -138
- package/dist/types/affects-marks.d.ts +14 -0
- package/dist/types/affects.d.ts +12 -30
- package/dist/types/attribution.d.ts +19 -0
- package/dist/types/attribution.prod.d.ts +22 -0
- package/dist/types/boundaries.d.ts +99 -124
- package/dist/types/carved.d.ts +1 -0
- package/dist/types/core/action.d.ts +23 -9
- package/dist/types/core/async.d.ts +34 -6
- package/dist/types/core/attribution-costs.d.ts +35 -0
- package/dist/types/core/attribution-feedback.d.ts +133 -0
- package/dist/types/core/attribution-hooks.d.ts +307 -8
- package/dist/types/core/attribution-queries.d.ts +24 -0
- package/dist/types/core/attribution.d.ts +802 -72
- package/dist/types/core/constants.d.ts +195 -38
- package/dist/types/core/copies.d.ts +54 -0
- package/dist/types/core/core.d.ts +295 -65
- package/dist/types/core/dev.d.ts +509 -22
- package/dist/types/core/effect.d.ts +1 -1
- package/dist/types/core/error-hooks.d.ts +71 -0
- package/dist/types/core/error.d.ts +18 -1
- package/dist/types/core/graph.d.ts +40 -1
- package/dist/types/core/heap.d.ts +5 -5
- package/dist/types/core/identities.d.ts +17 -0
- package/dist/types/core/index.d.ts +11 -7
- package/dist/types/core/invariants.d.ts +1 -26
- package/dist/types/core/lanes.d.ts +74 -43
- package/dist/types/core/owner.d.ts +27 -9
- package/dist/types/core/scheduler.d.ts +353 -102
- package/dist/types/core/truth.d.ts +18 -0
- package/dist/types/core/types.d.ts +97 -71
- package/dist/types/core/verdict.d.ts +35 -0
- package/dist/types/deferred.d.ts +28 -0
- package/dist/types/flatten.d.ts +8 -0
- package/dist/types/from.d.ts +47 -0
- package/dist/types/index.d.ts +33 -7
- package/dist/types/map.d.ts +4 -2
- package/dist/types/reveal.d.ts +19 -0
- package/dist/types/signals.d.ts +196 -45
- package/dist/types/store/affects.d.ts +12 -0
- package/dist/types/store/edges.d.ts +9 -0
- package/dist/types/store/hooks.d.ts +62 -0
- package/dist/types/store/index.d.ts +42 -15
- package/dist/types/store/optimistic.d.ts +24 -45
- package/dist/types/store/projection.d.ts +17 -68
- package/dist/types/store/reconcile.d.ts +3 -46
- package/dist/types/store/store.d.ts +133 -136
- package/dist/types/store/storePath.d.ts +1 -1
- package/dist/types/store/target.d.ts +166 -0
- package/dist/types/store/types.d.ts +105 -0
- package/dist/types/store/utils.d.ts +188 -0
- package/package.json +31 -26
- package/dist/node.cjs +0 -8745
- package/dist/prod/core/optimistic.js +0 -265
- package/dist/prod/store/next/optimistic.js +0 -385
- package/dist/prod/store/next/projection.js +0 -172
- package/dist/prod/store/next/reconcile.js +0 -331
- package/dist/prod/store/next/store.js +0 -1499
- package/dist/prod/store/next/target.js +0 -20
- package/dist/types/core/optimistic.d.ts +0 -6
- package/dist/types/store/next/optimistic.d.ts +0 -20
- package/dist/types/store/next/projection.d.ts +0 -8
- package/dist/types/store/next/reconcile.d.ts +0 -3
- package/dist/types/store/next/store.d.ts +0 -77
- package/dist/types/store/next/target.d.ts +0 -117
- package/dist/types-cjs/affects.d.cts +0 -47
- package/dist/types-cjs/boundaries.d.cts +0 -175
- package/dist/types-cjs/core/action.d.cts +0 -64
- package/dist/types-cjs/core/async.d.cts +0 -21
- package/dist/types-cjs/core/attribution-hooks.d.cts +0 -52
- package/dist/types-cjs/core/attribution.d.cts +0 -186
- package/dist/types-cjs/core/constants.d.cts +0 -97
- package/dist/types-cjs/core/context.d.cts +0 -36
- package/dist/types-cjs/core/core.d.cts +0 -163
- package/dist/types-cjs/core/dev.d.cts +0 -81
- package/dist/types-cjs/core/effect.d.cts +0 -30
- package/dist/types-cjs/core/error.d.cts +0 -47
- package/dist/types-cjs/core/external.d.cts +0 -15
- package/dist/types-cjs/core/graph.d.cts +0 -6
- package/dist/types-cjs/core/heap.d.cts +0 -22
- package/dist/types-cjs/core/index.d.cts +0 -13
- package/dist/types-cjs/core/invariants.d.cts +0 -59
- package/dist/types-cjs/core/lanes.d.cts +0 -44
- package/dist/types-cjs/core/optimistic.d.cts +0 -6
- package/dist/types-cjs/core/owner.d.cts +0 -124
- package/dist/types-cjs/core/scheduler.d.cts +0 -180
- package/dist/types-cjs/core/types.d.cts +0 -192
- package/dist/types-cjs/core/verdict.d.cts +0 -2
- package/dist/types-cjs/index.d.cts +0 -10
- package/dist/types-cjs/map.d.cts +0 -69
- package/dist/types-cjs/package.json +0 -3
- package/dist/types-cjs/signals.d.cts +0 -624
- package/dist/types-cjs/store/index.d.cts +0 -19
- package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
- package/dist/types-cjs/store/next/projection.d.cts +0 -8
- package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
- package/dist/types-cjs/store/next/store.d.cts +0 -77
- package/dist/types-cjs/store/next/target.d.cts +0 -117
- package/dist/types-cjs/store/optimistic.d.cts +0 -45
- package/dist/types-cjs/store/projection.d.cts +0 -70
- package/dist/types-cjs/store/reconcile.d.cts +0 -46
- package/dist/types-cjs/store/store.d.cts +0 -138
- package/dist/types-cjs/store/storePath.d.cts +0 -58
- package/dist/types-cjs/store/utils.d.cts +0 -74
package/dist/prod/core/graph.js
CHANGED
|
@@ -1,43 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NewSet, REACTIVE_RECOMPUTING_DEPS, CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE } from "./constants.js";
|
|
2
2
|
|
|
3
|
-
import { deleteFromHeap
|
|
3
|
+
import { deleteFromHeap } from "./heap.js";
|
|
4
4
|
|
|
5
|
-
import { disposeChildren } from "./owner.js";
|
|
5
|
+
import { disposeChildren, runCleanup } from "./owner.js";
|
|
6
6
|
|
|
7
|
-
import { bumpNotifyEpoch } from "./scheduler.js";
|
|
7
|
+
import { bumpNotifyEpoch, dirtyQueue } from "./scheduler.js";
|
|
8
|
+
|
|
9
|
+
/** The store's shared slot-node release handler (store/store.ts installs it
|
|
10
|
+
* once) — a live binding read directly by the sweep site: no wrapper frame,
|
|
11
|
+
* no null check (a CONFIG_SLOT_NODE node existing implies the store module
|
|
12
|
+
* loaded and registered it). */ let slotUnobservedHook;
|
|
13
|
+
|
|
14
|
+
function setSlotUnobserved(e) {
|
|
15
|
+
slotUnobservedHook = e;
|
|
16
|
+
}
|
|
8
17
|
|
|
9
18
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
|
|
10
19
|
function unlinkSubs(e) {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const s = e
|
|
15
|
-
if (
|
|
16
|
-
if (s !== null) s.
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
+
const n = e.S;
|
|
21
|
+
const l = e.G;
|
|
22
|
+
const o = e.t;
|
|
23
|
+
const s = e.$e;
|
|
24
|
+
if (o !== null) o.$e = s; else n.Ze = s;
|
|
25
|
+
if (s !== null) s.t = o; else {
|
|
26
|
+
n.o = o;
|
|
27
|
+
if (o === null) {
|
|
28
|
+
// Store slot nodes dispatch to the ONE shared hook — no per-node
|
|
29
|
+
// unobserved closure, no NodeExtension to hold it.
|
|
30
|
+
// A user hook that throws is collected like a cleanup (owner.ts): the
|
|
31
|
+
// unlink and the teardown around it carry on.
|
|
32
|
+
if (n.l & CONFIG_SLOT_NODE) slotUnobservedHook(n); else if (n.T?.Ye) runCleanup(n.T.Ye);
|
|
20
33
|
// No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
|
|
21
|
-
// A pending node is exempt: its in-flight async work
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
// A pending node is exempt: its in-flight async work is an observer —
|
|
35
|
+
// tearing down would orphan the work and re-execute it on the next
|
|
36
|
+
// read. The settle path runs this same last-one-out check when that
|
|
37
|
+
// observer releases (the untracked-read dormancy sweep guards on
|
|
38
|
+
// pending identically).
|
|
39
|
+
// During a pass's teardown of its unfinished frame, the release waits
|
|
40
|
+
// for the pass to end (`deferredReleases`, #4142).
|
|
41
|
+
const e = n;
|
|
42
|
+
e.X && e.l & CONFIG_AUTO_DISPOSE && !(e.R & REACTIVE_ZOMBIE) && !(e.m & STATUS_PENDING) && (deferredReleases ? deferredReleases.push(e) : unobserved(e));
|
|
28
43
|
}
|
|
29
44
|
}
|
|
30
|
-
return
|
|
45
|
+
return l;
|
|
31
46
|
}
|
|
32
47
|
|
|
33
48
|
function trimStaleDeps(e) {
|
|
34
|
-
const
|
|
35
|
-
let
|
|
36
|
-
if (
|
|
49
|
+
const n = e._;
|
|
50
|
+
let l = n !== null ? n.G : e.C;
|
|
51
|
+
if (l !== null) {
|
|
37
52
|
do {
|
|
38
|
-
|
|
39
|
-
} while (
|
|
40
|
-
if (
|
|
53
|
+
l = unlinkSubs(l);
|
|
54
|
+
} while (l !== null);
|
|
55
|
+
if (n !== null) n.G = null; else e.C = null;
|
|
41
56
|
}
|
|
42
57
|
}
|
|
43
58
|
|
|
@@ -46,42 +61,80 @@ function trimStaleDeps(e) {
|
|
|
46
61
|
// and skipping early also avoids adding one (hidden-class churn) via the
|
|
47
62
|
// null-out below.
|
|
48
63
|
function clearDeps(e) {
|
|
49
|
-
let
|
|
50
|
-
if (!
|
|
64
|
+
let n = e.C;
|
|
65
|
+
if (!n) return;
|
|
51
66
|
do {
|
|
52
|
-
|
|
53
|
-
} while (
|
|
54
|
-
e.
|
|
55
|
-
e.
|
|
67
|
+
n = unlinkSubs(n);
|
|
68
|
+
} while (n !== null);
|
|
69
|
+
e.C = null;
|
|
70
|
+
e._ = null;
|
|
56
71
|
}
|
|
57
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Last-one-out releases held back while a pass tears down the frame of an
|
|
75
|
+
* earlier pass that never committed (#4142). The pass is about to rebuild
|
|
76
|
+
* the same children, which read the same lazy nodes again. Released on the
|
|
77
|
+
* spot, a lazy async memo whose only reader was the old frame's child memo
|
|
78
|
+
* was torn down, re-ran on the new child's read, went pending, and the cycle
|
|
79
|
+
* repeated forever. `recompute` collects them around that teardown and
|
|
80
|
+
* releases what is still unobserved when the pass ends.
|
|
81
|
+
*/ let deferredReleases = null;
|
|
82
|
+
|
|
83
|
+
const deferReleases = e => deferredReleases = e;
|
|
84
|
+
|
|
58
85
|
function unobserved(e) {
|
|
59
|
-
deleteFromHeap(e,
|
|
86
|
+
deleteFromHeap(e, dirtyQueue);
|
|
60
87
|
clearDeps(e);
|
|
61
88
|
disposeChildren(e, true);
|
|
62
89
|
}
|
|
63
90
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Deferred dormancy for never-observed auto-dispose computeds (#3078).
|
|
93
|
+
*
|
|
94
|
+
* An untracked top-level read of a subscriber-less observation-lifecycle memo
|
|
95
|
+
* used to call unobserved() inline at the end of read(). That kept the leak
|
|
96
|
+
* closed (the compute links the memo into its deps' sub lists — without a
|
|
97
|
+
* teardown point a never-observed memo is retained by its sources forever;
|
|
98
|
+
* upstream alien-signals has exactly this retention), but it made reads
|
|
99
|
+
* destructive: each read disposed the node, the next read revived it with a
|
|
100
|
+
* full recompute in whatever ambient transition/lane context happened to be
|
|
101
|
+
* current, so consecutive reads could return different answers with no write
|
|
102
|
+
* in between.
|
|
103
|
+
*
|
|
104
|
+
* Instead, reads queue the node here and the scheduler sweeps at the top of
|
|
105
|
+
* the next flush (before runHeap, so a same-tick dirtying is reclaimed
|
|
106
|
+
* instead of recomputed). Reads become idempotent within a tick (the node
|
|
107
|
+
* stays alive and serves its cache, uniform with observed memos) while
|
|
108
|
+
* reclamation still happens within one microtask — the enqueue site arms
|
|
109
|
+
* schedule(), so a flush is guaranteed even when no other work is queued.
|
|
110
|
+
*/ const dormantNodes = new NewSet;
|
|
111
|
+
|
|
112
|
+
function sweepDormant() {
|
|
113
|
+
if (dormantNodes.size === 0) return;
|
|
114
|
+
for (const e of dormantNodes) {
|
|
115
|
+
// Re-validate at sweep time: the node may have gained a subscriber (its
|
|
116
|
+
// lifecycle is the unlinkSubs cascade now), gone pending (in-flight async
|
|
117
|
+
// is an observer; the settle path re-runs last-one-out), lost its
|
|
118
|
+
// AUTO_DISPOSE bit (owner teardown strips it, #3024), or already been
|
|
119
|
+
// torn down.
|
|
120
|
+
if (!e.o && e.l & CONFIG_AUTO_DISPOSE && !(e.m & STATUS_PENDING) && !(e.R & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
|
|
121
|
+
unobserved(e);
|
|
122
|
+
}
|
|
75
123
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
124
|
+
dormantNodes.clear();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L52
|
|
128
|
+
function link(e, n) {
|
|
129
|
+
const l = n._;
|
|
130
|
+
if (l !== null && l.S === e) return;
|
|
131
|
+
let o = null;
|
|
132
|
+
const s = n.R & REACTIVE_RECOMPUTING_DEPS;
|
|
133
|
+
if (s) {
|
|
134
|
+
o = l !== null ? l.G : n.C;
|
|
135
|
+
if (o !== null && o.S === e) {
|
|
136
|
+
o.Ne = n.de;
|
|
137
|
+
n._ = o;
|
|
85
138
|
return;
|
|
86
139
|
}
|
|
87
140
|
}
|
|
@@ -90,26 +143,20 @@ function link(e, l, n = false) {
|
|
|
90
143
|
// [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
|
|
91
144
|
// (the old alien-signals `isValidLink` walk, O(n²) when a computation
|
|
92
145
|
// re-reads earlier deps non-consecutively, e.g. store leaf reads).
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
ae: l,
|
|
103
|
-
it: s,
|
|
104
|
-
el: t,
|
|
105
|
-
fe: null,
|
|
106
|
-
ll: l.Ze,
|
|
107
|
-
me: n
|
|
146
|
+
const r = e.Ze;
|
|
147
|
+
if (r !== null && r.u === n && (!s || r.Ne === n.de)) return;
|
|
148
|
+
const t = n._ = e.Ze = {
|
|
149
|
+
S: e,
|
|
150
|
+
u: n,
|
|
151
|
+
G: o,
|
|
152
|
+
$e: r,
|
|
153
|
+
t: null,
|
|
154
|
+
Ne: n.de
|
|
108
155
|
};
|
|
109
|
-
if (
|
|
110
|
-
if (
|
|
156
|
+
if (l !== null) l.G = t; else n.C = t;
|
|
157
|
+
if (r !== null) r.t = t; else e.o = t;
|
|
111
158
|
// New subscriber edge: staged-rewrite skips (§12d) must not miss it.
|
|
112
159
|
bumpNotifyEpoch();
|
|
113
160
|
}
|
|
114
161
|
|
|
115
|
-
export { clearDeps, link, trimStaleDeps, unlinkSubs, unobserved };
|
|
162
|
+
export { clearDeps, deferReleases, deferredReleases, dormantNodes, link, setSlotUnobserved, slotUnobservedHook, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };
|
package/dist/prod/core/heap.js
CHANGED
|
@@ -1,148 +1,124 @@
|
|
|
1
1
|
import "./core.js";
|
|
2
2
|
|
|
3
|
-
import { REACTIVE_IN_HEAP,
|
|
3
|
+
import { REACTIVE_IN_HEAP, REACTIVE_RECOMPUTING_DEPS, REACTIVE_CHECK, REACTIVE_DIRTY, REACTIVE_IN_HEAP_HEIGHT } from "./constants.js";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
/** The queue a node belongs to, picked from its own zombie flag. */ function queueFor(e) {
|
|
8
|
-
return e.ie & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
|
|
9
|
-
}
|
|
5
|
+
import { dirtyQueue } from "./scheduler.js";
|
|
10
6
|
|
|
11
7
|
/**
|
|
12
|
-
* Schedule one subscriber to re-run on the next flush:
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* Schedule one subscriber to re-run on the next flush: inserted into the
|
|
9
|
+
* dirty heap with the `_min` cursor pulled down. Tracked effects ride the
|
|
10
|
+
* heap too — the heap visit is their (empty) compute phase, which hands the
|
|
11
|
+
* callback to the user queue once the pass has committed (see
|
|
12
|
+
* GlobalQueue._update, #3291).
|
|
15
13
|
*/ function enqueueSub(e) {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
if (!E.Xe) {
|
|
19
|
-
E.Xe = true;
|
|
20
|
-
E.C.enqueue(EFFECT_USER, E.Ut);
|
|
21
|
-
}
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const E = queueFor(e);
|
|
25
|
-
if (E.xe > e.Le) E.xe = e.Le;
|
|
26
|
-
insertIntoHeap(e, E);
|
|
14
|
+
if (dirtyQueue.Fe > e.he) dirtyQueue.Fe = e.he;
|
|
15
|
+
insertIntoHeap(e, dirtyQueue);
|
|
27
16
|
}
|
|
28
17
|
|
|
29
|
-
function actualInsertIntoHeap(e,
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
const n = e.
|
|
33
|
-
const I =
|
|
34
|
-
if (I === undefined)
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
e.
|
|
38
|
-
I.
|
|
18
|
+
function actualInsertIntoHeap(e, t) {
|
|
19
|
+
const E = (e._parent?.Qe ? e._parent.Ke?.he : e._parent?.he) ?? -1;
|
|
20
|
+
if (E >= e.he) e.he = E + 1;
|
|
21
|
+
const n = e.he;
|
|
22
|
+
const I = t.et[n];
|
|
23
|
+
if (I === undefined) t.et[n] = e; else {
|
|
24
|
+
const t = I.We;
|
|
25
|
+
t.ve = e;
|
|
26
|
+
e.We = t;
|
|
27
|
+
I.We = e;
|
|
39
28
|
}
|
|
40
|
-
if (n >
|
|
29
|
+
if (n > t.Et) t.Et = n;
|
|
41
30
|
}
|
|
42
31
|
|
|
43
|
-
function insertIntoHeap(e,
|
|
44
|
-
let
|
|
32
|
+
function insertIntoHeap(e, t) {
|
|
33
|
+
let E = e.R;
|
|
45
34
|
// RECOMPUTING refusals are not always losses: a genuinely missed wake (a
|
|
46
35
|
// write to a link this pass already validated) is latched link-side in
|
|
47
36
|
// insertSubs as REACTIVE_MISSED_WAKE for recompute's tail (#3037).
|
|
48
|
-
if (
|
|
49
|
-
if (
|
|
50
|
-
e.
|
|
37
|
+
if (E & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS)) return;
|
|
38
|
+
if (E & REACTIVE_CHECK) {
|
|
39
|
+
e.R = E & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
|
|
51
40
|
} else {
|
|
52
|
-
e.
|
|
53
|
-
// An unmarked node entering
|
|
54
|
-
// `_marked` is only reset by
|
|
55
|
-
// pulls (read-time markHeap +
|
|
56
|
-
// this node unmarked and every
|
|
57
|
-
// flush (#2922: the second
|
|
58
|
-
|
|
41
|
+
e.R = E | REACTIVE_IN_HEAP;
|
|
42
|
+
// An unmarked node entering an already-marked heap is marked on the
|
|
43
|
+
// spot, keeping the markHeap memo valid. `_marked` is only reset by
|
|
44
|
+
// runHeap, so a write between two mid-tick pulls (read-time markHeap +
|
|
45
|
+
// updateIfNecessary) would otherwise leave this node unmarked and every
|
|
46
|
+
// downstream pull stale until the next flush (#2922: the second
|
|
47
|
+
// `latest()` returned the first write's value). Invalidating the memo
|
|
48
|
+
// instead re-walked the WHOLE heap on the next pull — with N effects
|
|
49
|
+
// parked in the heap for a synchronous mount (each row writing a ref
|
|
50
|
+
// signal its effect subscribes to), mounting N rows was O(N²) (#3350).
|
|
51
|
+
// markNode's own guard skips an already-DIRTY node.
|
|
52
|
+
if (t.p) markNode(e);
|
|
59
53
|
}
|
|
60
|
-
if (!(
|
|
54
|
+
if (!(E & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, t);
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
function insertIntoHeapHeight(e,
|
|
64
|
-
let
|
|
65
|
-
if (
|
|
66
|
-
e.
|
|
67
|
-
actualInsertIntoHeap(e,
|
|
57
|
+
function insertIntoHeapHeight(e, t) {
|
|
58
|
+
let E = e.R;
|
|
59
|
+
if (E & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_IN_HEAP_HEIGHT)) return;
|
|
60
|
+
e.R = E | REACTIVE_IN_HEAP_HEIGHT;
|
|
61
|
+
actualInsertIntoHeap(e, t);
|
|
68
62
|
}
|
|
69
63
|
|
|
70
|
-
function deleteFromHeap(e,
|
|
71
|
-
const
|
|
72
|
-
if (!(
|
|
73
|
-
e.
|
|
74
|
-
const n = e.
|
|
75
|
-
if (e.
|
|
76
|
-
const
|
|
77
|
-
const I =
|
|
78
|
-
const
|
|
79
|
-
if (e === I)
|
|
80
|
-
|
|
64
|
+
function deleteFromHeap(e, t) {
|
|
65
|
+
const E = e.R;
|
|
66
|
+
if (!(E & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
|
|
67
|
+
e.R = E & -25;
|
|
68
|
+
const n = e.he;
|
|
69
|
+
if (e.We === e) t.et[n] = undefined; else {
|
|
70
|
+
const E = e.ve;
|
|
71
|
+
const I = t.et[n];
|
|
72
|
+
const i = E ?? I;
|
|
73
|
+
if (e === I) t.et[n] = E; else e.We.ve = E;
|
|
74
|
+
i.We = e.We;
|
|
81
75
|
}
|
|
82
|
-
e.
|
|
83
|
-
e.
|
|
76
|
+
e.We = e;
|
|
77
|
+
e.ve = undefined;
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
function markHeap(e) {
|
|
87
|
-
if (e.
|
|
88
|
-
e.
|
|
89
|
-
for (let
|
|
90
|
-
for (let
|
|
91
|
-
if (
|
|
81
|
+
if (e.p) return;
|
|
82
|
+
e.p = true;
|
|
83
|
+
for (let t = 0; t <= e.Et; t++) {
|
|
84
|
+
for (let E = e.et[t]; E !== undefined; E = E.ve) {
|
|
85
|
+
if (E.R & REACTIVE_IN_HEAP) markNode(E);
|
|
92
86
|
}
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
89
|
|
|
96
|
-
function markNode(e,
|
|
97
|
-
const
|
|
98
|
-
if ((
|
|
99
|
-
e.
|
|
100
|
-
for (let
|
|
101
|
-
markNode(
|
|
102
|
-
}
|
|
103
|
-
// Firewall children (projection machinery only): gate the cold-extension
|
|
104
|
-
// deref on the config bit — markNode runs per sub edge per write, and an
|
|
105
|
-
// unconditional _x chase here taxed every propagation (diamond -22%).
|
|
106
|
-
if (e.T & CONFIG_FW_CHILDREN) {
|
|
107
|
-
for (let E = e.o.l; E !== null; E = E.ce) {
|
|
108
|
-
for (let e = E.u; e !== null; e = e.fe) {
|
|
109
|
-
markNode(e.ae, REACTIVE_CHECK);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
90
|
+
function markNode(e, t = REACTIVE_DIRTY) {
|
|
91
|
+
const E = e.R;
|
|
92
|
+
if ((E & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= t) return;
|
|
93
|
+
e.R = E & -4 | t;
|
|
94
|
+
for (let t = e.o; t !== null; t = t.t) {
|
|
95
|
+
markNode(t.u, REACTIVE_CHECK);
|
|
112
96
|
}
|
|
113
97
|
}
|
|
114
98
|
|
|
115
|
-
function runHeap(e,
|
|
116
|
-
e.
|
|
117
|
-
for (e.
|
|
118
|
-
let
|
|
119
|
-
while (
|
|
120
|
-
if (
|
|
121
|
-
|
|
99
|
+
function runHeap(e, t) {
|
|
100
|
+
e.p = false;
|
|
101
|
+
for (e.Fe = 0; e.Fe <= e.Et; e.Fe++) {
|
|
102
|
+
let E = e.et[e.Fe];
|
|
103
|
+
while (E !== undefined) {
|
|
104
|
+
if (E.R & REACTIVE_IN_HEAP) t(E); else adjustHeight(E, e);
|
|
105
|
+
E = e.et[e.Fe];
|
|
122
106
|
}
|
|
123
107
|
}
|
|
124
|
-
e.
|
|
108
|
+
e.Et = 0;
|
|
125
109
|
}
|
|
126
110
|
|
|
127
|
-
function adjustHeight(e,
|
|
128
|
-
deleteFromHeap(e,
|
|
129
|
-
let
|
|
130
|
-
for (let
|
|
131
|
-
const e =
|
|
132
|
-
|
|
133
|
-
if (n.Se && n.Le >= t) t = n.Le + 1;
|
|
111
|
+
function adjustHeight(e, t) {
|
|
112
|
+
deleteFromHeap(e, t);
|
|
113
|
+
let E = e.he;
|
|
114
|
+
for (let t = e.C; t; t = t.G) {
|
|
115
|
+
const e = t.S;
|
|
116
|
+
if (e.X && e.he >= E) E = e.he + 1;
|
|
134
117
|
}
|
|
135
|
-
if (e.
|
|
136
|
-
e.
|
|
137
|
-
for (let E = e.
|
|
138
|
-
// Route each subscriber by its own zombie flag, mirroring the
|
|
139
|
-
// post-recompute height-adjust path. Inserting into the running `heap`
|
|
140
|
-
// unconditionally can park a zombie in `dirtyQueue` (or a live node in
|
|
141
|
-
// `zombieQueue`), breaking the flag/queue invariant `deleteFromHeap`
|
|
142
|
-
// relies on — the same corruption class as #2759.
|
|
143
|
-
insertIntoHeapHeight(E.ae, queueFor(E.ae));
|
|
144
|
-
}
|
|
118
|
+
if (e.he !== E) {
|
|
119
|
+
e.he = E;
|
|
120
|
+
for (let E = e.o; E !== null; E = E.t) insertIntoHeapHeight(E.u, t);
|
|
145
121
|
}
|
|
146
122
|
}
|
|
147
123
|
|
|
148
|
-
export { deleteFromHeap, enqueueSub, insertIntoHeap, insertIntoHeapHeight, markHeap, markNode,
|
|
124
|
+
export { deleteFromHeap, enqueueSub, insertIntoHeap, insertIntoHeapHeight, markHeap, markNode, runHeap };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CONFIG_TRANSPARENT } from "./constants.js";
|
|
2
|
+
|
|
3
|
+
import "./core.js";
|
|
4
|
+
|
|
5
|
+
import { getOwner } from "./owner.js";
|
|
6
|
+
|
|
7
|
+
// Deferred hydration, dependency edges: plain-signal identities.
|
|
8
|
+
// While on (`setSignalIdentities`; the server-components client turns it on
|
|
9
|
+
// before hydrating), a plain signal created under an id-bearing owner is
|
|
10
|
+
// named `<owner id>~<n>`, n counting the plain signals (and plain store
|
|
11
|
+
// roots: `createStore` over an object, store/edges.ts) created under that
|
|
12
|
+
// owner in its current pass (transparent owners defer to the nearest
|
|
13
|
+
// id-bearing one, as child ids do). The server names the same signal the
|
|
14
|
+
// same way and restarts the count on every re-run, so an edge it shipped (a
|
|
15
|
+
// slot fill read it) matches the client node; the write hook receives the
|
|
16
|
+
// node and looks its name up (`signalName`). The count restarts when the owner's pass
|
|
17
|
+
// generation (`_depGen`, bumped by every recompute) moves on. Only the
|
|
18
|
+
// frames client imports this module, so nothing here ships without it.
|
|
19
|
+
// Names live in a side table, not on the node: frames reads them across the
|
|
20
|
+
// package boundary, where a mangled field would not survive.
|
|
21
|
+
let counts = null;
|
|
22
|
+
|
|
23
|
+
const names = new WeakMap;
|
|
24
|
+
|
|
25
|
+
/** @internal The identity of a plain signal named while identities were on. */ function signalName(n) {
|
|
26
|
+
return n === undefined ? undefined : names.get(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function identify(n) {
|
|
30
|
+
let e = getOwner();
|
|
31
|
+
if (!e) return;
|
|
32
|
+
while (e.l & CONFIG_TRANSPARENT && e._parent) e = e._parent;
|
|
33
|
+
if (e.id == null) return;
|
|
34
|
+
const t = e.de;
|
|
35
|
+
let i = counts.get(e);
|
|
36
|
+
if (i === undefined || i[0] !== t) counts.set(e, i = [ t, 0 ]);
|
|
37
|
+
const s = e.id + "~" + i[1]++;
|
|
38
|
+
// A store root named twice (one object made into two stores, or a store
|
|
39
|
+
// handed to `createStore`) is one target under two server names: its
|
|
40
|
+
// writes cannot be attributed (an empty name).
|
|
41
|
+
names.set(n, names.has(n) ? "" : s);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @internal Name plain signals from now on (`on`), or stop. */ function setSignalIdentities(n) {
|
|
45
|
+
counts = n ? counts || new WeakMap : null;
|
|
46
|
+
signalHook = n ? identify : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @internal Called with every plain signal `createSignal` makes, and every
|
|
51
|
+
* plain store root `createStore` makes, while set (the namer above). Never
|
|
52
|
+
* set unless `setSignalIdentities` is imported, so a bundle without it keeps
|
|
53
|
+
* only a null check.
|
|
54
|
+
*/ let signalHook = null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @internal Dev only: `watch` is called with every node read while set (the
|
|
58
|
+
* dev hook `onRead`) — the frames client's identity-drift check watches the
|
|
59
|
+
* named signals a deferred occurrence reads as it mounts. A no-op in prod.
|
|
60
|
+
*/ function setReadWatch(n) {}
|
|
61
|
+
|
|
62
|
+
export { setReadWatch, setSignalIdentities, signalHook, signalName };
|
|
@@ -1,36 +1,5 @@
|
|
|
1
1
|
import "./core.js";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* INV-2: a node with an *active* override must be registered for reversion in
|
|
5
|
-
* the queue's or a transition's `_optimisticNodes`. An unregistered active
|
|
6
|
-
* override would survive transition completion forever. Runs at the end of
|
|
7
|
-
* every flush (not just quiescence — the invariant holds mid-transition).
|
|
8
|
-
* (There is no revert-target requirement: authoritative values commit
|
|
9
|
-
* silently into `_value` under the override mask — A17 — so reverting is
|
|
10
|
-
* just dropping the override.)
|
|
11
|
-
*/ function devCheckActiveOverrides(e) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** INV-1: an isPending() probe must never leak past its own call. */ function devCheckFlushStart() {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Companion-vs-oracle census (#2838 pre-work). A NON-ASSERTING diff logger:
|
|
21
|
-
* at the end of every flush it compares each live companion's cached state
|
|
22
|
-
* against a fresh oracle and logs every distinct divergence fingerprint once
|
|
23
|
-
* (console, `[census]` prefix). Legit lane-scoped windows will show up too —
|
|
24
|
-
* the census exists to enumerate the full taxonomy of mid-flight divergence
|
|
25
|
-
* so the write-driven redesign knows every case it must produce, not to
|
|
26
|
-
* judge them. Enabled only when the COMPANION_CENSUS env var is set (in
|
|
27
|
-
* addition to `false`), so normal test runs pay one boolean check.
|
|
28
|
-
*/ typeof globalThis !== "undefined" && !!globalThis.process?.env?.COMPANION_CENSUS;
|
|
29
|
-
|
|
30
|
-
function devCensusCompanions(e) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
3
|
/**
|
|
35
4
|
* Quiescence checks. Run only when the system is fully drained: nothing
|
|
36
5
|
* scheduled, no active/stashed transitions, no live lanes. At that point no
|
|
@@ -40,4 +9,4 @@ function devCensusCompanions(e) {
|
|
|
40
9
|
return;
|
|
41
10
|
}
|
|
42
11
|
|
|
43
|
-
export {
|
|
12
|
+
export { devCheckQuiescent };
|