Skip to content

feat(compiler): target 'lynx' — create-function template emission for the Lynx main thread (issue-58 L1) - #63

Merged
Huxpro merged 2 commits into
new-lynxfrom
claude/octane-issue-58-l1-lynx-target
Aug 19, 2026
Merged

Huxpro merged 2 commits into
new-lynxfrom
claude/octane-issue-58-l1-lynx-target

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 18, 2026 •

Copy link
Copy Markdown
Owner

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.js accepts target: 'lynx' (renderer config v5); compile.js / universal-runtime.js / bundler.js treat it as universal-family everywhere except emission (isUniversalFamilyTarget).
  • compile-universal.js lowers 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/core builders, copy-on-write, plan-origin locs preserved. Ineligible plans keep the interpreted plan encoding, so mixed modules stay correct.
  • lynxMainThreadRenderer flips to target: 'lynx' (config.ts + config.runtime.js). main-renderer.ts executes create programs through a record-building first-screen env producing the exact same UniversalHostBatch — ids, listener ids, props, events with priorities, visibility — as renderPlanNode, 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.ts gains the UniversalTemplatePlan type 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)
  • octane + octane-prod full projects: 835 files / 12,414 tests green
  • targeted tests:
    • new differential suite 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.
    • full lynx project with the flipped target: 25 files / 340 tests green.
    • full compiler suite: 37 files / 1158 tests green (renderer-config signature v4→v5 updated, new lynx-target acceptance/rejection cases added).
    • compiler-ast-emit-audit + compiler-ast-immutability green (builder/COW discipline).
    • rspack-plugin project green (v5 signature pin); rspeedy-plugin failures (native-demo process-group case, packed-consumer archive 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)

fixture plan raw/min/gz lynx raw/min/gz ratios
lynx-table 11776 / 5354 / 1480 10843 / 5161 / 1805 0.92 / 0.96 / 1.22
lynx-render 3381 / 1526 / 558 3377 / 1571 / 644 1.00 / 1.03 / 1.15
lynx-bundle-size 2405 / 1091 / 503 2477 / 1130 / 556 1.03 / 1.04 / 1.11

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-size budgets then. The re-audit is a hard pre-cutover gate so this trade cannot silently compound.

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

…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 Huxpro left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread packages/lynx/src/main-renderer.ts Resolved
Comment thread packages/lynx/src/main-renderer.ts Resolved
…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
@Huxpro
Huxpro force-pushed the claude/octane-issue-58-l1-lynx-target branch from f4c6617 to c9190af Compare August 18, 2026 16:07
Huxpro added a commit that referenced this pull request Aug 18, 2026
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
@Huxpro
Huxpro changed the base branch from claude/octane-issue-58-arch-j4ya6v to new-lynx August 19, 2026 17:12
@Huxpro
Huxpro marked this pull request as ready for review August 19, 2026 17:12
@Huxpro
Huxpro merged commit 0cec347 into new-lynx Aug 19, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants