Remove gratuitous const_cast<GenContext&> casts; legalize stop() (A6 phases 0–1)#209
Merged
Merged
Conversation
…phases 0-1) - stop() is now const with mutable stopProcess - it is an out-of-band cancellation signal; the two casting call sites and the internal rootContext cast disappear - Nine casts were not mutations at all: non-const method calls on the copyable funcOp op handle (getSymName/getCallableResults/ getCallableRegion/setPersonalityAttr) now copy the handle; the inferTypes pointer deref never needed a cast (pointee is not const); getConditionalType cast a local non-const context - Review doc A6 updated with phase 0/1 status and the remaining census (all genuine mutations, for phases 2-4) 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
First implementation slice of the A6 plan (
docs/MLIRGen-refactoring-review.md, §3): 11 of the 31const_cast<GenContext &>casts removed with zero semantic change.stop()legalized.stopProcessis nowmutableandstop()isconst: it's an out-of-band cancellation signal, which is exactly whatmutableis for. The internalconst_cast<GenContext *>(rootContext)and both casting call sites disappear.funcOpop handle (getSymName,getCallableResults,getCallableRegion,setPersonalityAttr, debug print). MLIR op handles are cheap value types — copying the handle gives a non-const handle to the same operation, so these now copy instead of casting. (setPersonalityAttrmutates IR, not the context; behavior identical.)*(const_cast<GenContext &>(genContext).inferTypes)— the member is a pointer; reading it from a const context yields pointer-to-non-const already.getConditionalTypecast a local, non-constGenContext.funcOpVarScopefield, and updated A6 in the review doc with the phase 0/1 status and remaining census — everything left (thisType,typeAliasMap, loop flags,generatedStatements,typeParamsWithArgs,MLIRCodeLogic.h) is a genuine mutation for phases 2–4.Test plan
tslangrebuilt cleanly (header change rebuilds all dependent TUs)MLIRGenTests.exe: 12/12 pass🤖 Generated with Claude Code