enable ast type-annotator pass (phase-e step 5, pr1)#573
Merged
Conversation
…) cache pre-codegen; parallel-array storage avoids native map<object,v> segv
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.
Summary
Enables the pre-codegen AST type-annotator pass introduced (but disabled) in the phase-e scaffolding. The annotator walks every expression in the AST once, resolves its type via the memoized
TypeInference.resolveExpressionTypeRich, and stores the result in an expression-keyed cache. Codegen consumers can now read canonical types viactx.typeOf(expr)instead of re-deriving from stringly-typed LLVM value names.This PR is purely additive: it populates the cache. No codegen consumer reads from it yet. Consumer migrations land in follow-up PRs, one site at a time.
Why users benefit
Foundations work that retires whole classes of silent-wrong bugs. Today different codegen sites disagree about an expression's type because each re-derives it from whatever happens to be in scope; the annotator makes type info authoritative and shared.
Key changes
src/semantic/type-annotator.ts— new file. Post-order walker over the full AST, callssink.resolveExpressionTypeRichthensink.appendExpressionType. Skips expressions withunknownbase (resolver gaps remain on-demand for now).BaseGenerator/IGeneratorContext— replacedexpressionTypes: Map<Expression, ResolvedType>with parallel arraysexpressionTypeNodes/expressionTypeValues. Native self-hosted Map lacks pointer-identity hashing (segfaults — seenative-map-object-key-unsupported.md); linear-scan is mandatory until that's fixed.expressionType*arrays are NOT cleared inreset()— they're keyed by AST identity which outlives per-function state.appendExpressionTypefast-path skips dedup for the annotator, which guarantees each node is visited once.typeOf()now reads the parallel-array cache first, falls back to on-demand resolution for unknown/missing-base expressions.Test plan
npm run verify(full, stage 2 included) green locally.Follow-ups (not in this PR)
getVariableType(valueName)totypeOf(expr)to prove the pattern.