Skip to content

Make inference-family GenContext mutations honest (A6 phase 3)#210

Merged
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-constcast-p3
Jul 12, 2026
Merged

Make inference-family GenContext mutations honest (A6 phase 3)#210
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-constcast-p3

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

A6 phase 3 from docs/MLIRGen-refactoring-review.md — the three genuine typeParamsWithArgs mutations stop hiding behind const_cast.

  • processTypeArgumentsFromFunctionParameters and processConditionalForType now take GenContext &: they genuinely return inferred type parameters to their callers. Both call sites already passed local non-const contexts (funcGenContext in specialized-function instantiation, condTypeGenContext in getConditionalType), so no ripple beyond the two signatures.
  • getMappedType keys 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: the processKeyItem lambda's early returns (!type, NeverType) skipped the erase, leaking the key into the caller's map — and since StringMap::insert doesn'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 in MLIRCodeLogic.h (phase 4).

Test plan

  • tslang rebuilt cleanly (vs2026 debug)
  • New smoke test driving mapped types ({ [K in keyof T]: T[K] }) and conditional types (T extends number ? … : …) through the changed code — JIT output 3 y num true as expected
  • All seven prior smoke tests identical
  • MLIRGenTests.exe: 12/12 pass

🤖 Generated with Claude Code

@ASDAlexander77 ASDAlexander77 merged commit 836b018 into main Jul 12, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/gencontext-constcast-p3 branch July 12, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant