@solidjs/signals 2.0.0-rc.3 → 2.0.0-rc.5
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.js +2494 -271
- package/dist/node.cjs +3691 -1595
- package/dist/prod/affects.js +13 -12
- package/dist/prod/boundaries.js +43 -35
- package/dist/prod/core/action.js +3 -3
- package/dist/prod/core/async.js +137 -106
- package/dist/prod/core/constants.js +55 -1
- package/dist/prod/core/core.js +354 -247
- package/dist/prod/core/effect.js +47 -50
- package/dist/prod/core/error.js +13 -1
- package/dist/prod/core/external.js +4 -4
- package/dist/prod/core/graph.js +88 -52
- package/dist/prod/core/heap.js +38 -38
- package/dist/prod/core/lanes.js +34 -34
- package/dist/prod/core/optimistic.js +61 -58
- package/dist/prod/core/owner.js +38 -38
- package/dist/prod/core/scheduler.js +401 -174
- package/dist/prod/core/verdict.js +132 -65
- package/dist/prod/index.js +7 -3
- package/dist/prod/map.js +106 -106
- package/dist/prod/signals.js +253 -25
- package/dist/prod/store/index.js +2 -0
- package/dist/prod/store/next/optimistic.js +314 -121
- package/dist/prod/store/next/patch-hooks.js +13 -0
- package/dist/prod/store/next/patch.js +614 -0
- package/dist/prod/store/next/projection.js +23 -19
- package/dist/prod/store/next/reconcile.js +307 -120
- package/dist/prod/store/next/store.js +440 -117
- package/dist/prod/store/next/target.js +13 -4
- package/dist/prod/store/store.js +5 -5
- package/dist/types/core/async.d.ts +2 -0
- package/dist/types/core/attribution.d.ts +9 -4
- package/dist/types/core/constants.d.ts +54 -0
- package/dist/types/core/core.d.ts +34 -21
- package/dist/types/core/dev.d.ts +8 -0
- package/dist/types/core/error.d.ts +9 -0
- package/dist/types/core/graph.d.ts +22 -0
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/scheduler.d.ts +46 -0
- package/dist/types/core/types.d.ts +12 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/signals.d.ts +108 -0
- package/dist/types/store/index.d.ts +2 -0
- package/dist/types/store/next/optimistic.d.ts +13 -10
- package/dist/types/store/next/patch-hooks.d.ts +41 -0
- package/dist/types/store/next/patch.d.ts +91 -0
- package/dist/types/store/next/projection.d.ts +1 -1
- package/dist/types/store/next/reconcile.d.ts +14 -0
- package/dist/types/store/next/store.d.ts +52 -2
- package/dist/types/store/next/target.d.ts +73 -8
- package/dist/types-cjs/core/async.d.cts +2 -0
- package/dist/types-cjs/core/attribution.d.cts +9 -4
- package/dist/types-cjs/core/constants.d.cts +54 -0
- package/dist/types-cjs/core/core.d.cts +34 -21
- package/dist/types-cjs/core/dev.d.cts +8 -0
- package/dist/types-cjs/core/error.d.cts +9 -0
- package/dist/types-cjs/core/graph.d.cts +22 -0
- package/dist/types-cjs/core/index.d.cts +2 -2
- package/dist/types-cjs/core/scheduler.d.cts +46 -0
- package/dist/types-cjs/core/types.d.cts +12 -0
- package/dist/types-cjs/index.d.cts +3 -3
- package/dist/types-cjs/signals.d.cts +108 -0
- package/dist/types-cjs/store/index.d.cts +2 -0
- package/dist/types-cjs/store/next/optimistic.d.cts +13 -10
- package/dist/types-cjs/store/next/patch-hooks.d.cts +41 -0
- package/dist/types-cjs/store/next/patch.d.cts +91 -0
- package/dist/types-cjs/store/next/projection.d.cts +1 -1
- package/dist/types-cjs/store/next/reconcile.d.cts +14 -0
- package/dist/types-cjs/store/next/store.d.cts +52 -2
- package/dist/types-cjs/store/next/target.d.cts +73 -8
- package/package.json +2 -2
package/dist/prod/core/effect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { REACTIVE_DISPOSED, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED,
|
|
1
|
+
import { REACTIVE_DISPOSED, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, STATUS_PENDING } from "./constants.js";
|
|
2
2
|
|
|
3
|
-
import { ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
|
|
3
|
+
import { setEffectStatusNotify, ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
|
|
4
4
|
|
|
5
5
|
import { unwrapStatusError, StatusError } from "./error.js";
|
|
6
6
|
|
|
@@ -10,20 +10,20 @@ import { GlobalQueue, haltReactivity } from "./scheduler.js";
|
|
|
10
10
|
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
|
11
11
|
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
|
12
12
|
* sources and recompute
|
|
13
|
-
*/ function effect(t, e, E,
|
|
14
|
-
const r = !!
|
|
15
|
-
const
|
|
16
|
-
recompute(
|
|
17
|
-
!
|
|
13
|
+
*/ function effect(t, e, E, f) {
|
|
14
|
+
const r = !!f?.user;
|
|
15
|
+
const R = createEffectNode(t, e, E, r ? EFFECT_USER : EFFECT_RENDER, f);
|
|
16
|
+
recompute(R, true);
|
|
17
|
+
!f?.defer && (R.he === EFFECT_USER || f?.schedule ? R.C.enqueue(R.he, runEffect.bind(null, R)) : runEffect(R));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function notifyEffectStatus(t, e) {
|
|
21
21
|
// Use passed values if provided, otherwise read from node
|
|
22
22
|
const E = t !== undefined ? t : this.S;
|
|
23
|
-
const
|
|
23
|
+
const f = e !== undefined ? e : this.o?._;
|
|
24
24
|
if (E & STATUS_ERROR) {
|
|
25
25
|
this.C.notify(this, STATUS_PENDING, 0);
|
|
26
|
-
if (this.
|
|
26
|
+
if (this.he === EFFECT_USER) {
|
|
27
27
|
// The error handler is the error arm of the effect phase (#2840 ruling):
|
|
28
28
|
// queue it like the effect function. It runs in the same imperative,
|
|
29
29
|
// writable scope, throws escalate the same way, and a held transition
|
|
@@ -34,22 +34,22 @@ function notifyEffectStatus(t, e) {
|
|
|
34
34
|
// `status` arg without node-state writes) don't queue: the status
|
|
35
35
|
// re-propagates unblocked at commit.
|
|
36
36
|
if (this.S & STATUS_ERROR) {
|
|
37
|
-
this.
|
|
38
|
-
this.C.enqueue(this.
|
|
37
|
+
this.tt = true;
|
|
38
|
+
this.C.enqueue(this.he, this.nt ??= runEffect.bind(null, this));
|
|
39
39
|
}
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
if (!this.C.notify(this, STATUS_ERROR, STATUS_ERROR)) {
|
|
43
|
-
haltReactivity(unwrapStatusError(
|
|
44
|
-
throw
|
|
43
|
+
haltReactivity(unwrapStatusError(f));
|
|
44
|
+
throw f;
|
|
45
45
|
}
|
|
46
|
-
} else if (this.
|
|
47
|
-
this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E,
|
|
46
|
+
} else if (this.he === EFFECT_RENDER) {
|
|
47
|
+
this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E, f);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function runEffect(t) {
|
|
52
|
-
if (!t.
|
|
52
|
+
if (!t.tt || t.ie & REACTIVE_DISPOSED) return;
|
|
53
53
|
// Error arm (#2840), user effects only: a compute-phase error that is still
|
|
54
54
|
// the node's settled state at effect time runs the bundle's error handler in
|
|
55
55
|
// this same imperative, writable scope. Unwrap the StatusError used for
|
|
@@ -60,14 +60,14 @@ function runEffect(t) {
|
|
|
60
60
|
// Render effects bypass: their errors route to boundaries synchronously in
|
|
61
61
|
// notifyEffectStatus, and a runner queued by an earlier valueChanged in the
|
|
62
62
|
// same flush must not be hijacked by a later-arriving error status.
|
|
63
|
-
if (t.S & STATUS_ERROR && t.
|
|
63
|
+
if (t.S & STATUS_ERROR && t.he === EFFECT_USER) {
|
|
64
64
|
const e = unwrapStatusError(t.o?._);
|
|
65
|
-
t.
|
|
66
|
-
t.
|
|
65
|
+
t.At = t.be;
|
|
66
|
+
t.tt = false;
|
|
67
67
|
try {
|
|
68
|
-
t.
|
|
69
|
-
const e = t.
|
|
70
|
-
t.
|
|
68
|
+
t.Ct ? t.Ct(e, () => {
|
|
69
|
+
const e = t.Rt;
|
|
70
|
+
t.Rt = undefined;
|
|
71
71
|
e?.();
|
|
72
72
|
}) : console.error(e);
|
|
73
73
|
} catch (e) {
|
|
@@ -78,14 +78,14 @@ function runEffect(t) {
|
|
|
78
78
|
}
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
|
-
const e = t.
|
|
82
|
-
t.
|
|
81
|
+
const e = t.Rt;
|
|
82
|
+
t.Rt = undefined;
|
|
83
83
|
try {
|
|
84
84
|
e?.();
|
|
85
|
-
const E = t.
|
|
85
|
+
const E = t.Ot(t.be, t.At);
|
|
86
86
|
if (false && E !== undefined && typeof E !== "function") ;
|
|
87
87
|
// The final cleanup is invoked by disposeChildren at true disposal.
|
|
88
|
-
t.
|
|
88
|
+
t.Rt = E;
|
|
89
89
|
} catch (e) {
|
|
90
90
|
ext(t)._ = new StatusError(t, e);
|
|
91
91
|
t.S |= STATUS_ERROR;
|
|
@@ -94,12 +94,12 @@ function runEffect(t) {
|
|
|
94
94
|
throw e;
|
|
95
95
|
}
|
|
96
96
|
} finally {
|
|
97
|
-
t.
|
|
98
|
-
t.
|
|
97
|
+
t.At = t.be;
|
|
98
|
+
t.tt = false;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
GlobalQueue.
|
|
102
|
+
GlobalQueue.it = runEffect;
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* Internal tracked effect - bypasses heap, goes directly to effect queue.
|
|
@@ -107,39 +107,36 @@ GlobalQueue.tt = runEffect;
|
|
|
107
107
|
* Uses stale reads.
|
|
108
108
|
*/ function trackedEffect(t, e) {
|
|
109
109
|
const run = () => {
|
|
110
|
-
if (!E.
|
|
110
|
+
if (!E.tt || E.ie & REACTIVE_DISPOSED) return;
|
|
111
111
|
try {
|
|
112
|
-
E.
|
|
112
|
+
E.tt = false;
|
|
113
113
|
recompute(E);
|
|
114
114
|
} finally {}
|
|
115
115
|
};
|
|
116
116
|
const E = computed(() => {
|
|
117
|
-
const e = E.
|
|
118
|
-
E.
|
|
117
|
+
const e = E.Rt;
|
|
118
|
+
E.Rt = undefined;
|
|
119
119
|
e?.();
|
|
120
|
-
const
|
|
121
|
-
E.
|
|
120
|
+
const f = staleValues(t);
|
|
121
|
+
E.Rt = f;
|
|
122
122
|
}, {
|
|
123
123
|
...e,
|
|
124
124
|
lazy: true
|
|
125
125
|
});
|
|
126
|
-
E.
|
|
126
|
+
E.Rt = undefined;
|
|
127
127
|
E.T = E.T & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
|
|
128
|
-
E.
|
|
129
|
-
E.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const t = e !== undefined ? e : E.o?._;
|
|
135
|
-
if (!E.C.notify(E, STATUS_ERROR, STATUS_ERROR)) {
|
|
136
|
-
haltReactivity(unwrapStatusError(t));
|
|
137
|
-
throw t;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
E.Ut = run;
|
|
128
|
+
E.tt = true;
|
|
129
|
+
E.he = EFFECT_TRACKED;
|
|
130
|
+
// Status dispatch rides the SHARED notifier (statusNotifierOf keys off
|
|
131
|
+
// _type): its error arm is behavior-identical to the closure that used to
|
|
132
|
+
// live here, without the per-node NodeExtension allocation.
|
|
133
|
+
E.yt = run;
|
|
142
134
|
E.C.enqueue(EFFECT_USER, run);
|
|
143
135
|
}
|
|
144
136
|
|
|
137
|
+
// Install the shared effect status notifier (statusNotifierOf serves it to
|
|
138
|
+
// every effect node) — module-scope: any bundle that creates effects
|
|
139
|
+
// evaluates this module.
|
|
140
|
+
setEffectStatusNotify(notifyEffectStatus);
|
|
141
|
+
|
|
145
142
|
export { effect, trackedEffect };
|
package/dist/prod/core/error.js
CHANGED
|
@@ -53,6 +53,18 @@ class StatusError extends Error {
|
|
|
53
53
|
return r instanceof StatusError ? r.cause : r;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Rejection value of `until(fn, { timeout })` when the predicate does not turn
|
|
58
|
+
* truthy within the window. Inside an `action()`, the rejection is thrown back
|
|
59
|
+
* in at the `yield` point — catchable there, or the action fails and its
|
|
60
|
+
* optimistic state reverts.
|
|
61
|
+
*/ class TimeoutError extends Error {
|
|
62
|
+
constructor(r = "Timed out waiting for condition") {
|
|
63
|
+
super(r);
|
|
64
|
+
this.name = "TimeoutError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
56
68
|
class NoOwnerError extends Error {
|
|
57
69
|
constructor() {
|
|
58
70
|
super("");
|
|
@@ -65,4 +77,4 @@ class ContextNotFoundError extends Error {
|
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
79
|
|
|
68
|
-
export { ContextNotFoundError, NoOwnerError, NotReadyError, StatusError, unwrapStatusError };
|
|
80
|
+
export { ContextNotFoundError, NoOwnerError, NotReadyError, StatusError, TimeoutError, unwrapStatusError };
|
|
@@ -46,11 +46,11 @@ function wireExternalSource(e) {
|
|
|
46
46
|
equals: false,
|
|
47
47
|
ownedWrite: true
|
|
48
48
|
});
|
|
49
|
-
const r = externalSourceConfig.factory(e.
|
|
49
|
+
const r = externalSourceConfig.factory(e.oe, () => {
|
|
50
50
|
setSignal(n, undefined);
|
|
51
51
|
});
|
|
52
52
|
cleanup(() => r.dispose());
|
|
53
|
-
e.
|
|
53
|
+
e.oe = e => {
|
|
54
54
|
read(n);
|
|
55
55
|
return r.track(e);
|
|
56
56
|
};
|
|
@@ -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.Pt = externalSourceConfig ? wireExternalSource : null;
|
|
68
|
+
GlobalQueue.ht = externalSourceConfig ? externalUntrack : null;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function enableExternalSource(e) {
|
package/dist/prod/core/graph.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONFIG_AUTO_DISPOSE,
|
|
1
|
+
import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
|
|
2
2
|
|
|
3
3
|
import { deleteFromHeap, queueFor } from "./heap.js";
|
|
4
4
|
|
|
@@ -8,36 +8,36 @@ import { bumpNotifyEpoch } from "./scheduler.js";
|
|
|
8
8
|
|
|
9
9
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
|
|
10
10
|
function unlinkSubs(e) {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
11
|
+
const n = e.ot;
|
|
12
|
+
const l = e.lt;
|
|
13
|
+
const o = e.ae;
|
|
14
|
+
const u = e.en;
|
|
15
|
+
if (o !== null) o.en = u; else n._t = u;
|
|
16
|
+
if (u !== null) u.ae = o; else {
|
|
17
|
+
n.u = o;
|
|
18
|
+
if (o === null) {
|
|
19
|
+
n.o?.Et?.();
|
|
20
20
|
// No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
|
|
21
21
|
// A pending node is exempt: its in-flight async work (or the
|
|
22
22
|
// transition holding it) is an observer — tearing down would orphan
|
|
23
23
|
// the work and re-execute it on the next read. The settle path runs
|
|
24
24
|
// this same last-one-out check when that observer releases (the
|
|
25
|
-
// untracked-read
|
|
26
|
-
const e =
|
|
27
|
-
e.
|
|
25
|
+
// untracked-read dormancy sweep guards on pending identically).
|
|
26
|
+
const e = n;
|
|
27
|
+
e.oe && e.T & CONFIG_AUTO_DISPOSE && !(e.ie & REACTIVE_ZOMBIE) && !(e.S & STATUS_PENDING) && unobserved(e);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
return
|
|
30
|
+
return l;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function trimStaleDeps(e) {
|
|
34
|
-
const
|
|
35
|
-
let
|
|
36
|
-
if (
|
|
34
|
+
const n = e.je;
|
|
35
|
+
let l = n !== null ? n.lt : e.ut;
|
|
36
|
+
if (l !== null) {
|
|
37
37
|
do {
|
|
38
|
-
|
|
39
|
-
} while (
|
|
40
|
-
if (
|
|
38
|
+
l = unlinkSubs(l);
|
|
39
|
+
} while (l !== null);
|
|
40
|
+
if (n !== null) n.lt = null; else e.ut = null;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -46,13 +46,13 @@ function trimStaleDeps(e) {
|
|
|
46
46
|
// and skipping early also avoids adding one (hidden-class churn) via the
|
|
47
47
|
// null-out below.
|
|
48
48
|
function clearDeps(e) {
|
|
49
|
-
let
|
|
50
|
-
if (!
|
|
49
|
+
let n = e.ut;
|
|
50
|
+
if (!n) return;
|
|
51
51
|
do {
|
|
52
|
-
|
|
53
|
-
} while (
|
|
54
|
-
e.
|
|
55
|
-
e.
|
|
52
|
+
n = unlinkSubs(n);
|
|
53
|
+
} while (n !== null);
|
|
54
|
+
e.ut = null;
|
|
55
|
+
e.je = null;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function unobserved(e) {
|
|
@@ -61,27 +61,63 @@ function unobserved(e) {
|
|
|
61
61
|
disposeChildren(e, true);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Deferred dormancy for never-observed auto-dispose computeds (#3078).
|
|
66
|
+
*
|
|
67
|
+
* An untracked top-level read of a subscriber-less observation-lifecycle memo
|
|
68
|
+
* used to call unobserved() inline at the end of read(). That kept the leak
|
|
69
|
+
* closed (the compute links the memo into its deps' sub lists — without a
|
|
70
|
+
* teardown point a never-observed memo is retained by its sources forever;
|
|
71
|
+
* upstream alien-signals has exactly this retention), but it made reads
|
|
72
|
+
* destructive: each read disposed the node, the next read revived it with a
|
|
73
|
+
* full recompute in whatever ambient transition/lane context happened to be
|
|
74
|
+
* current, so consecutive reads could return different answers with no write
|
|
75
|
+
* in between.
|
|
76
|
+
*
|
|
77
|
+
* Instead, reads queue the node here and the scheduler sweeps at the top of
|
|
78
|
+
* the next flush (before runHeap, so a same-tick dirtying is reclaimed
|
|
79
|
+
* instead of recomputed). Reads become idempotent within a tick (the node
|
|
80
|
+
* stays alive and serves its cache, uniform with observed memos) while
|
|
81
|
+
* reclamation still happens within one microtask — the enqueue site arms
|
|
82
|
+
* schedule(), so a flush is guaranteed even when no other work is queued.
|
|
83
|
+
*/ const dormantNodes = new Set;
|
|
84
|
+
|
|
85
|
+
function sweepDormant() {
|
|
86
|
+
if (dormantNodes.size === 0) return;
|
|
87
|
+
for (const e of dormantNodes) {
|
|
88
|
+
// Re-validate at sweep time: the node may have gained a subscriber (its
|
|
89
|
+
// lifecycle is the unlinkSubs cascade now), gone pending (in-flight async
|
|
90
|
+
// is an observer; the settle path re-runs last-one-out), lost its
|
|
91
|
+
// AUTO_DISPOSE bit (owner teardown strips it, #3024), or already been
|
|
92
|
+
// torn down.
|
|
93
|
+
if (!e.u && e.T & CONFIG_AUTO_DISPOSE && !(e.S & STATUS_PENDING) && !(e.ie & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
|
|
94
|
+
unobserved(e);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
dormantNodes.clear();
|
|
98
|
+
}
|
|
99
|
+
|
|
64
100
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L52
|
|
65
|
-
function link(e,
|
|
101
|
+
function link(e, n, l = false) {
|
|
66
102
|
// Repeat touches within one pass AND-combine `_pendingObserver`: a probe
|
|
67
103
|
// read (`isPending(() => x())`) beside a value read of the same dep must
|
|
68
104
|
// not relabel the value dependency as probe-only — the value read is what
|
|
69
105
|
// real-error propagation and affects() coverage key off, regardless of
|
|
70
106
|
// read order within the computation.
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
|
|
107
|
+
const o = n.je;
|
|
108
|
+
if (o !== null && o.ot === e) {
|
|
109
|
+
o.ve &&= l;
|
|
74
110
|
return;
|
|
75
111
|
}
|
|
76
|
-
let
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
112
|
+
let u = null;
|
|
113
|
+
const t = n.ie & REACTIVE_RECOMPUTING_DEPS;
|
|
114
|
+
if (t) {
|
|
115
|
+
u = o !== null ? o.lt : n.ut;
|
|
116
|
+
if (u !== null && u.ot === e) {
|
|
117
|
+
u.Ft = n.Ke;
|
|
118
|
+
n.je = u;
|
|
83
119
|
// First touch of this pass: the previous pass's label is stale.
|
|
84
|
-
|
|
120
|
+
u.ve = l;
|
|
85
121
|
return;
|
|
86
122
|
}
|
|
87
123
|
}
|
|
@@ -90,26 +126,26 @@ function link(e, l, n = false) {
|
|
|
90
126
|
// [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
|
|
91
127
|
// (the old alien-signals `isValidLink` walk, O(n²) when a computation
|
|
92
128
|
// re-reads earlier deps non-consecutively, e.g. store leaf reads).
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
129
|
+
const s = e._t;
|
|
130
|
+
if (s !== null && s.ce === n && (!t || s.Ft === n.Ke)) {
|
|
95
131
|
// Gen-matched during a recompute = repeat touch this pass (AND); outside
|
|
96
132
|
// a recompute there is no pass boundary, so the latest read labels it.
|
|
97
|
-
if (
|
|
133
|
+
if (t) s.ve &&= l; else s.ve = l;
|
|
98
134
|
return;
|
|
99
135
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
136
|
+
const r = n.je = e._t = {
|
|
137
|
+
ot: e,
|
|
138
|
+
ce: n,
|
|
139
|
+
lt: u,
|
|
140
|
+
en: s,
|
|
141
|
+
ae: null,
|
|
142
|
+
Ft: n.Ke,
|
|
143
|
+
ve: l
|
|
108
144
|
};
|
|
109
|
-
if (
|
|
110
|
-
if (
|
|
145
|
+
if (o !== null) o.lt = r; else n.ut = r;
|
|
146
|
+
if (s !== null) s.ae = r; else e.u = r;
|
|
111
147
|
// New subscriber edge: staged-rewrite skips (§12d) must not miss it.
|
|
112
148
|
bumpNotifyEpoch();
|
|
113
149
|
}
|
|
114
150
|
|
|
115
|
-
export { clearDeps, link, trimStaleDeps, unlinkSubs, unobserved };
|
|
151
|
+
export { clearDeps, dormantNodes, link, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };
|
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, EFFECT_TRACKED, EFFECT_USER, REACTIVE_RECOMPUTING_DEPS, REACTIVE_MANUAL_WRITE,
|
|
3
|
+
import { REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, EFFECT_TRACKED, EFFECT_USER, 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
|
|
|
@@ -13,29 +13,29 @@ import { zombieQueue, dirtyQueue } from "./scheduler.js";
|
|
|
13
13
|
* the heap and go directly to their effect queue; everything else is inserted
|
|
14
14
|
* into its own (zombie-flag-routed) heap with the `_min` cursor pulled down.
|
|
15
15
|
*/ function enqueueSub(e) {
|
|
16
|
-
if (e.
|
|
16
|
+
if (e.he === EFFECT_TRACKED) {
|
|
17
17
|
const E = e;
|
|
18
|
-
if (!E.
|
|
19
|
-
E.
|
|
20
|
-
E.C.enqueue(EFFECT_USER, E.
|
|
18
|
+
if (!E.tt) {
|
|
19
|
+
E.tt = true;
|
|
20
|
+
E.C.enqueue(EFFECT_USER, E.yt);
|
|
21
21
|
}
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
const E = queueFor(e);
|
|
25
|
-
if (E.
|
|
25
|
+
if (E.Qe > e.Me) E.Qe = e.Me;
|
|
26
26
|
insertIntoHeap(e, E);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function actualInsertIntoHeap(e, E) {
|
|
30
|
-
const t = (e.
|
|
31
|
-
if (t >= e.
|
|
32
|
-
const n = e.
|
|
30
|
+
const t = (e.ke?.Gt ? e.ke.Dt?.Me : e.ke?.Me) ?? -1;
|
|
31
|
+
if (t >= e.Me) e.Me = t + 1;
|
|
32
|
+
const n = e.Me;
|
|
33
33
|
const I = E.eE[n];
|
|
34
34
|
if (I === undefined) E.eE[n] = e; else {
|
|
35
|
-
const E = I.
|
|
36
|
-
E.
|
|
37
|
-
e.
|
|
38
|
-
I.
|
|
35
|
+
const E = I.ct;
|
|
36
|
+
E.rt = e;
|
|
37
|
+
e.ct = E;
|
|
38
|
+
I.ct = e;
|
|
39
39
|
}
|
|
40
40
|
if (n > E.EE) E.EE = n;
|
|
41
41
|
}
|
|
@@ -71,23 +71,23 @@ function deleteFromHeap(e, E) {
|
|
|
71
71
|
const t = e.ie;
|
|
72
72
|
if (!(t & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
|
|
73
73
|
e.ie = t & -25;
|
|
74
|
-
const n = e.
|
|
75
|
-
if (e.
|
|
76
|
-
const t = e.
|
|
74
|
+
const n = e.Me;
|
|
75
|
+
if (e.ct === e) E.eE[n] = undefined; else {
|
|
76
|
+
const t = e.rt;
|
|
77
77
|
const I = E.eE[n];
|
|
78
78
|
const o = t ?? I;
|
|
79
|
-
if (e === I) E.eE[n] = t; else e.
|
|
80
|
-
o.
|
|
79
|
+
if (e === I) E.eE[n] = t; else e.ct.rt = t;
|
|
80
|
+
o.ct = e.ct;
|
|
81
81
|
}
|
|
82
|
-
e.
|
|
83
|
-
e.
|
|
82
|
+
e.ct = e;
|
|
83
|
+
e.rt = undefined;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function markHeap(e) {
|
|
87
87
|
if (e.tE) return;
|
|
88
88
|
e.tE = true;
|
|
89
89
|
for (let E = 0; E <= e.EE; E++) {
|
|
90
|
-
for (let t = e.eE[E]; t !== undefined; t = t.
|
|
90
|
+
for (let t = e.eE[E]; t !== undefined; t = t.rt) {
|
|
91
91
|
if (t.ie & REACTIVE_IN_HEAP) markNode(t);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -97,16 +97,16 @@ function markNode(e, E = REACTIVE_DIRTY) {
|
|
|
97
97
|
const t = e.ie;
|
|
98
98
|
if ((t & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= E) return;
|
|
99
99
|
e.ie = t & -4 | E;
|
|
100
|
-
for (let E = e.u; E !== null; E = E.
|
|
101
|
-
markNode(E.
|
|
100
|
+
for (let E = e.u; E !== null; E = E.ae) {
|
|
101
|
+
markNode(E.ce, REACTIVE_CHECK);
|
|
102
102
|
}
|
|
103
103
|
// Firewall children (projection machinery only): gate the cold-extension
|
|
104
104
|
// deref on the config bit — markNode runs per sub edge per write, and an
|
|
105
105
|
// unconditional _x chase here taxed every propagation (diamond -22%).
|
|
106
106
|
if (e.T & CONFIG_FW_CHILDREN) {
|
|
107
|
-
for (let E = e.o.
|
|
108
|
-
for (let e = E.u; e !== null; e = e.
|
|
109
|
-
markNode(e.
|
|
107
|
+
for (let E = e.o.i; E !== null; E = E.Se) {
|
|
108
|
+
for (let e = E.u; e !== null; e = e.ae) {
|
|
109
|
+
markNode(e.ce, REACTIVE_CHECK);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -114,11 +114,11 @@ function markNode(e, E = REACTIVE_DIRTY) {
|
|
|
114
114
|
|
|
115
115
|
function runHeap(e, E) {
|
|
116
116
|
e.tE = false;
|
|
117
|
-
for (e.
|
|
118
|
-
let t = e.eE[e.
|
|
117
|
+
for (e.Qe = 0; e.Qe <= e.EE; e.Qe++) {
|
|
118
|
+
let t = e.eE[e.Qe];
|
|
119
119
|
while (t !== undefined) {
|
|
120
120
|
if (t.ie & REACTIVE_IN_HEAP) E(t); else adjustHeight(t, e);
|
|
121
|
-
t = e.eE[e.
|
|
121
|
+
t = e.eE[e.Qe];
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
e.EE = 0;
|
|
@@ -126,21 +126,21 @@ function runHeap(e, E) {
|
|
|
126
126
|
|
|
127
127
|
function adjustHeight(e, E) {
|
|
128
128
|
deleteFromHeap(e, E);
|
|
129
|
-
let t = e.
|
|
130
|
-
for (let E = e.
|
|
131
|
-
const e = E.
|
|
132
|
-
const n = e.
|
|
133
|
-
if (n.
|
|
129
|
+
let t = e.Me;
|
|
130
|
+
for (let E = e.ut; E; E = E.lt) {
|
|
131
|
+
const e = E.ot;
|
|
132
|
+
const n = e.st || e;
|
|
133
|
+
if (n.oe && n.Me >= t) t = n.Me + 1;
|
|
134
134
|
}
|
|
135
|
-
if (e.
|
|
136
|
-
e.
|
|
137
|
-
for (let E = e.u; E !== null; E = E.
|
|
135
|
+
if (e.Me !== t) {
|
|
136
|
+
e.Me = t;
|
|
137
|
+
for (let E = e.u; E !== null; E = E.ae) {
|
|
138
138
|
// Route each subscriber by its own zombie flag, mirroring the
|
|
139
139
|
// post-recompute height-adjust path. Inserting into the running `heap`
|
|
140
140
|
// unconditionally can park a zombie in `dirtyQueue` (or a live node in
|
|
141
141
|
// `zombieQueue`), breaking the flag/queue invariant `deleteFromHeap`
|
|
142
142
|
// relies on — the same corruption class as #2759.
|
|
143
|
-
insertIntoHeapHeight(E.
|
|
143
|
+
insertIntoHeapHeight(E.ce, queueFor(E.ce));
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
}
|