Make inference-family GenContext mutations honest (A6 phase 3)#210
Merged
Conversation
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
A6 phase 3 from
docs/MLIRGen-refactoring-review.md— the three genuinetypeParamsWithArgsmutations stop hiding behindconst_cast.processTypeArgumentsFromFunctionParametersandprocessConditionalForTypenow takeGenContext &: they genuinely return inferred type parameters to their callers. Both call sites already passed local non-const contexts (funcGenContextin specialized-function instantiation,condTypeGenContextingetConditionalType), so no ripple beyond the two signatures.getMappedTypekeys the mapped-type parameter into a local context copy instead of insert/erase on the caller's map. This also fixes a latent bug of exactly the kind the A6 plan predicted: theprocessKeyItemlambda's early returns (!type,NeverType) skipped theerase, leaking the key into the caller's map — and sinceStringMap::insertdoesn't overwrite, later iterations could silently resolve against the stale first key item. With the copy, the leak cannot escape the mapped-type resolution; within-loop behavior is unchanged.const_cast<GenContext&>census after this PR: 6 active sites in MLIRGen.cpp (thisType×2, loop flags ×3 sites… phase 2) +generatedStatements×4 +typeAliasMap×2 + 2 inMLIRCodeLogic.h(phase 4).Test plan
tslangrebuilt cleanly (vs2026 debug){ [K in keyof T]: T[K] }) and conditional types (T extends number ? … : …) through the changed code — JIT output3 y num trueas expectedMLIRGenTests.exe: 12/12 pass🤖 Generated with Claude Code