0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00

refactor(compiler): stage computePlacement

`computePlacement` was one 2,075-line closure whose phases shared ~100
locals; the fixed point called helpers declared 300-500 lines below it and
invalidated lazy memos by hand. It is now the composition of seven stages
in `placement/`, each a function of the data the previous ones produced:

- clusters.ts: union-find, the write table, ordered evaluation, the
  materialised clusters, the one mutation predicate (`mutatedOutside`) and
  the readers of mutable state (computed with the `ordered-effect`
  fallbacks in one pass over the eager reads, instead of a lazy memo)
- reads.ts: memoised reads and successors per output, `reach`
- roots.ts: the roots planners and the module declare, extraction
  candidates, provenance
- settle.ts: the env-roots / movable / extraction fixed point, helpers
  above the loop; the dev fold of extracted exports
- kept.ts: the kept declarations and their causes
- homes.ts: homes, the single-writer rule, env-declared roots
- inclusion.ts: inclusion, imports and exports

The union-find no longer leaves stage 1: a claimed region is in its
owner's cluster, so a writer's cluster is `clusterOfRegion` and every rule
compares cluster ids. The generated reads `importStays` asks about are
collected only in route modules, when asked.

No behaviour change: identical outputs, maps, edges and diagnostics over
the compiler-perf apps (14,216 outputs) and 5,000 fuzz-generated modules
(353,990 outputs). Micro-bench: -1.7 to -3.2 % per module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sheraff 2026-10-29 19:13:59 +01:00
commit 5e88a91c81
No known key found for this signature in database
8 changed files with 2602 additions and 2189 deletions