Decompose 304-line inferType into per-template-kind helpers#207
Merged
Conversation
inferType was a chain of template-kind blocks, each ending in return. Each kind is now a tryInfer* helper returning true when handled: tryInferNamedGeneric, tryInferClass, tryInferInterface, tryInferArray, tryInferTuple (shared field walk via template helper), tryInferOptional, tryInferFunction, tryInferUnion. The conditional-type and typeref tail stays in the driver because the conditional block intentionally leaves its false branch for the typeref check. Bodies moved verbatim; driver is now a readable dispatch list. Review doc item (section 5). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Third §5 item (giant-method decomposition) from
docs/MLIRGen-refactoring-review.md, following the pattern of #205/#206.inferTypewas a chain of template-type-kind blocks, each ending inreturn. Each kind is now atryInfer*helper returningtruewhen the kind matched and inference was handled,falseto continue the chain — which preserves the original fall-through behavior exactly (e.g. a class template whose class info isn't registered falls through, a function template with zero params falls through):tryInferNamedGeneric→tryInferClass→tryInferInterface→tryInferArray→tryInferTuple(tuple/const-tuple field walk shared via a small template helper) →tryInferOptional→tryInferFunction→tryInferUnion.The conditional-type + typeref tail stays in the driver: the original conditional block intentionally leaves
currentTemplateTypepointing at the false branch, which the typeref check then examines — that coupling is now spelled out in a comment instead of being an accident of shared mutable locals.Bodies moved verbatim; the driver reads as a dispatch list with the two-step tail.
Test plan
tslangrebuilt cleanly (vs2026 debug)first<T>(T[])), function parameter and return types (apply<T, R>), tuples (pairFirst<A, B>([A, B])), and optional parameters (orDefault<T>(v?: T)) — JIT output10 42 7 false trueas expectedMLIRGenTests.exe: 12/12 pass🤖 Generated with Claude Code