Repository navigation
feat(compiler): target 'lynx' — create-function template emission for the Lynx main thread (issue-58 L1) - #63
Conversation
…for the Lynx main thread The universal front-end and descriptor ABI are unchanged; eligible host-only plans lower to straight-line create functions plus a slot-kind table, the Lynx main-thread renderer executes them through a record-building env that reproduces the interpreted plan path's first-screen batch exactly, and ineligible plans keep the plan encoding. Renderer config bumps to v5. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
Huxpro
left a comment
There was a problem hiding this comment.
Reviewed the compiler backend and template env against the interpreted path. The core equivalences hold up: lynxTemplateEligible is conservative (props-program/key/ref/children/static-event-named props all fall back), the compiler's event-prop regex is byte-identical to the renderer's, static/dynamic text and slot holes lower to the same records, listener ordering matches, all emission goes through fresh @tsrx/core builders with no parsed-AST mutation, and the v4→v5 signature bump correctly invalidates transform caches. The differential suite pinning deep-equal batches between the two encodings is the right gate, and I verified it green locally along with the full lynx project (26 files / 342 tests) on the stack head.
Two inline findings (native-resource event values diverging from the interpreted path; template plan shape validation). One finding with no diff line to anchor on: compile-renderer-boundaries.js (~lines 814/851) was not extended with isUniversalFamilyTarget, so a boundary region whose child renderer is the main-thread renderer now falls through to the cannot lower "dom" -> "lynx" regions throw, where before the flip it lowered through the universal region path. It fails loudly and the benchmark app declares no boundaries, but it is inconsistent with the stated rule that every non-emission decision treats lynx exactly like universal (universal-runtime.js:5-9) — worth a follow-up or a note in the PR body.
The gzip regression (1.11–1.22× at module level) is honestly recorded as an accepted trade with the offset deferred to L3/L5; flagging that the lynx-bundle-size re-audit needs to actually happen before cutover so this doesn't silently compound.
Generated by Claude Code
…d template plan validation TEMPLATE_ENV.e now rejects native-resource event values with the same TypeError the interpreted path raises from hostNode, and freezePlanNode validates template plans (create function, slots array) at freeze time so malformed plans fail with a source-attributed diagnostic instead of an opaque mid-first-screen TypeError. Both pinned by parity tests that run the same descriptor through the plan and template encodings. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
f4c6617 to
c9190af
Compare
Counterexample to the #65 claim that `applyLynxFirstScreenDirect` leaves the container indistinguishable from `prepareLynxHostBatch` + `apply`. RED on this stack head. The staged applier validates host placement before mutating: a `#text` host under a non-text parent is refused with "#text host N may only be placed directly under a text host." The direct applier runs no equivalent check, so it paints the same tree — 2 instances against the staged path's 0. The refusal is what keeps an invalid tree away from the engine, so an applier that skips it is not substitutable for one that performs it. Reachable from authored `.tsrx`: the renderer rejects `<view>{text}</view>` at compile time ("does not allow authored primitive text under <view>"), but an explicit `children` prop is skipped by that attribute check and compiles clean, after which the renderer materializes the string into a `#text` host under the view. This sits entirely on the plan encoding — a `children` binding makes the template ineligible — so it is an applier-level divergence independent of #63. Asserts only that the two appliers agree, so either repair passes. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_015bSFKJDuqGJALcNAEiycA4
Summary
Stacked on the L0 PR (#59); first slice of #60 (L1 of the #58 roadmap). The compiler accepts
target: 'lynx'and emits the representation the L0 prototype measured — create functions + slot-kind tables for eligible host-only templates — while keeping the universal front-end, descriptor ABI, and behavior byte-identical.renderers.jsacceptstarget: 'lynx'(renderer config v5);compile.js/universal-runtime.js/bundler.jstreat it as universal-family everywhere except emission (isUniversalFamilyTarget).compile-universal.jslowers eligible plans (host/text/slot nodes only, no props program, statically classifiable prop names) into{kind:'template', slots, create(env, values)}— AST-built via@tsrx/corebuilders, copy-on-write, plan-origin locs preserved. Ineligible plans keep the interpreted plan encoding, so mixed modules stay correct.lynxMainThreadRendererflips totarget: 'lynx'(config.ts + config.runtime.js).main-renderer.tsexecutes create programs through a record-building first-screen env producing the exact sameUniversalHostBatch— ids, listener ids, props, events with priorities, visibility — asrenderPlanNode, so background adoption identity is untouched. Binding this env directly to PAPI is the L3 cutover (L3 (#58): main-thread slot-table applier + first-screen create-function codegen in @octanejs/lynx #62).universal-core.tsgains theUniversalTemplatePlantype and rejects template plans loudly in the generic core (they are main-thread-lynx artifacts).Why
The L0 measurement (see #59) put the win in eliminating the interpret → record graph → command batch → generic-apply pipeline, not the plan walk alone. This lands the compiler half of that representation with a behavior-identical runtime seam, validating the key L1 assumptions: the create-function form can express the corpus (with fallback), integrates with adoption identity unchanged, and is emitted at or below plan-encoding size raw/minified.
Validation
pnpm typecheck(clean)packages/octane/tests/lynx-target-templates.test.ts(octane + octane-prod projects): template-emitted and plan-emitted modules render deep-equal first-screen batches; red-green verified by deliberately breaking the env's event-priority handling. Review follow-ups added native-resource-event parity and template-plan freeze-validation cases.lynxproject with the flipped target: 25 files / 340 tests green.compiler-ast-emit-audit+compiler-ast-immutabilitygreen (builder/COW discipline).rspack-pluginproject green (v5 signature pin);rspeedy-pluginfailures (native-demoprocess-group case,packed-consumerarchive build) reproduce on the clean tree in this container — pre-existing, environmental.pnpm test(full repo run beyond the projects above not executed in-session)Size gate (fixture main-thread modules; esbuild minify, gzip -9)
Raw/minified meet the "≤ plan encoding" gate; gzip regresses 10–22% at module level because repeated JSON keys compress better than code (the slot table itself costs only ~28 gz bytes). Recorded as an accepted L1 trade in the spec §8 — the offset lands at L3/L5 when the plan interpreter and batch pipeline leave the main-thread bundle, re-audited against the
lynx-bundle-sizebudgets then. The re-audit is a hard pre-cutover gate so this trade cannot silently compound.Risk / follow-ups
target: 'lynx'compiler backend — create functions, slot tables, dual-graph emission #60.compile-renderer-boundaries.jsstill gates ontarget === 'universal', so a boundary region whose child is the lynx-target main-thread renderer fails loudly (cannot lower "dom" -> "lynx" regions) instead of lowering through the universal region path. No.lynx.tsrxcorpus module hosts a boundary region today; lowering into a lynx-target child needs its own region contract and is folded into L1 (#58):target: 'lynx'compiler backend — create functions, slot tables, dual-graph emission #60's scope.slotstables are emitted but unconsumed until the L2 delta protocol (L2 (#58): Lynx background core + typed slot-delta protocol (kernel-extraction spike first) #61).Provenance
agent-authored)