Skip to content

Commit 1866163

Browse files
ryansolidClaude via Cursorcursoragent
committed
S1 floor lever (a): the provisional re-derive's arms move to the lane engine
`laneStage` takes the provisional hold: it supersedes the staging when no lane seats the pass to the end (or it errored) and otherwise seats the staging as the lane's value, so `recompute`'s normal compare reads it; `adoptReaders` writes the re-derived value. The floor keeps the head arm, the local and the adopt call. Core floor 20,721 -> 20,599 B minified (core.js -85); engine scenarios +106 B (lanes.js +155). Signals suite green, shadow 0 classes (965,387 reads). Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent e5b6cf2 commit 1866163

4 files changed

Lines changed: 75 additions & 43 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
Reader seat S1: D-2's in-place re-derive (#4417) is judged by the lane engine — `laneStage` supersedes or seats a verdict reader's provisional staging as the lane's value, `adoptReaders` writes the re-derived value; `recompute` keeps only the head arm and the adopt call (core floor −122 B minified).

‎packages/signals/src/core/core.ts‎

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,12 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
540540
// A verdict reader's staging is D-2's provisional answer (it read
541541
// a staging of the flush that parked, as a verdict reader; this
542542
// pass is its one re-derive): kept as this pass's previous value
543-
// and judged at the tail — equal, and the pass the hold's verdict
544-
// reader, the readers that derived from it are the verdict lane's
545-
// with their frames (`adoptReadersHook`, #4417: a keyed Show mounts
546-
// once); else published mainline as below. (Only the verdict engine
547-
// stages one: without it the arm folds to the publish.)
543+
// and judged at the tail by the lane engine (`laneStage`): seated
544+
// in the hold's verdict lane, it is the lane's value — equal, the
545+
// readers that derived from it are the lane's with their frames
546+
// (`adoptReadersHook`, #4417: a keyed Show mounts once); else
547+
// superseded as below. (Only the verdict engine stages one: without
548+
// it the arm folds to the publish.)
548549
if (el._pendingValue !== NOT_PENDING) {
549550
if (verdictApplyHook !== null && el._config & CONFIG_VERDICT && !isEffect)
550551
provisional = tx;
@@ -815,19 +816,12 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
815816
// Listed before its staging, a pending pass included (the lane's own
816817
// flight is the lane's); false: the pass left the lane (lanes.ts).
817818
const errored = !!el._x?._error || stagedErr;
818-
// (The provisional staging, before `laneStage` voids the slot.)
819-
const staged = provisional !== null ? el._pendingValue : NOT_PENDING;
820-
if (laneStageHook && lane !== null) {
821-
if (laneStageHook(el, lane, create, errored)) setPassLane(lane);
822-
else lane = null;
823-
}
824-
// The provisional staging (above) of a pass that is not the hold's verdict
825-
// reader after all (no verdict lane seats it) is superseded as any other:
826-
// published mainline, its readers re-derive (#4378).
827-
if (provisional !== null && (lane === null || errored)) {
828-
insertSubs(el);
829-
el._pendingValue = NOT_PENDING;
830-
provisional = null;
819+
// (A provisional pass is the engine's to judge with or without a lane:
820+
// seated to the end, its staging is the lane's value — the slot this
821+
// pass compares against —; else superseded, its readers re-derive, #4378.)
822+
if (laneStageHook && (lane !== null || provisional !== null)) {
823+
if (laneStageHook(el, lane, create, errored, provisional)) setPassLane(lane!);
824+
else lane = provisional = null;
831825
}
832826

833827
if (!errored) {
@@ -850,16 +844,15 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
850844
// INV-11 (#3330): the equality gate compares against the slot this run
851845
// publishes to — the staged `_pendingValue` when staged; a lane node's
852846
// lane value (a node entering the lane this pass has none yet — its
853-
// committed value, `laneStage` having voided a frame staging).
854-
// (A provisional staging the pass re-derives is what it compares to.)
847+
// committed value, `laneStage` having voided a frame staging — or, a
848+
// provisional pass's, the staging it re-derives, seated as the lane's
849+
// value).
855850
const compareValue =
856-
provisional !== null
857-
? staged
858-
: el._pendingValue !== NOT_PENDING
859-
? el._pendingValue
860-
: el._config & CONFIG_OVERRIDE && el._x!._lane !== NOT_PENDING
861-
? el._x!._lane
862-
: el._value;
851+
el._pendingValue !== NOT_PENDING
852+
? el._pendingValue
853+
: el._config & CONFIG_OVERRIDE && el._x!._lane !== NOT_PENDING
854+
? el._x!._lane
855+
: el._value;
863856
// A throwing comparator is contained inside `isSame` (A3, #2837; #4111).
864857
// A pass replacing an error this node staged is a new answer, even the
865858
// committed value (D-41: a recovery equal to the last good value is a
@@ -1015,9 +1008,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
10151008
// the value is the lane's (as a changed one would be, above), and the
10161009
// readers that derived from the staging are the lane's with their
10171010
// frames, revealed at its seam instead of re-run (lanes.ts).
1018-
if (lane!._shown) el._pendingValue = value;
1019-
else el._x!._lane = value;
1020-
adoptReadersHook!(el, lane!, provisional);
1011+
adoptReadersHook!(el, lane!, provisional, value);
10211012
} else if (el._height != oldHeight) {
10221013
for (let s = el._subs; s !== null; s = s._nextSub) insertIntoHeapHeight(s._sub, dirtyQueue);
10231014
}

‎packages/signals/src/core/lanes.ts‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,26 @@ export function verdictLane(t: Transaction): Transaction {
389389
* not leave (A30: it never got there). A first pass under a lane is the
390390
* lane's (ruling A); a guess is written, not derived — it never leaves this
391391
* way. `errored`: the pass has no answer — or, a lane pass's pending
392-
* propagation (async.ts `propagateStatus`), the node gone pending. */
392+
* propagation (async.ts `propagateStatus`), the node gone pending.
393+
* `provisional`: the hold whose verdict reader's provisional staging this
394+
* pass re-derived (D-2, #4417; core.ts `recompute`'s head kept it as the
395+
* pass's previous value) — superseded here, its readers re-deriving
396+
* (#4378), unless the lane seats the pass to the end with an answer: then
397+
* the staging is the lane's value meanwhile — what the pass compares
398+
* against; the lane's at the seam if the value stands (`adoptReaders`),
399+
* replaced if not. `l` is null for a provisional pass no lane seats. */
393400
export function laneStage(
394401
el: Computed<any>,
395-
l: Transaction,
402+
l: Transaction | null,
396403
create: boolean,
397-
errored: boolean | Computed<any>
404+
errored: boolean | Computed<any>,
405+
provisional: Transaction | null = null
398406
): boolean {
407+
if (provisional !== null && (l === null || errored || !(el._flags & REACTIVE_LANE_READ))) {
408+
insertSubs(el);
409+
el._pendingValue = NOT_PENDING;
410+
}
411+
if (l === null) return false;
399412
if (!(create || errored || el._flags & REACTIVE_LANE_READ || el._config & CONFIG_GUESS)) {
400413
const x = el._x;
401414
if (x !== null) {
@@ -422,9 +435,17 @@ export function laneStage(
422435
}
423436
if (!(el as any)._type) {
424437
if (!(el._config & CONFIG_OVERRIDE)) {
438+
const staged = el._pendingValue;
425439
el._pendingValue = NOT_PENDING;
426440
el._config = (el._config & ~(CONFIG_HELD | CONFIG_HELD_FRAME)) | CONFIG_OVERRIDE;
427441
ext(el);
442+
// A provisional pass seated to the end: the staging is the lane's
443+
// value for now — in the lane's slot while the lane has not shown,
444+
// as a lane pass's would be (`recompute`), as its staging once it has.
445+
if (provisional !== null && !errored) {
446+
if (l._shown) el._pendingValue = staged;
447+
else el._x!._lane = staged;
448+
}
428449
}
429450
// A written guess whose own pass is the lane's work — its source is a
430451
// derivation of another guess (a guess over `config().courier` under a
@@ -1483,8 +1504,17 @@ const laneServed = (c: Computed<any>, el: Signal<any> | Computed<any>): void =>
14831504
* lane's to re-derive — it re-runs as today, as does every leaf (its run
14841505
* is the lane's; the one the park stashed with `t` is the frame's) and
14851506
* every reader with nothing staged. The notify is `insertSubs` +
1486-
* `laneDirty`'s, the adopted taken back out of the heap. */
1487-
function adoptReaders(el: Computed<any>, l: Transaction, t: Transaction): void {
1507+
* `laneDirty`'s, the adopted taken back out of the heap. `value`: the
1508+
* re-derived value — the lane's, as a changed one would be (`recompute`'s
1509+
* lane arm; `laneStage` seated the staging there meanwhile). */
1510+
function adoptReaders(el: Computed<any>, l: Transaction, t: Transaction, value: unknown): void {
1511+
if (l._shown) el._pendingValue = value;
1512+
else el._x!._lane = value;
1513+
adoptSubs(el, l, t);
1514+
}
1515+
/** The readers of `el` held by `t` that derived from its staging alone are
1516+
* the lane's with their frames, recursively (`adoptReaders`). */
1517+
function adoptSubs(el: Computed<any>, l: Transaction, t: Transaction): void {
14881518
insertSubs(el);
14891519
laneDirty(el, l);
14901520
for (let s = el._subs; s !== null; s = s._nextSub) {
@@ -1518,7 +1548,7 @@ function adoptReaders(el: Computed<any>, l: Transaction, t: Transaction): void {
15181548
r._pendingValue = NOT_PENDING;
15191549
}
15201550
adoptFrame(r, el, l);
1521-
adoptReaders(r, l, t);
1551+
adoptSubs(r, l, t);
15221552
}
15231553
}
15241554
/** Every source of `r` is `el`, the lane's, or neither held nor staged. */

‎packages/signals/src/core/scheduler.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ export let laneApplyHook:
8181
/** The lane slots served (lanes.ts `laneServe`): Lv, Dv, T, a fold. */
8282
export let laneServeHook: ((el: Signal<any> | Computed<any>, slot: number) => unknown) | null =
8383
null;
84+
/** A lane pass's node at its tail (lanes.ts `laneStage`); `provisional`: the
85+
* hold whose verdict reader's provisional staging this pass re-derived
86+
* (D-2, #4417) — `l` may be null then: no lane seats the pass. */
8487
export let laneStageHook:
8588
| ((
8689
el: Computed<any>,
87-
l: Transaction,
90+
l: Transaction | null,
8891
create: boolean,
89-
errored: boolean | Computed<any>
92+
errored: boolean | Computed<any>,
93+
provisional?: Transaction | null
9094
) => boolean)
9195
| null = null;
9296
export let laneOutcomeHook:
@@ -102,11 +106,13 @@ export let lanesBlockedHook: ((t: Transaction) => boolean) | null = null;
102106
* of a reader adopts the flight instead (true: adopted, nothing to queue). */
103107
export let laneAdoptHook: ((r: Computed<any>) => boolean) | null = null;
104108
/** D-2's re-derive in place (core.ts `recompute`, #4417): a verdict reader
105-
* re-derived the value it staged provisionally — the readers that derived
106-
* from the staging are adopted into the hold's verdict lane `l` with their
107-
* frames (lanes.ts `adoptReaders`). */
108-
export let adoptReadersHook: ((el: Computed<any>, l: Transaction, t: Transaction) => void) | null =
109-
null;
109+
* seated in the hold's verdict lane `l` re-derived the `value` it staged
110+
* provisionally under `t` — it is the lane's, and the readers that derived
111+
* from the staging are adopted into the lane with their frames (lanes.ts
112+
* `adoptReaders`). */
113+
export let adoptReadersHook:
114+
| ((el: Computed<any>, l: Transaction, t: Transaction, value: unknown) => void)
115+
| null = null;
110116
/** core.ts `frameRead` served lane work or a verdict reader a held node's
111117
* committed value (lanes.ts `laneServed`). */
112118
export let laneServedHook: ((c: Computed<any>, el: Signal<any> | Computed<any>) => void) | null =

0 commit comments

Comments
 (0)