[codegen/annotator] populate cache for declared-type params + decl scaffolding#654
Merged
[codegen/annotator] populate cache for declared-type params + decl scaffolding#654
Conversation
…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.
Contributor
Benchmark Results (Linux x86-64)
CLI Tool Benchmarks
|
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.
Before
typeOf(expr)forvariableexpressions referring to function parameters falls through toresolveExpressionTypeRich, 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 thetypeOfcache. 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.mdfor why broad resolver memoization (Step 1 in the original plan, PR #571/#580) doesn't work — mid-codegensetResolvedTyperefinement poisons a naive cache. Annotator-pass approach instead.Scope this PR:
annotateTypeswalker (src/semantic/type-annotator.ts).isSafelyAnnotatable(typeStr)gate: rejects unions (|), optionals (?),any/unknown/void/never, function types (=>), intersections (&), inline object types ({).resolveDeclaredTypeStringsink onLLVMGeneratormirrors the gate, defense-in-depth.parambindings feed the cache this PR.declbindings are recorded butlookupParamfilters them out — Piece 3 needs refinement-interaction logic before they're safe.Gated by full
npm run verify(stage 2 green).Next Steps
index_access— fixes [codegen/native] Array<Map<...>> element access loses concrete Map type → method dispatch fails #653 (arr[i]onMap<K,V>[]).if (x != null)narrowing, wire decl bindings into cache — fixes [codegen/native] Map<K, V> | null union loses .set/.get dispatch #652 (Map<K,V> | nulldispatch).Related: #640 (refactor tracker), #652, #653.