Skip to content

Commit a1348b1

Browse files
ryansolidClaude via Cursorcursoragent
committed
signals: S1 floor lever (b) — plain rows fire their mechanisms directly
The plain rows of the slot table (seat.ts plainRows) fire the join, the staging read, the stale reader, the late linker and the link themselves and return the slot alone; the packed-result convention stays with the engine rows, whose applier moves to lanes.ts (applyMarks, reached from readSlow through applyMarksHook) so an engine-less build retains neither. The hydration claim becomes a table slot (claim / SLOT_SNAPSHOT): the plain rows decide it before firing a staging's mechanisms, seatRows masks an engine row's packed raise to what fired before the snapshot (preSnapshotBits). snapshotCaptureActive lives in scheduler.ts, ahead of seat.ts in the bundle, so a build without hydration folds the claim arms. Core floor 20,599 → 20,411 min (−188); engine scenarios +110..+278 (the claim arms and the applier's relocation). Shadow: 0 classes across signals/solid/web and the 2k × 3 generator; ASYNC_GEN_DIFF: only the two known closed cases. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 1866163 commit a1348b1

7 files changed

Lines changed: 298 additions & 184 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, floor lever (b): the plain rows of the slot table fire their mechanisms directly (the join, the staging read, the stale reader, the late linker, the link) and return the slot alone; the packed-result convention and its applier stay with the engine rows (lanes.ts `applyMarks`). The hydration claim is a table slot (`claim`, `SLOT_SNAPSHOT`), and `snapshotCaptureActive` moves to the scheduler module so a build without hydration folds the claim arms. No public API change.

‎packages/signals/docs/RULES-INDEX.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
381381
| §1 | live | `docs/INTERNALS-STORE-STATE.md:27` | seat.ts×1 target.ts×1 | reveal-gating-contract.test.ts×1 | Storage model (the single-home rule) |
382382
| §2 | live | `docs/INTERNALS-STORE-STATE.md:81` | — | — | Read paths |
383383
| §3 | live | `docs/INTERNALS-STORE-STATE.md:116` | core.ts×2 optimistic.ts×1 reconcile.ts×1 store.ts×2 | seat-shadow-report.ts×1 | Write paths (all must stay equivalent) |
384-
| §4 | live | `docs/INTERNALS-STORE-STATE.md:200` | seat.ts×3 | seat-shadow-report.ts×1 | Identity rules |
384+
| §4 | live | `docs/INTERNALS-STORE-STATE.md:200` | seat.ts×4 | seat-shadow-report.ts×1 | Identity rules |
385385
| §5 | live | `docs/INTERNALS-STORE-STATE.md:221` | seat-oracle.ts×1 store.ts×1 target.ts×1 | — | Laziness invariants (candidates for `__TEST__` assertions) |
386386
| §5b | live | `docs/INTERNALS-STORE-STATE.md:239` | target.ts×2 | — | Creation budget (phase-1 fitness) |
387387
| §5c | live | `docs/INTERNALS-STORE-STATE.md:258` | — | — | Comparison method (shipped vs rewrite) |

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

Lines changed: 48 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,12 @@ import { cleanup, disposeChildren, inheritId, linkChild, markDisposal } from "./
106106
// The reader seat's shadow (S0): reachable only under `__TEST__`
107107
// (documentation/plans/reader-seat-rebuild.md §3).
108108
import {
109-
LANE_BITS,
110109
MARK_LATE,
111-
MARK_LINK,
112-
MARK_SERVED,
113-
MARK_ST,
114-
MARK_UNANS,
115110
MARK_W,
116111
RAISE_FL,
117112
RAISE_H,
118113
RAISE_HAT,
119114
RAISE_MASK,
120-
SLOT_C,
121115
SLOT_DV,
122116
SLOT_E,
123117
SLOT_ESHOWN,
@@ -133,16 +127,14 @@ import {
133127
SLOT_SNAPSHOT,
134128
SLOT_STASH,
135129
SLOT_T,
136-
VERDICT_BITS,
137130
SEAT_BORN_H,
138131
SEAT_OWN_FL,
139132
SEAT_OWN_H,
140133
SEAT_TX_H,
141134
bornInto,
142135
childBorn,
136+
noteFired,
143137
raiseSeatWorld,
144-
seatLane,
145-
seatTx,
146138
seatWorld,
147139
setSeatWorld,
148140
worldLevel,
@@ -175,6 +167,8 @@ import {
175167
queuePendingNode,
176168
schedule,
177169
setPassLane,
170+
setSnapshotCaptureActive,
171+
snapshotCaptureActive,
178172
txOf,
179173
inEffectCallback,
180174
effectCallbackEvent,
@@ -188,13 +182,12 @@ import {
188182
externalUntrackHook,
189183
freshHook,
190184
guessing,
191-
laneApplyHook,
192185
laneOutcomeHook,
186+
applyMarksHook,
193187
laneServeHook,
194188
adoptReadersHook,
195189
laneStageHook,
196190
laneSeamsHook,
197-
laneServedHook,
198191
holdWorkHook,
199192
laneWriteHook,
200193
verdictApplyHook,
@@ -301,7 +294,7 @@ export function setContextInternal(v: Owner | null): void {
301294
export let stale = false;
302295
export let context: Owner | null = null;
303296

304-
export let snapshotCaptureActive = false;
297+
export { snapshotCaptureActive };
305298
/** The lane at the root of the running chain of first passes: the lane whose
306299
* pass created the chain's first node (a mount), inherited by every first
307300
* pass nested under it, whose seats are mainline (`recompute`, #4166). */
@@ -316,8 +309,27 @@ function ownerInSnapshotScope(owner: Owner | null): boolean {
316309
return false;
317310
}
318311

312+
/** A hydration claim's read (`SLOT_SNAPSHOT`): a reader in a snapshot scope,
313+
* of a node the server rendered a value for, not errored, is served that
314+
* value — a client write's recompute still in flight does not pull the
315+
* claim off the markup it adopts; the reader replays at the scope's
316+
* release. (The callers guard with `snapshotCaptureActive` so a build
317+
* without hydration folds the arms.) Of the row's mechanisms only those the old deciders fired
318+
* before the snapshot fire: the hold arms (H, ST — a lane's enter bits,
319+
* the engine's); nothing of the staging's or the flight's. Not a lane's
320+
* value served (the engine's rows decide that first). */
321+
export function claim(c: Computed<any> | null, el: Signal<any> | Computed<any>): boolean {
322+
return (
323+
c !== null &&
324+
snapshotCaptureActive &&
325+
(c._config & CONFIG_IN_SNAPSHOT_SCOPE) !== 0 &&
326+
!((el as Computed<any>)._statusFlags & STATUS_ERROR) &&
327+
el._x?._snapshotValue !== undefined
328+
);
329+
}
330+
319331
export function setSnapshotCapture(active: boolean): void {
320-
snapshotCaptureActive = active;
332+
setSnapshotCaptureActive(active);
321333
if (active && !snapshotSources) snapshotSources = new NewSet();
322334
}
323335

@@ -380,7 +392,7 @@ export function clearSnapshots(): void {
380392
}
381393
snapshotSources = null;
382394
}
383-
snapshotCaptureActive = false;
395+
setSnapshotCaptureActive(false);
384396
}
385397

386398
export function recompute(el: Computed<any>, create: boolean = false): void {
@@ -1309,6 +1321,7 @@ export function joinPass(c: Computed<any>, el: Signal<any> | Computed<any>): voi
13091321
// The running pass's world is the hold's now (seat.ts `seatWorld`; not
13101322
// an idle owner a `runWithOwner` reads under).
13111323
if (c._flags & REACTIVE_RECOMPUTING_DEPS) raiseSeatWorld(SEAT_OWN_H);
1324+
if (__TEST__) noteFired(RAISE_H);
13121325
if (__TEST__) shadowExternalRaise(c, RAISE_H);
13131326
// A new memo's first pass is the hold's work (born held) but not the
13141327
// tick's: a render effect that reads it decides — under a boundary that
@@ -1330,6 +1343,7 @@ export function joinPass(c: Computed<any>, el: Signal<any> | Computed<any>): voi
13301343
export function joinPassAt(c: Computed<any>, t: Transaction): void {
13311344
c._flags |= REACTIVE_JOINED;
13321345
if (c._flags & REACTIVE_RECOMPUTING_DEPS) raiseSeatWorld(SEAT_OWN_H);
1346+
if (__TEST__) noteFired(RAISE_H | RAISE_HAT);
13331347
if (__TEST__) shadowExternalRaise(c, RAISE_H | RAISE_HAT);
13341348
joinPassTx(t, (!(c as any)._type && c._statusFlags & STATUS_UNINITIALIZED) || freshHook?.(c));
13351349
}
@@ -1890,6 +1904,7 @@ export function markLateLinker(c: Computed<any>): true {
18901904
// The pass's own tail re-enqueues on this latch (recompute's finally) —
18911905
// a direct enqueue here would be wiped by the pass's flag reset.
18921906
c._flags |= REACTIVE_MISSED_WAKE;
1907+
if (__TEST__) noteFired(MARK_LATE);
18931908
return true;
18941909
}
18951910

@@ -2008,21 +2023,11 @@ function laneSlot(s: number): boolean {
20082023
return s === SLOT_LV || s === SLOT_DV || s === SLOT_T || s === SLOT_FOLD;
20092024
}
20102025

2011-
/** The raise bits the old deciders applied before the hydration snapshot
2012-
* served a reader in a snapshot scope: the hold arms (`frameRead`,
2013-
* `joinPass`) and the lane read; everything after the snapshot (the
2014-
* staging's, the flight's) did not run. */
2015-
function preSnapshotBits(cfg: number): number {
2016-
return cfg & CONFIG_OVERRIDE
2017-
? LANE_BITS | RAISE_FL | MARK_W
2018-
: cfg & CONFIG_HELD
2019-
? RAISE_H | MARK_ST | MARK_SERVED
2020-
: 0;
2021-
}
2022-
20232026
/** `read`'s decision and its application, for every node the fast path
2024-
* does not serve: the table decides (seat.ts `slot`), the marks are applied
2025-
* (`applyMarks`), the slot is served. */
2027+
* does not serve: the table decides (seat.ts `slot`) — the plain rows fire
2028+
* their mechanisms as they decide; an engine row's packed raise is applied
2029+
* by the engine (lanes.ts `applyMarks`, `applyMarksHook`) — and the slot
2030+
* is served. */
20262031
function readSlow(el: Signal<any> | Computed<any>, c: Computed<any> | null): unknown {
20272032
const owner = el as Computed<any>;
20282033
if (__DEV__ && strictRead && owner._statusFlags & STATUS_PENDING && strictReadActive())
@@ -2031,7 +2036,7 @@ function readSlow(el: Signal<any> | Computed<any>, c: Computed<any> | null): unk
20312036
ownerName: (c as any)?._name,
20322037
nodeName: (owner as any)?._name
20332038
});
2034-
let r = slot(c, el, tracking, spectating);
2039+
const r = slot(c, el, tracking, spectating);
20352040
const s = r & SLOT_MASK;
20362041
// A component body's direct read is wrong in the same way whether the
20372042
// pass is hydrating or not, and the hydration pass is the console nobody
@@ -2042,35 +2047,20 @@ function readSlow(el: Signal<any> | Computed<any>, c: Computed<any> | null): unk
20422047
ownerName: (c as any)?._name,
20432048
nodeName: (owner as any)?._name
20442049
});
2045-
// A reader in a snapshot scope (a hydration claim) is served the value the
2046-
// server rendered with: a client write's recompute still in flight does
2047-
// not pull the claim off the markup it adopts — the reader replays at the
2048-
// scope's release. An errored node throws as for any reader; a lane's
2049-
// value served is the lane's.
2050-
let snapshot: unknown;
2051-
if (
2052-
snapshotCaptureActive &&
2053-
c !== null &&
2054-
c._config & CONFIG_IN_SNAPSHOT_SCOPE &&
2055-
!laneSlot(s) &&
2056-
(snapshot = el._x?._snapshotValue) !== undefined &&
2057-
!(owner._statusFlags & STATUS_ERROR)
2058-
) {
2059-
r = (r & preSnapshotBits(el._config)) | SLOT_SNAPSHOT;
2060-
if (__TEST__) shadowDecided(c, el, tracking, 0, spectating, r);
2061-
if (r & RAISE_MASK) applyMarks(c, el, r);
2062-
if (__TEST__) shadowActual(SLOT_SNAPSHOT);
2063-
const value = snapshot === NO_SNAPSHOT ? undefined : snapshot;
2064-
const current = el._pendingValue !== NOT_PENDING ? el._pendingValue : el._value;
2065-
if (current !== value) c._flags |= REACTIVE_SNAPSHOT_STALE;
2066-
return value;
2067-
}
20682050
if (__TEST__) shadowDecided(c, el, tracking, 0, spectating, r);
2069-
if (c !== null && r & RAISE_MASK) applyMarks(c, el, r);
2051+
if (applyMarksHook !== null && c !== null && r & RAISE_MASK) applyMarksHook(c, el, r);
20702052
if (__TEST__) shadowActual(s);
20712053
let value: unknown;
20722054
if (laneServeHook !== null && laneSlot(s)) value = laneServeHook(el, s);
2073-
else
2055+
else if (snapshotCaptureActive && s === SLOT_SNAPSHOT) {
2056+
// A hydration claim (`claim`): the value the server rendered with; the
2057+
// reader replays at the scope's release if the node has moved on. (The
2058+
// guard is what lets a bundle without hydration fold the arm.)
2059+
const sv = el._x!._snapshotValue;
2060+
value = sv === NO_SNAPSHOT ? undefined : sv;
2061+
const current = el._pendingValue !== NOT_PENDING ? el._pendingValue : el._value;
2062+
if (current !== value) c!._flags |= REACTIVE_SNAPSHOT_STALE;
2063+
} else
20742064
switch (s) {
20752065
case SLOT_P:
20762066
value = el._pendingValue;
@@ -2118,40 +2108,6 @@ function dormant(el: Computed<unknown>): void {
21182108
schedule();
21192109
}
21202110

2121-
/**
2122-
* The mechanisms a row of the table fires, applied to the reader `c`
2123-
* (seat.ts: the RAISE_* / MARK_* bits of `r`, with `seatTx` / `seatLane`
2124-
* naming the hold and the lane). The lane engine's bits go to it
2125-
* (`laneApplyHook`) and the verdict engine's to it (`verdictApplyHook`)
2126-
* first: a lane read moves the seat before the pass's world is raised, and
2127-
* a verdict read opens the flush's transaction before the hold is named.
2128-
* Then, in the order the old deciders fired them: the join (H; `joinPassAt`
2129-
* into the hold named when RAISE_HAT), the staging read (Fl), the
2130-
* unanswered probe, the seam watch (W), the stale reader (ST), the flight
2131-
* no longer waited on (`laneServed`), the late linker, the link of a
2132-
* throwing untracked read.
2133-
*/
2134-
export function applyMarks(c: Computed<any>, el: Signal<any> | Computed<any>, r: number): void {
2135-
// (Each engine's bits arise only from its rows: a build without the engine
2136-
// folds the guarded line.)
2137-
if (laneApplyHook !== null && r & LANE_BITS) laneApplyHook(c, r, seatLane);
2138-
if (verdictApplyHook !== null && r & VERDICT_BITS) verdictApplyHook(c, el, r, seatTx);
2139-
if (r & RAISE_H) {
2140-
if (r & RAISE_HAT) joinPassAt(c, seatTx!);
2141-
else joinPass(c, el);
2142-
}
2143-
if (r & RAISE_FL) {
2144-
c._flags |= REACTIVE_STAGED_READ;
2145-
if (c._flags & REACTIVE_RECOMPUTING_DEPS) raiseSeatWorld(SEAT_OWN_FL);
2146-
}
2147-
if (verdictApplyHook !== null && r & MARK_UNANS) c._flags |= REACTIVE_PROBE_UNANSWERED;
2148-
if (laneSeamsHook !== null && r & MARK_W) stagedReaders.push(c);
2149-
if (r & MARK_ST) staleReader(c, seatTx ?? flushTransaction!);
2150-
if (laneServedHook !== null && r & MARK_SERVED) laneServedHook(c, el);
2151-
if (r & MARK_LATE) markLateLinker(c);
2152-
if (r & MARK_LINK) link(el, c);
2153-
}
2154-
21552111
/** Shadow (S1, `seat.ts`): run `read` once for real and compare the slot it
21562112
* served with the table's prediction recorded at the decision point. A
21572113
* throw is a slot too: NotReady is NR, anything else E. */
@@ -2191,15 +2147,18 @@ export function stagedRead(c: Computed<any>, el?: Signal<any> | Computed<any>):
21912147
if (!((el as Computed<any> | undefined)?._statusFlags! & STATUS_UNINITIALIZED)) {
21922148
c._flags |= REACTIVE_STAGED_READ;
21932149
if (c._flags & REACTIVE_RECOMPUTING_DEPS) raiseSeatWorld(SEAT_OWN_FL);
2150+
if (__TEST__) noteFired(RAISE_FL);
21942151
if (__TEST__) shadowExternalRaise(c, RAISE_FL);
21952152
// A verdict reader's too when it is an effect, before the frame has a
21962153
// transaction (after, `stagedScreen` serves it the screen): the staging
21972154
// is the frame's read, and the pass re-derives once as a verdict reader
21982155
// if the flush parks (D-22; D-25: the probe decides the posture in either
21992156
// read order). A memo's is the frame's derivation either way: a memo is
22002157
// not a leaf.
2201-
if (laneSeamsHook && (passLane !== null || ((c as any)._type && c._config & CONFIG_VERDICT)))
2158+
if (laneSeamsHook && (passLane !== null || ((c as any)._type && c._config & CONFIG_VERDICT))) {
2159+
if (__TEST__) noteFired(MARK_W);
22022160
stagedReaders.push(c);
2161+
}
22032162
}
22042163
}
22052164

0 commit comments

Comments
 (0)