Document remaining const_cast sites as upward mailboxes; add A7 channel proposal#212
Merged
Merged
Conversation
…el proposal The 10 remaining const_cast<GenContext&> casts all intentionally write into the caller''s context so later code observes the value (field-init statement queue, safe-cast aliases, this-parameter type, dispose marker, switch-state arming). Copy-on-override cannot work for these and GenContext& would ripple through the whole statement chain; their correctness depends on value-copy visibility, which A7 in the review doc now explains, with a per-channel redesign proposal. Each site carries a greppable "NOTE: upward mailbox" comment. No code behavior change (comments and docs only). 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
Closes the mechanical portion of the A6
const_cast<GenContext&>effort and documents what's left. Comments and docs only — no behavior change.Investigating the final 10 casts (8 in MLIRGen.cpp, 2 in
MLIRCodeLogic.h) showed they are all upward mailboxes: they intentionally write into the caller's context so later code observes the value — the class-field-init statement queue (generatedStatementspush/drain), synthesized safe-cast aliases (typeAliasMap), the explicitthis: Tparameter type (mlirGenParameters), the dispose process-once marker (usingVars), and__switchstatearming variable-allocation placement for following statements. Copy-on-override cannot work for these,GenContext&signatures would ripple through the entire statement chain, and — the key finding — their correctness depends onGenContext's value-copy visibility semantics (a write is visible exactly to contexts copied from the mutated object after the write). The original phase-4 guess ("plain parameters") was wrong: those are out-channels too.NOTE: upward mailboxcomment pointing at the doc.docs/MLIRGen-refactoring-review.mdexplains the mechanism and proposes a per-channel redesign (pointer-shared channel object for the statement queue, per-function registry for safe-cast aliases, returned values instead of pokes formlirGenParameters/mlirGenSwitchState), one PR per channel, each needing review before implementation.Series scorecard for §3: 31 casts → 10, with every eliminated cast either provably semantics-free or a fixed latent leak, and every survivor documented.
Test plan
tslangrebuilds cleanly; smoke subset +MLIRGenTests.exe12/12 (comment-only change)🤖 Generated with Claude Code