Repository navigation
fix(compiler): inline plain-module memos beside parent-printed syntax - #1577
Merged
Merged
Conversation
The production inline memo tier for plain .ts/.js hook modules bailed for
any module containing a template literal: canPrintProgram required an esrap
visitor for every node, but esrap prints TemplateElement (and SwitchCase,
CatchClause, import specifiers and attributes, overload signatures) from
the parent's visitor. Accept those types in the parent field that prints
them.
Widening the tier exposed esrap shapes that have a visitor but misprint:
`declare global`, cast assignment targets, a non-null assertion that
continues an optional chain, an empty `import type {}`, member modifier
order, and dropped type arguments or annotations. Keep those modules on
the surgical path, checking the Program as printed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)
99 other measured values are unchanged. |
trueadm
marked this pull request as ready for review
October 2, 2026 15:41
This was referenced Oct 3, 2026
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
…owering (#1634) Production builds of plain .ts/.js hook modules grew with #1546 (a withSlot boundary per local custom-hook call) and #1577 (the inline memo tier admitted ~99% of modules). This trims both without changing behavior: - hook-deps.js omits a module-declared hook's call boundary when the hook reads no slot (it calls nothing but useContext and other such hooks), or when it is the hook's only use, made directly by another local hook that is used only by name, outside any cycle of such calls. Signal-reading modules and `$` hooks keep every boundary. - memoSlot receives the hook name only for an authored slot, which a manual hook may leave undefined; a compiler-appended slot always resolves. - A plain-module memo dependency that is a never-reassigned local binding is read in place instead of through a temporary. Imports stay copied: they are live bindings the factory can change. - The inline tier's admission and print move into createPlainProgramPrinter, and a corpus test reprints every Octane module in packages/*/src through it, comparing TypeScript syntax trees and requiring TypeScript and esbuild to parse the output, so an esrap gap fails CI instead of shipping to production only. Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.ts/.jshook modules (inlinePlainHookMemos) silently fell back to the surgical path for any module with a template literal.canPrintProgramrequired an esrap visitor for every node, and esrap printsTemplateElementfrom theTemplateLiteralvisitor, so it has none.SwitchCase,CatchClause,ImportDefaultSpecifier,ImportNamespaceSpecifier,ImportAttribute, andTSDeclareMethod(overload signatures) failed the same way. Main admitted only 41% of parseable repo modules.TSTemplateLiteralType.quasisstays rejected because esrap 2.3 drops its final quasi.Why
Production client builds take this tier by default (
bundler.jsinlinePlainMemo). A binding module with a default import, aswitch, or a template literal lost the closure-free memo lowering without any signal.esrap misprints that the widened check must not admit (verified against esbuild and
tsc):declare global { … }declare global global {(ref.current as any) = v/(x as T)++/[(x as T) = 1] = ybox?.item!.label(box?.item!).labelimport type {} from './x'import './x'static override m()/protected abstract m()tag<T>\…`,{ m() {} },([a]: T[]) =>,extends Base+ line-broken{`Changes
packages/octane/src/compiler/plain-hook-memo.js:walkNodespasses(parent, field). APARENT_PRINTEDallowlist keys each child-only type to the fields that print it.misprints(node)covers the table above, andnonNullEndsChainfires only when a parenthesized!sits under a non-optional link with an optional link below it. The visitor check stays on the authored AST as before; the misprint check runs on the transformed Program right before the single print.tests/compiler/plain-hook-memo-codegen.test.ts: every parent-printed type takes the inline path (a source map is returned) and keeps its authored TypeScript syntax tree.tests/plain-hook-memo.test.ts: runtime behavior with inline on and off, both for a template-literal/switch/catch/namespace-import module (also pinning the tier) and forprops.box?.item!.labelshort-circuiting.benchmarks/hook-memo/plain-hooks.ts: slot Symbols now take template-literal descriptions, so the existingeligible_hit_*ratio guards cover this regression.docs/decallback-memo.md: what "unsupported printing shape" means.Audit
.ts/.jsmodule, then compare TypeScript syntax trees (parentheses unwrapped, optional-chain and type-only flags kept). Also require that both esbuild andtscparse the output.{ a: a }→{ a }andexport { default as default }→export { default }, which are equivalent..tsx/.jsx/.mjsnever reach this tier (plainHelperSource).Performance audit
benchmarks/hook-memowith the template-literal fixture, main vs this branch, inline variant. Values are per 32 dependency-hit renders; value/identity controls pass in both.plain_hook: function expressions 128 → 64, arrays 512 → 384.plain_explicit_slot: function expressions 192 → 64, arrays 640 → 384.packages/*/src,examples/*/src, andwebsite/src(589), throughcreateOctaneCompiler().transform.bundle-size/bundle-reachability, main vs this branch: 33 of 35 rows byte-identical; only the apollo-client binding moves (vite gzip +4 B, esbuild gzip −42 B).node benchmarks/bench.mjs --ratios hook-memobreaches 9 guards with or without this change (identical ratios). CI's bench job fails earlier at the Lynx diagnostic step, so it never sees them. Filed separately.Validation
plain-hook-memo-codegen.test.ts,plain-hook-memo.test.ts, everypackages/octane/testsfile that usesinlineHookMemo/slotHooks/createOctaneCompiler, andpackages/octane/tests/compiler: 137 files, 5,400 tests pass across octane and octane-prod.pnpm sync(no changes);pnpm format:files:checkandpnpm typecheck:fileson changed files. The codegen test file'sTS2531at theout!.mapline also exists on main, and CI typecheck excludespackages/octane/tests.pnpm test/pnpm typecheck/pnpm format:check(full): not completed locally. The machine was overloaded by concurrent sessions: the unsharded run hit an OOM, and the shard runs failed only on 5 s timeouts, where every file re-run in isolation passed. Local full runs were then stopped on request, so CI is the gate.Risk / follow-ups
hmr.test.tsandvolar.test.tsreproduce on main and do not touch this tier.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes production compile routing and esrap reprint eligibility for many hook modules; misprint detection is empirical, though known gaps are test-pinned and unsafe shapes stay on the surgical path.
Overview
Production plain
.ts/.jshook modules can take the inlineuseMemo/useCallbacktier even when the file uses syntax that esrap prints from a parent visitor—template literals,switch/try/catch, default or namespace imports, import attributes, and method overload signatures. Previously, missing per-node visitors forced the whole module onto the slower surgical path with no signal.The compiler now walks the AST with parent/field context, treats those child-only shapes as printable when they sit in the right parent slot, and adds a post-lowering fidelity gate (
misprints/printsFaithfully) so modules still fall back unchanged when esrap would rewrite behavior or types—e.g.declare global, emptyimport type {}, cast assignment targets, orbox?.item!.labeloptional-chain continuations.Docs, hook-memo benchmarks (template-literal slot symbols), and codegen/runtime tests lock in both the widened admission and the misprint guards.
Reviewed by Cursor Bugbot for commit bd1f6b7. Bugbot is set up for automated code reviews on this repo. Configure here.