@solidjs/signals 2.0.0-rc.6 → 2.0.0-rc.8
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 +5243 -0
- package/dist/dev.attribution.js +2333 -0
- package/dist/dev.js +1758 -6621
- package/dist/observe/affects.js +127 -0
- package/dist/observe/attribution.js +1 -0
- package/dist/observe/boundaries.js +586 -0
- package/dist/observe/core/action.js +167 -0
- package/dist/observe/core/async.js +736 -0
- package/dist/observe/core/attribution-hooks.js +60 -0
- package/dist/observe/core/attribution.js +2318 -0
- package/dist/{types-cjs/core/constants.d.cts → observe/core/constants.js} +135 -71
- package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
- package/dist/observe/core/core.js +1289 -0
- package/dist/observe/core/dev.js +232 -0
- package/dist/observe/core/effect.js +179 -0
- package/dist/observe/core/error.js +80 -0
- package/dist/observe/core/external.js +98 -0
- package/dist/observe/core/graph.js +155 -0
- package/dist/observe/core/heap.js +147 -0
- package/dist/observe/core/invariants.js +43 -0
- package/dist/observe/core/lanes.js +168 -0
- package/dist/observe/core/optimistic.js +438 -0
- package/dist/observe/core/owner.js +308 -0
- package/dist/observe/core/scheduler.js +1190 -0
- package/dist/observe/core/verdict.js +551 -0
- package/dist/observe/index.js +55 -0
- package/dist/observe/map.js +482 -0
- package/dist/{types-cjs/signals.d.cts → observe/signals.js} +305 -317
- package/dist/observe/store/index.js +38 -0
- package/dist/observe/store/next/optimistic.js +651 -0
- package/dist/observe/store/next/projection.js +242 -0
- package/dist/observe/store/next/reconcile.js +373 -0
- package/dist/observe/store/next/store.js +2213 -0
- package/dist/observe/store/next/target.js +51 -0
- package/dist/observe/store/store.js +323 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/utils.js +210 -0
- package/dist/prod/attribution.js +32 -0
- package/dist/prod/boundaries.js +3 -1
- package/dist/prod/core/action.js +52 -32
- package/dist/prod/core/async.js +177 -128
- package/dist/prod/core/attribution-hooks.js +3 -0
- package/dist/prod/core/constants.js +32 -1
- package/dist/prod/core/context.js +10 -16
- package/dist/prod/core/core.js +505 -286
- package/dist/prod/core/dev.js +2 -0
- package/dist/prod/core/effect.js +72 -43
- package/dist/prod/core/external.js +2 -2
- package/dist/prod/core/graph.js +40 -36
- package/dist/prod/core/heap.js +50 -51
- package/dist/prod/core/lanes.js +43 -22
- package/dist/prod/core/optimistic.js +224 -80
- package/dist/prod/core/owner.js +43 -39
- package/dist/prod/core/scheduler.js +347 -232
- package/dist/prod/core/verdict.js +71 -74
- package/dist/prod/index.js +9 -5
- package/dist/prod/map.js +311 -150
- package/dist/prod/signals.js +52 -38
- package/dist/prod/store/next/optimistic.js +127 -131
- package/dist/prod/store/next/projection.js +3 -3
- package/dist/prod/store/next/reconcile.js +149 -294
- package/dist/prod/store/next/store.js +694 -380
- package/dist/prod/store/next/target.js +32 -10
- package/dist/prod/store/store.js +12 -14
- package/dist/prod/store/utils.js +36 -27
- package/dist/types/attribution.d.ts +15 -0
- package/dist/types/attribution.prod.d.ts +13 -0
- package/dist/types/core/async.d.ts +1 -1
- package/dist/types/core/attribution-hooks.d.ts +183 -6
- package/dist/types/core/attribution.d.ts +435 -24
- package/dist/types/core/constants.d.ts +31 -0
- package/dist/types/core/core.d.ts +19 -3
- package/dist/types/core/dev.d.ts +165 -26
- package/dist/types/core/effect.d.ts +8 -1
- package/dist/types/core/heap.d.ts +5 -3
- package/dist/types/core/index.d.ts +2 -1
- package/dist/types/core/invariants.d.ts +1 -1
- package/dist/types/core/lanes.d.ts +17 -0
- package/dist/types/core/scheduler.d.ts +69 -4
- package/dist/types/core/types.d.ts +29 -9
- package/dist/types/index.d.ts +9 -2
- package/dist/types/map.d.ts +2 -0
- package/dist/types/signals.d.ts +10 -0
- package/dist/types/store/index.d.ts +4 -6
- package/dist/types/store/next/optimistic.d.ts +4 -2
- package/dist/types/store/next/reconcile.d.ts +5 -12
- package/dist/types/store/next/store.d.ts +8 -9
- package/dist/types/store/next/target.d.ts +56 -55
- package/dist/types/store/store.d.ts +14 -9
- package/dist/types/store/utils.d.ts +7 -0
- package/package.json +21 -16
- package/dist/node.cjs +0 -11121
- package/dist/prod/store/next/patch-hooks.js +0 -13
- package/dist/prod/store/next/patch.js +0 -614
- package/dist/types/store/next/patch-hooks.d.ts +0 -41
- package/dist/types/store/next/patch.d.ts +0 -91
- 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 -23
- package/dist/types-cjs/core/attribution-hooks.d.cts +0 -63
- package/dist/types-cjs/core/attribution.d.cts +0 -239
- package/dist/types-cjs/core/core.d.cts +0 -176
- package/dist/types-cjs/core/dev.d.cts +0 -95
- package/dist/types-cjs/core/effect.d.cts +0 -30
- package/dist/types-cjs/core/error.d.cts +0 -56
- package/dist/types-cjs/core/external.d.cts +0 -15
- package/dist/types-cjs/core/graph.d.cts +0 -28
- 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 -231
- package/dist/types-cjs/core/types.d.cts +0 -204
- 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/store/index.d.cts +0 -21
- package/dist/types-cjs/store/next/optimistic.d.cts +0 -23
- package/dist/types-cjs/store/next/patch-hooks.d.cts +0 -41
- package/dist/types-cjs/store/next/patch.d.cts +0 -91
- package/dist/types-cjs/store/next/projection.d.cts +0 -8
- package/dist/types-cjs/store/next/reconcile.d.cts +0 -17
- package/dist/types-cjs/store/next/store.d.cts +0 -127
- package/dist/types-cjs/store/next/target.d.cts +0 -192
- 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/dev.js
CHANGED
package/dist/prod/core/effect.js
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import { REACTIVE_DISPOSED, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, STATUS_PENDING } from "./constants.js";
|
|
1
|
+
import { REACTIVE_DISPOSED, LANE_RUN, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, STATUS_PENDING } from "./constants.js";
|
|
2
2
|
|
|
3
3
|
import { setEffectStatusNotify, ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
|
|
4
4
|
|
|
5
5
|
import { unwrapStatusError, StatusError } from "./error.js";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { enqueueSub } from "./heap.js";
|
|
8
|
+
|
|
9
|
+
import { GlobalQueue, currentTransition, activeTransition, haltReactivity, schedule } from "./scheduler.js";
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
|
11
13
|
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
|
12
14
|
* sources and recompute
|
|
13
|
-
*/ function effect(t, e, E,
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
recompute(
|
|
17
|
-
!
|
|
15
|
+
*/ function effect(t, e, E, r) {
|
|
16
|
+
const n = !!r?.user;
|
|
17
|
+
const f = createEffectNode(t, e, E, n ? EFFECT_USER : EFFECT_RENDER, r);
|
|
18
|
+
recompute(f, true);
|
|
19
|
+
!r?.defer && (f.Ce === EFFECT_USER || r?.schedule ? f.C.enqueue(f.Ce, runEffect.bind(null, f)) : runEffect(f, LANE_RUN));
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
function notifyEffectStatus(t, e) {
|
|
21
23
|
// Use passed values if provided, otherwise read from node
|
|
22
24
|
const E = t !== undefined ? t : this.S;
|
|
23
|
-
const
|
|
25
|
+
const r = e !== undefined ? e : this.o?._;
|
|
24
26
|
if (E & STATUS_ERROR) {
|
|
25
27
|
this.C.notify(this, STATUS_PENDING, 0);
|
|
26
|
-
if (this.
|
|
28
|
+
if (this.Ce === EFFECT_USER) {
|
|
27
29
|
// The error handler is the error arm of the effect phase (#2840 ruling):
|
|
28
30
|
// queue it like the effect function. It runs in the same imperative,
|
|
29
31
|
// writable scope, throws escalate the same way, and a held transition
|
|
@@ -34,22 +36,42 @@ function notifyEffectStatus(t, e) {
|
|
|
34
36
|
// `status` arg without node-state writes) don't queue: the status
|
|
35
37
|
// re-propagates unblocked at commit.
|
|
36
38
|
if (this.S & STATUS_ERROR) {
|
|
37
|
-
this.
|
|
38
|
-
this.C.enqueue(this.
|
|
39
|
+
this.He = true;
|
|
40
|
+
this.C.enqueue(this.Ce, this.rt ??= runEffect.bind(null, this));
|
|
39
41
|
}
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
42
44
|
if (!this.C.notify(this, STATUS_ERROR, STATUS_ERROR)) {
|
|
43
|
-
haltReactivity(unwrapStatusError(
|
|
44
|
-
throw
|
|
45
|
+
haltReactivity(unwrapStatusError(r));
|
|
46
|
+
throw r;
|
|
45
47
|
}
|
|
46
|
-
} else if (this.
|
|
47
|
-
this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E,
|
|
48
|
+
} else if (this.Ce === EFFECT_RENDER) {
|
|
49
|
+
this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E, r);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
function runEffect(t) {
|
|
52
|
-
if (!t.
|
|
53
|
+
function runEffect(t, e) {
|
|
54
|
+
if (!t.He || t.ie & REACTIVE_DISPOSED) return;
|
|
55
|
+
// Ownership (#3319): a value computed under a transaction is applied by that
|
|
56
|
+
// transaction's commit. The ordinary effect phase runs with a transaction
|
|
57
|
+
// active only when the flush's finalize ENTERED one (every other path parks
|
|
58
|
+
// or settles first): leave a run owned by a still-held transaction queued —
|
|
59
|
+
// `_modified` stays set — and the next gate stashes it with the owner.
|
|
60
|
+
// Mainline-owned runs (null) apply now. Lanes are exempt by design (they
|
|
61
|
+
// apply their own effects ahead of their transaction — the optimistic view)
|
|
62
|
+
// and mark their runs with LANE_RUN.
|
|
63
|
+
|
|
64
|
+
// Lane exemption has one exception (#3331): a lane runner for an effect that
|
|
65
|
+
// no longer rides a lane — its optimistic source was superseded, so the lane
|
|
66
|
+
// has no optimistic view left to apply, and the value this effect now
|
|
67
|
+
// carries (or will, once its plain recompute lands) belongs to the still-held
|
|
68
|
+
// transaction. Hand the run to the regular queue, where the transaction's
|
|
69
|
+
// gate stashes it with the owner. Lane-less runners with no live owner
|
|
70
|
+
// (reverts, wake-only lanes) apply now.
|
|
71
|
+
if (t._t !== null && !currentTransition(t._t).ft && (e & LANE_RUN ? !t.o?.Oe : activeTransition !== null)) {
|
|
72
|
+
t.C.enqueue(t.Ce, t.rt);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
53
75
|
// Error arm (#2840), user effects only: a compute-phase error that is still
|
|
54
76
|
// the node's settled state at effect time runs the bundle's error handler in
|
|
55
77
|
// this same imperative, writable scope. Unwrap the StatusError used for
|
|
@@ -60,14 +82,14 @@ function runEffect(t) {
|
|
|
60
82
|
// Render effects bypass: their errors route to boundaries synchronously in
|
|
61
83
|
// notifyEffectStatus, and a runner queued by an earlier valueChanged in the
|
|
62
84
|
// same flush must not be hijacked by a later-arriving error status.
|
|
63
|
-
if (t.S & STATUS_ERROR && t.
|
|
85
|
+
if (t.S & STATUS_ERROR && t.Ce === EFFECT_USER) {
|
|
64
86
|
const e = unwrapStatusError(t.o?._);
|
|
65
|
-
t.
|
|
66
|
-
t.
|
|
87
|
+
t.Ft = t.me;
|
|
88
|
+
t.He = false;
|
|
67
89
|
try {
|
|
68
|
-
t.
|
|
69
|
-
const e = t.
|
|
70
|
-
t.
|
|
90
|
+
t.vt ? t.vt(e, () => {
|
|
91
|
+
const e = t.Ht;
|
|
92
|
+
t.Ht = undefined;
|
|
71
93
|
e?.();
|
|
72
94
|
}) : console.error(e);
|
|
73
95
|
} catch (e) {
|
|
@@ -78,14 +100,14 @@ function runEffect(t) {
|
|
|
78
100
|
}
|
|
79
101
|
return;
|
|
80
102
|
}
|
|
81
|
-
const
|
|
82
|
-
t.
|
|
103
|
+
const E = t.Ht;
|
|
104
|
+
t.Ht = undefined;
|
|
83
105
|
try {
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
if (false &&
|
|
106
|
+
E?.();
|
|
107
|
+
const e = t.ht(t.me, t.Ft);
|
|
108
|
+
if (false && e !== undefined && typeof e !== "function") ;
|
|
87
109
|
// The final cleanup is invoked by disposeChildren at true disposal.
|
|
88
|
-
t.
|
|
110
|
+
t.Ht = e;
|
|
89
111
|
} catch (e) {
|
|
90
112
|
ext(t)._ = new StatusError(t, e);
|
|
91
113
|
t.S |= STATUS_ERROR;
|
|
@@ -94,12 +116,12 @@ function runEffect(t) {
|
|
|
94
116
|
throw e;
|
|
95
117
|
}
|
|
96
118
|
} finally {
|
|
97
|
-
t.
|
|
98
|
-
t.
|
|
119
|
+
t.Ft = t.me;
|
|
120
|
+
t.He = false;
|
|
99
121
|
}
|
|
100
122
|
}
|
|
101
123
|
|
|
102
|
-
GlobalQueue.
|
|
124
|
+
GlobalQueue.ct = runEffect;
|
|
103
125
|
|
|
104
126
|
/**
|
|
105
127
|
* Internal tracked effect - bypasses heap, goes directly to effect queue.
|
|
@@ -107,31 +129,38 @@ GlobalQueue.it = runEffect;
|
|
|
107
129
|
* Uses stale reads.
|
|
108
130
|
*/ function trackedEffect(t, e) {
|
|
109
131
|
const run = () => {
|
|
110
|
-
|
|
132
|
+
// `_modified` is NOT redundant with the heap: the heap dedups within a
|
|
133
|
+
// pass, but a held transition's passes each enqueue `_run` into the same
|
|
134
|
+
// user queue, and this gate is what collapses them into one run at commit.
|
|
135
|
+
if (!E.He || E.ie & REACTIVE_DISPOSED) return;
|
|
111
136
|
try {
|
|
112
|
-
E.
|
|
137
|
+
E.He = false;
|
|
113
138
|
recompute(E);
|
|
114
139
|
} finally {}
|
|
115
140
|
};
|
|
116
141
|
const E = computed(() => {
|
|
117
|
-
const e = E.
|
|
118
|
-
E.
|
|
142
|
+
const e = E.Ht;
|
|
143
|
+
E.Ht = undefined;
|
|
119
144
|
e?.();
|
|
120
|
-
const
|
|
121
|
-
E.
|
|
145
|
+
const r = staleValues(t);
|
|
146
|
+
E.Ht = r;
|
|
122
147
|
}, {
|
|
123
148
|
...e,
|
|
124
149
|
lazy: true
|
|
125
150
|
});
|
|
126
|
-
E.
|
|
151
|
+
E.Ht = undefined;
|
|
127
152
|
E.T = E.T & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
|
|
128
|
-
E.
|
|
129
|
-
E.
|
|
153
|
+
E.He = true;
|
|
154
|
+
E.Ce = EFFECT_TRACKED;
|
|
130
155
|
// Status dispatch rides the SHARED notifier (statusNotifierOf keys off
|
|
131
156
|
// _type): its error arm is behavior-identical to the closure that used to
|
|
132
157
|
// live here, without the per-node NodeExtension allocation.
|
|
133
|
-
E.
|
|
134
|
-
|
|
158
|
+
E.Ve = run;
|
|
159
|
+
// The first run rides the heap like every wake (GlobalQueue._update), so a
|
|
160
|
+
// tracked effect created inside a render-effect callback runs after that
|
|
161
|
+
// pass's staged writes commit, not before.
|
|
162
|
+
enqueueSub(E);
|
|
163
|
+
schedule();
|
|
135
164
|
}
|
|
136
165
|
|
|
137
166
|
// Install the shared effect status notifier (statusNotifierOf serves it to
|
|
@@ -64,8 +64,8 @@ function externalUntrack(e) {
|
|
|
64
64
|
// removed on reset) so core's null checks stay equivalent to the old
|
|
65
65
|
// `externalSourceConfig` truthiness checks.
|
|
66
66
|
function syncExternalHooks() {
|
|
67
|
-
GlobalQueue.
|
|
68
|
-
GlobalQueue.
|
|
67
|
+
GlobalQueue.kt = externalSourceConfig ? wireExternalSource : null;
|
|
68
|
+
GlobalQueue.Lt = externalSourceConfig ? externalUntrack : null;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function enableExternalSource(e) {
|
package/dist/prod/core/graph.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
|
|
1
|
+
import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
|
|
2
|
+
|
|
3
|
+
import { slotUnobservedHook } from "./core.js";
|
|
2
4
|
|
|
3
5
|
import { deleteFromHeap, queueFor } from "./heap.js";
|
|
4
6
|
|
|
@@ -8,15 +10,17 @@ import { bumpNotifyEpoch } from "./scheduler.js";
|
|
|
8
10
|
|
|
9
11
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
|
|
10
12
|
function unlinkSubs(e) {
|
|
11
|
-
const n = e.
|
|
12
|
-
const l = e.
|
|
13
|
-
const o = e.
|
|
14
|
-
const
|
|
15
|
-
if (o !== null) o.en =
|
|
16
|
-
if (
|
|
13
|
+
const n = e.Se;
|
|
14
|
+
const l = e.ae;
|
|
15
|
+
const o = e.Te;
|
|
16
|
+
const s = e.en;
|
|
17
|
+
if (o !== null) o.en = s; else n.dt = s;
|
|
18
|
+
if (s !== null) s.Te = o; else {
|
|
17
19
|
n.u = o;
|
|
18
20
|
if (o === null) {
|
|
19
|
-
|
|
21
|
+
// Slot nodes (store leaves) dispatch to the ONE shared hook — no
|
|
22
|
+
// per-node unobserved closure, no NodeExtension to hold it.
|
|
23
|
+
if (n.T & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.o?.Ct?.();
|
|
20
24
|
// No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
|
|
21
25
|
// A pending node is exempt: its in-flight async work (or the
|
|
22
26
|
// transition holding it) is an observer — tearing down would orphan
|
|
@@ -31,13 +35,13 @@ function unlinkSubs(e) {
|
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
function trimStaleDeps(e) {
|
|
34
|
-
const n = e.
|
|
35
|
-
let l = n !== null ? n.
|
|
38
|
+
const n = e.et;
|
|
39
|
+
let l = n !== null ? n.ae : e.fe;
|
|
36
40
|
if (l !== null) {
|
|
37
41
|
do {
|
|
38
42
|
l = unlinkSubs(l);
|
|
39
43
|
} while (l !== null);
|
|
40
|
-
if (n !== null) n.
|
|
44
|
+
if (n !== null) n.ae = null; else e.fe = null;
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -46,13 +50,13 @@ function trimStaleDeps(e) {
|
|
|
46
50
|
// and skipping early also avoids adding one (hidden-class churn) via the
|
|
47
51
|
// null-out below.
|
|
48
52
|
function clearDeps(e) {
|
|
49
|
-
let n = e.
|
|
53
|
+
let n = e.fe;
|
|
50
54
|
if (!n) return;
|
|
51
55
|
do {
|
|
52
56
|
n = unlinkSubs(n);
|
|
53
57
|
} while (n !== null);
|
|
54
|
-
e.
|
|
55
|
-
e.
|
|
58
|
+
e.fe = null;
|
|
59
|
+
e.et = null;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
function unobserved(e) {
|
|
@@ -104,20 +108,20 @@ function link(e, n, l = false) {
|
|
|
104
108
|
// not relabel the value dependency as probe-only — the value read is what
|
|
105
109
|
// real-error propagation and affects() coverage key off, regardless of
|
|
106
110
|
// read order within the computation.
|
|
107
|
-
const o = n.
|
|
108
|
-
if (o !== null && o.
|
|
109
|
-
o.
|
|
111
|
+
const o = n.et;
|
|
112
|
+
if (o !== null && o.Se === e) {
|
|
113
|
+
o.je &&= l;
|
|
110
114
|
return;
|
|
111
115
|
}
|
|
112
|
-
let
|
|
116
|
+
let s = null;
|
|
113
117
|
const t = n.ie & REACTIVE_RECOMPUTING_DEPS;
|
|
114
118
|
if (t) {
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
n.
|
|
119
|
+
s = o !== null ? o.ae : n.fe;
|
|
120
|
+
if (s !== null && s.Se === e) {
|
|
121
|
+
s.yt = n.tt;
|
|
122
|
+
n.et = s;
|
|
119
123
|
// First touch of this pass: the previous pass's label is stale.
|
|
120
|
-
|
|
124
|
+
s.je = l;
|
|
121
125
|
return;
|
|
122
126
|
}
|
|
123
127
|
}
|
|
@@ -126,24 +130,24 @@ function link(e, n, l = false) {
|
|
|
126
130
|
// [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
|
|
127
131
|
// (the old alien-signals `isValidLink` walk, O(n²) when a computation
|
|
128
132
|
// re-reads earlier deps non-consecutively, e.g. store leaf reads).
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
133
|
+
const r = e.dt;
|
|
134
|
+
if (r !== null && r.Ie === n && (!t || r.yt === n.tt)) {
|
|
131
135
|
// Gen-matched during a recompute = repeat touch this pass (AND); outside
|
|
132
136
|
// a recompute there is no pass boundary, so the latest read labels it.
|
|
133
|
-
if (t)
|
|
137
|
+
if (t) r.je &&= l; else r.je = l;
|
|
134
138
|
return;
|
|
135
139
|
}
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
en:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
const u = n.et = e.dt = {
|
|
141
|
+
Se: e,
|
|
142
|
+
Ie: n,
|
|
143
|
+
ae: s,
|
|
144
|
+
en: r,
|
|
145
|
+
Te: null,
|
|
146
|
+
yt: n.tt,
|
|
147
|
+
je: l
|
|
144
148
|
};
|
|
145
|
-
if (o !== null) o.
|
|
146
|
-
if (
|
|
149
|
+
if (o !== null) o.ae = u; else n.fe = u;
|
|
150
|
+
if (r !== null) r.Te = u; else e.u = u;
|
|
147
151
|
// New subscriber edge: staged-rewrite skips (§12d) must not miss it.
|
|
148
152
|
bumpNotifyEpoch();
|
|
149
153
|
}
|
package/dist/prod/core/heap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./core.js";
|
|
2
2
|
|
|
3
|
-
import { REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT,
|
|
3
|
+
import { REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, REACTIVE_ZOMBIE, REACTIVE_RECOMPUTING_DEPS, REACTIVE_MANUAL_WRITE, REACTIVE_CHECK, REACTIVE_DIRTY, CONFIG_FW_CHILDREN } from "./constants.js";
|
|
4
4
|
|
|
5
5
|
import { zombieQueue, dirtyQueue } from "./scheduler.js";
|
|
6
6
|
|
|
@@ -9,33 +9,27 @@ import { zombieQueue, dirtyQueue } from "./scheduler.js";
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Schedule one subscriber to re-run on the next flush:
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Schedule one subscriber to re-run on the next flush: inserted into its own
|
|
13
|
+
* (zombie-flag-routed) heap with the `_min` cursor pulled down. Tracked
|
|
14
|
+
* effects ride the heap too — the heap visit is their (empty) compute phase,
|
|
15
|
+
* which hands the callback to the user queue once the pass has committed
|
|
16
|
+
* (see GlobalQueue._update, #3291).
|
|
15
17
|
*/ function enqueueSub(e) {
|
|
16
|
-
if (e.ge === EFFECT_TRACKED) {
|
|
17
|
-
const E = e;
|
|
18
|
-
if (!E.tt) {
|
|
19
|
-
E.tt = true;
|
|
20
|
-
E.C.enqueue(EFFECT_USER, E.yt);
|
|
21
|
-
}
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
18
|
const E = queueFor(e);
|
|
25
|
-
if (E.
|
|
19
|
+
if (E.Ke > e.Be) E.Ke = e.Be;
|
|
26
20
|
insertIntoHeap(e, E);
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
function actualInsertIntoHeap(e, E) {
|
|
30
|
-
const t = (e.
|
|
31
|
-
if (t >= e.
|
|
32
|
-
const n = e.
|
|
24
|
+
const t = (e.qe?.gt ? e.qe.bt?.Be : e.qe?.Be) ?? -1;
|
|
25
|
+
if (t >= e.Be) e.Be = t + 1;
|
|
26
|
+
const n = e.Be;
|
|
33
27
|
const I = E.eE[n];
|
|
34
28
|
if (I === undefined) E.eE[n] = e; else {
|
|
35
|
-
const E = I.
|
|
36
|
-
E.
|
|
37
|
-
e.
|
|
38
|
-
I.
|
|
29
|
+
const E = I.Tt;
|
|
30
|
+
E.Nt = e;
|
|
31
|
+
e.Tt = E;
|
|
32
|
+
I.Tt = e;
|
|
39
33
|
}
|
|
40
34
|
if (n > E.EE) E.EE = n;
|
|
41
35
|
}
|
|
@@ -50,12 +44,17 @@ function insertIntoHeap(e, E) {
|
|
|
50
44
|
e.ie = t & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
|
|
51
45
|
} else {
|
|
52
46
|
e.ie = t | REACTIVE_IN_HEAP;
|
|
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
|
-
|
|
47
|
+
// An unmarked node entering an already-marked heap is marked on the
|
|
48
|
+
// spot, keeping the markHeap memo valid. `_marked` is only reset by
|
|
49
|
+
// runHeap, so a write between two mid-tick pulls (read-time markHeap +
|
|
50
|
+
// updateIfNecessary) would otherwise leave this node unmarked and every
|
|
51
|
+
// downstream pull stale until the next flush (#2922: the second
|
|
52
|
+
// `latest()` returned the first write's value). Invalidating the memo
|
|
53
|
+
// instead re-walked the WHOLE heap on the next pull — with N effects
|
|
54
|
+
// parked in the heap for a synchronous mount (each row writing a ref
|
|
55
|
+
// signal its effect subscribes to), mounting N rows was O(N²) (#3350).
|
|
56
|
+
// markNode's own guard skips an already-DIRTY node.
|
|
57
|
+
if (E.tE) markNode(e);
|
|
59
58
|
}
|
|
60
59
|
if (!(t & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, E);
|
|
61
60
|
}
|
|
@@ -71,23 +70,23 @@ function deleteFromHeap(e, E) {
|
|
|
71
70
|
const t = e.ie;
|
|
72
71
|
if (!(t & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
|
|
73
72
|
e.ie = t & -25;
|
|
74
|
-
const n = e.
|
|
75
|
-
if (e.
|
|
76
|
-
const t = e.
|
|
73
|
+
const n = e.Be;
|
|
74
|
+
if (e.Tt === e) E.eE[n] = undefined; else {
|
|
75
|
+
const t = e.Nt;
|
|
77
76
|
const I = E.eE[n];
|
|
78
77
|
const o = t ?? I;
|
|
79
|
-
if (e === I) E.eE[n] = t; else e.
|
|
80
|
-
o.
|
|
78
|
+
if (e === I) E.eE[n] = t; else e.Tt.Nt = t;
|
|
79
|
+
o.Tt = e.Tt;
|
|
81
80
|
}
|
|
82
|
-
e.
|
|
83
|
-
e.
|
|
81
|
+
e.Tt = e;
|
|
82
|
+
e.Nt = undefined;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
function markHeap(e) {
|
|
87
86
|
if (e.tE) return;
|
|
88
87
|
e.tE = true;
|
|
89
88
|
for (let E = 0; E <= e.EE; E++) {
|
|
90
|
-
for (let t = e.eE[E]; t !== undefined; t = t.
|
|
89
|
+
for (let t = e.eE[E]; t !== undefined; t = t.Nt) {
|
|
91
90
|
if (t.ie & REACTIVE_IN_HEAP) markNode(t);
|
|
92
91
|
}
|
|
93
92
|
}
|
|
@@ -97,16 +96,16 @@ function markNode(e, E = REACTIVE_DIRTY) {
|
|
|
97
96
|
const t = e.ie;
|
|
98
97
|
if ((t & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= E) return;
|
|
99
98
|
e.ie = t & -4 | E;
|
|
100
|
-
for (let E = e.u; E !== null; E = E.
|
|
101
|
-
markNode(E.
|
|
99
|
+
for (let E = e.u; E !== null; E = E.Te) {
|
|
100
|
+
markNode(E.Ie, REACTIVE_CHECK);
|
|
102
101
|
}
|
|
103
102
|
// Firewall children (projection machinery only): gate the cold-extension
|
|
104
103
|
// deref on the config bit — markNode runs per sub edge per write, and an
|
|
105
104
|
// unconditional _x chase here taxed every propagation (diamond -22%).
|
|
106
105
|
if (e.T & CONFIG_FW_CHILDREN) {
|
|
107
|
-
for (let E = e.o.i; E !== null; E = E.
|
|
108
|
-
for (let e = E.u; e !== null; e = e.
|
|
109
|
-
markNode(e.
|
|
106
|
+
for (let E = e.o.i; E !== null; E = E.Ee) {
|
|
107
|
+
for (let e = E.u; e !== null; e = e.Te) {
|
|
108
|
+
markNode(e.Ie, REACTIVE_CHECK);
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
}
|
|
@@ -114,11 +113,11 @@ function markNode(e, E = REACTIVE_DIRTY) {
|
|
|
114
113
|
|
|
115
114
|
function runHeap(e, E) {
|
|
116
115
|
e.tE = false;
|
|
117
|
-
for (e.
|
|
118
|
-
let t = e.eE[e.
|
|
116
|
+
for (e.Ke = 0; e.Ke <= e.EE; e.Ke++) {
|
|
117
|
+
let t = e.eE[e.Ke];
|
|
119
118
|
while (t !== undefined) {
|
|
120
119
|
if (t.ie & REACTIVE_IN_HEAP) E(t); else adjustHeight(t, e);
|
|
121
|
-
t = e.eE[e.
|
|
120
|
+
t = e.eE[e.Ke];
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
e.EE = 0;
|
|
@@ -126,21 +125,21 @@ function runHeap(e, E) {
|
|
|
126
125
|
|
|
127
126
|
function adjustHeight(e, E) {
|
|
128
127
|
deleteFromHeap(e, E);
|
|
129
|
-
let t = e.
|
|
130
|
-
for (let E = e.
|
|
131
|
-
const e = E.
|
|
132
|
-
const n = e.
|
|
133
|
-
if (n.oe && n.
|
|
128
|
+
let t = e.Be;
|
|
129
|
+
for (let E = e.fe; E; E = E.ae) {
|
|
130
|
+
const e = E.Se;
|
|
131
|
+
const n = e.ce || e;
|
|
132
|
+
if (n.oe && n.Be >= t) t = n.Be + 1;
|
|
134
133
|
}
|
|
135
|
-
if (e.
|
|
136
|
-
e.
|
|
137
|
-
for (let E = e.u; E !== null; E = E.
|
|
134
|
+
if (e.Be !== t) {
|
|
135
|
+
e.Be = t;
|
|
136
|
+
for (let E = e.u; E !== null; E = E.Te) {
|
|
138
137
|
// Route each subscriber by its own zombie flag, mirroring the
|
|
139
138
|
// post-recompute height-adjust path. Inserting into the running `heap`
|
|
140
139
|
// unconditionally can park a zombie in `dirtyQueue` (or a live node in
|
|
141
140
|
// `zombieQueue`), breaking the flag/queue invariant `deleteFromHeap`
|
|
142
141
|
// relies on — the same corruption class as #2759.
|
|
143
|
-
insertIntoHeapHeight(E.
|
|
142
|
+
insertIntoHeapHeight(E.Ie, queueFor(E.Ie));
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
145
|
}
|