Skip to content

Decompose 590-line cast() into named pipeline stages#205

Merged
ASDAlexander77 merged 1 commit into
mainfrom
refactor/cast-decomposition
Jul 12, 2026
Merged

Decompose 590-line cast() into named pipeline stages#205
ASDAlexander77 merged 1 commit into
mainfrom
refactor/cast-decomposition

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

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 the ConstType case rewrites the target type mid-flow — so a TypeSwitch table would change semantics. Instead it is split into stage helpers returning std::optional<ValueOrLogicalResult> (nullopt = "not handled, continue the pipeline") plus LogicalResult verifiers, with a ~100-line driver that preserves the original stage order exactly:

verifyCastPreconditions (literal + strict-null) → enum unwrap → castViaToPrimitivecastToStringSpecialCasescastToInterfaceSpecialCasescastTupleLikeVariantscastToOptionalTypecastToTaggedUnionType → const-dest rewrite (kept inline: mutates type) → castFromSourceSpecialCases (union/optional/any/opaque sources) → verifyFunctionCastRulescastExtensionFunctionTypeverifyCastCompatibility → default CastOp.

Stage bodies are moved verbatim; the EXIT_IF_FAILED*/CAST_A macros compose correctly with the std::optional return (a failed result wraps and the driver returns it, identical to before).

Also includes the user's launch.json DEFAULT_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

🤖 Generated with Claude Code

@ASDAlexander77 ASDAlexander77 merged commit 7d07177 into main Jul 12, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/cast-decomposition branch July 12, 2026 00:02
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