Skip to content

Remove gratuitous const_cast<GenContext&> casts; legalize stop() (A6 phases 0–1)#209

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

Remove gratuitous const_cast<GenContext&> casts; legalize stop() (A6 phases 0–1)#209
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-constcast-p1p3

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

First implementation slice of the A6 plan (docs/MLIRGen-refactoring-review.md, §3): 11 of the 31 const_cast<GenContext &> casts removed with zero semantic change.

  • Phase 1 — stop() legalized. stopProcess is now mutable and stop() is const: it's an out-of-band cancellation signal, which is exactly what mutable is for. The internal const_cast<GenContext *>(rootContext) and both casting call sites disappear.
  • Phase 0 (discovered during the census) — nine casts were never mutations:
    • Six sites cast only to call non-const methods on the funcOp op 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. (setPersonalityAttr mutates 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.
    • getConditionalType cast a local, non-const GenContext.
  • Also removed a stale commented cast referencing a nonexistent funcOpVarScope field, 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

  • tslang rebuilt cleanly (header change rebuilds all dependent TUs)
  • All seven JIT smoke tests produce identical output
  • MLIRGenTests.exe: 12/12 pass

🤖 Generated with Claude Code

…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>
@ASDAlexander77 ASDAlexander77 merged commit 3c5af7f into main Jul 12, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/gencontext-constcast-p1p3 branch July 12, 2026 14:22
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