mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
The LLVM emitter's constructor runs many analyses that each walk every function body to collect facts from a few node kinds. IrNodeIndex (ir/node-index.ts) walks the bodies once, before those analyses, and records each body's nodes in everyStmtList's order with a kind code per node and the kinds present per function. An analysis names the kinds it reads and receives exactly those nodes, in the same order, without recursing through the tree; a function the index does not hold (a rewritten copy) is walked as before. The index also lists the distinct type objects of the module, which the boxed-union and runtime-feature scans read instead of walking every expression's type tree. These read the index: walk borrows, appended array literals, constant callbacks and the rebinding census, int32 slots (dynamic field stores, call facts, the box census, candidate writes and the range walks), initializer bindings, stack observations, the may-throw call-graph census, published types and construction facts, final fields, stable globals, reference writes (private arrays, call targets, definitions, fresh constructors), boxed unions and runtime features. Analyses whose walks track their position (statement lists, nesting, ordered dataflow) keep their own walks. Callers outside the emitter pass no index and walk as before. The emitted LLVM IR is unchanged. packages/compiler/native/cli.profdata.gz is refreshed with scripts/refresh-cli-profile.mjs on this change, so the native compiler's optimization profile covers the rewritten analyses.