Decompose 590-line cast() into named pipeline stages#205
Merged
Conversation
This was referenced Jul 12, 2026
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
Implements the first §5 item (giant-method decomposition) from
docs/MLIRGen-refactoring-review.md.cast()(590 lines) is a sequential pipeline, not a pure type dispatch — several blocks intentionally fall through when unhandled, and theConstTypecase rewrites the target type mid-flow — so aTypeSwitchtable would change semantics. Instead it is split into stage helpers returningstd::optional<ValueOrLogicalResult>(nullopt= "not handled, continue the pipeline") plusLogicalResultverifiers, with a ~100-line driver that preserves the original stage order exactly:verifyCastPreconditions(literal + strict-null) → enum unwrap →castViaToPrimitive→castToStringSpecialCases→castToInterfaceSpecialCases→castTupleLikeVariants→castToOptionalType→castToTaggedUnionType→ const-dest rewrite (kept inline: mutatestype) →castFromSourceSpecialCases(union/optional/any/opaque sources) →verifyFunctionCastRules→castExtensionFunctionType→verifyCastCompatibility→ defaultCastOp.Stage bodies are moved verbatim; the
EXIT_IF_FAILED*/CAST_Amacros compose correctly with thestd::optionalreturn (a failed result wraps and the driver returns it, identical to before).Also includes the user's
launch.jsonDEFAULT_LIB_PATH fix for the debug build, and repairs stray file corruption at the(this->*valueFactory)call site (five lines from #203 had been clobbered by a whitespace stub, most likely a stale editor buffer).Test plan
tslangrebuilt cleanly (vs2026 debug)toString, object literal→interface,anyunboxing — JIT output42 7 1 a greeter x 5as expectedMLIRGenTests.exe: 12/12 pass🤖 Generated with Claude Code