refactor(type-inference): memoize resolveExpressionTypeRich at the boundary#571
Merged
refactor(type-inference): memoize resolveExpressionTypeRich at the boundary#571
Conversation
…undary via parallel-array cache
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.
What changed for users
Compiler now caches type-resolution results per AST expression node. Today this is a wash (existing call sites don't repeat-query), but it unblocks the upcoming TypedAST annotator pass — which previously hung stage 2 self-compile because eager use of the unmemoized resolver was O(N^2).
Details
TypeInference.resolveExpressionTypeRich, keyed by AST expression reference identity. Chose parallel arrays overMap<object, ResolvedType>because native ChadScript'sMapdoesn't support object keys (a minimal repro segfaults). The previously-dormantLLVMGenerator.typeCache(PR feat(codegen): phase E substrate — ctx.typeOf() type cache #540) had this same latent bug; consolidated it away.new, array/map/set, object). Skipped forvariable/member_access/index_access/call/method_callbecause those resolve through the symbol table, which is refined mid-codegen by variable-allocator and friends — caching them could freeze an early, less-specific answer.LLVMGenerator.typeOf()now delegates to the inner cache, removing the duplicate Map.Test plan
npm run verify(full, including stage 2 self-host) green locallynpm run format:checkcleanCHAD_DEBUG_RESOLVER_CACHEinstrumentation during development (removed before commit)