Skip to content

[codegen/annotator] populate cache for declared-type params + decl scaffolding#654

Merged
cs01 merged 1 commit intomainfrom
annotator-declared-types
Apr 22, 2026
Merged

[codegen/annotator] populate cache for declared-type params + decl scaffolding#654
cs01 merged 1 commit intomainfrom
annotator-declared-types

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 22, 2026

Before

typeOf(expr) for variable expressions referring to function parameters falls through to resolveExpressionTypeRich, re-walking the symbol table on every consumer query. No scope tracking in the annotator walker.

After

Annotator walker tracks a scope stack populated from function parameters and let/const declarations. Parameter reads with concrete declared types (no unions, nullables, any, function types, etc.) populate the typeOf cache. Decl bindings are stored in scope but not yet cache-feeding — wired in Piece 3.

No user-facing behavior change. Infrastructure-only.

Description

Piece 1 of the annotator population program. See memory refactor-plan-stale-2026-04-21.md for why broad resolver memoization (Step 1 in the original plan, PR #571/#580) doesn't work — mid-codegen setResolvedType refinement poisons a naive cache. Annotator-pass approach instead.

Scope this PR:

  • New scope stack inside annotateTypes walker (src/semantic/type-annotator.ts).
  • isSafelyAnnotatable(typeStr) gate: rejects unions (|), optionals (?), any/unknown/void/never, function types (=>), intersections (&), inline object types ({).
  • resolveDeclaredTypeString sink on LLVMGenerator mirrors the gate, defense-in-depth.
  • Only param bindings feed the cache this PR. decl bindings are recorded but lookupParam filters them out — Piece 3 needs refinement-interaction logic before they're safe.

Gated by full npm run verify (stage 2 green).

Next Steps

Related: #640 (refactor tracker), #652, #653.

…affolding

piece 1 of annotator population program. extends type-annotator walker
with scope tracking for function parameters + let/const declarations.
param bindings feed typeOf cache when declared type is a safely-annotatable
single concrete shape (no unions, nullables, or any/unknown). decl bindings
are stored for piece 3 (nullable narrowing, #652) but not yet used.

adds resolveDeclaredTypeString sink on LLVMGenerator that rejects union
type strings up front.

no user-facing change. piece 3 (narrowing) lands the #652 fix on top.
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Place
Cold Start 1.4ms 0.8ms 1.2ms 27.6ms 🥇
Fibonacci 0.814s 0.762s 1.564s 3.195s 🥇
Hash Map Lookup 0.095s 0.063s 0.090s 0.109s 🥇
Binary Trees 1.377s 1.244s 2.704s 1.188s 🥈
File I/O 0.118s 0.093s 0.089s 0.203s 🥈
JSON Parse/Stringify 0.039s 0.052s 0.180s 0.134s 🥈
N-Body Simulation 1.666s 2.120s 2.199s 2.398s 🥈
Regex Match 0.016s 0.005s 0.021s 0.005s 🥈
SQLite 0.051s 0.366s 0.500s 0.407s 🥈
Monte Carlo Pi 0.388s 0.410s 0.404s 2.247s 🥉
Quicksort 0.215s 0.246s 0.213s 0.261s 🥉
Sieve of Eratosthenes 0.015s 0.028s 0.019s 0.040s 🥉
String Manipulation 0.008s 0.018s 0.017s 0.036s 🥉
Matrix Multiply 0.451s 0.737s 0.567s 0.432s #4

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.558s 0.920s 0.129s 🥈
Recursive Grep 0.020s 0.010s 0.104s 🥈

@cs01 cs01 merged commit c5d1c74 into main Apr 22, 2026
13 checks passed
@cs01 cs01 deleted the annotator-declared-types branch April 22, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant