refactor[next]: replace workflow combinators with explicit typed pipelines - #2743
Open
egparedes wants to merge 1 commit into
Open
refactor[next]: replace workflow combinators with explicit typed pipelines#2743egparedes wants to merge 1 commit into
egparedes wants to merge 1 commit into
Conversation
egparedes
marked this pull request as ready for review
July 30, 2026 17:58
egparedes
force-pushed
the
otf-split-4-pipeline
branch
from
July 30, 2026 17:58
55f9fcb to
706dcba
Compare
…lines The workflow-combinator framework introduced by ADR 0011 had grown to a dozen abstractions to express what is, in the end, function composition. Measured against actual use, only `CachedStep` was a deep module; the rest were shallow wrappers around `Callable[[S], T]`, and the reflection loop in `NamedStepSequence.__call__` was `Any`-typed, defeating the static typing ADR 0011 prized. The named pipelines become plain frozen dataclasses with an explicit, fully typed `__call__`: - `backend.Transforms` keeps its input-dependent step *selection* -- the `match` that used to live in `step_order` now lives in `__call__`, where the order is literally readable -- and the `step_order` method is retained only to raise, so a downstream override fails loudly instead of being silently ignored. - `recipes.OTFCompileWorkflow` becomes `backend.CompilePipeline` and spells out its three steps; `otf.recipes` and `otf.toolchain` are deleted. - Both take over emitting the `stage_hook` added in the previous PR. Names, order, count and artifacts are unchanged; the two instrumentation tests that assert the exact stage sequences pass unmodified, which is the proof. Steps are now plain callables, named by the `workflow.Step[S, T]` alias, and customization stays composition-time via `dataclasses.replace`. Deleted: `Workflow`, `ChainableWorkflowMixin`, `ReplaceEnabledWorkflowMixin`, `NamedStepSequence`, `MultiWorkflow`, `StepSequence`, `make_step`, `.chain`, the three adapters in `otf.toolchain`, and the five `adapted_*_factory` wrappers whose only job was to wrap a function into an adapter. `CachedStep`'s body is unchanged; it loses only the mixin bases, and with them `.replace` and `.chain`. Because steps no longer need to be adapter objects, the seven ffront factories collapse to returning either the bare function or a `CachedStep` around it, and the three per-step callers in `decorator.py` lose their wrap/unwrap dance. What ADR 0011's decisions become: named steps with a visible order are now dataclass fields plus an explicit `__call__`; statically typed composition is checked end-to-end instead of through an `Any`-typed reflection loop; customization at composition time is `dataclasses.replace`; and steps still compose across backends because every existing step already satisfies `Step[S, T]`. No behavior change, and -- unlike the naming PR -- no persistent cache key rotates: fingerprints embed a class's qualified name and fields but never its bases, and neither renamed pipeline is reachable from a persistent cache's fingerprint graph. Breaking, with no compatibility aliases: the deleted combinators and the `otf.recipes` / `otf.toolchain` modules, `.replace()` / `.chain()` on the classes that kept them via the mixins, overriding `Transforms.step_order`, `roundtrip.foast_to_gtir_step` (now a data-only step), and `linter_factory(adapter=...)` (the parameter was accepted and ignored). Claude-Session: https://claude.ai/code/session_01R8zRtFMhdJ8c96XJYCXkRk
egparedes
force-pushed
the
otf-split-4-pipeline
branch
from
July 31, 2026 16:15
706dcba to
605676d
Compare
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.
Description
Final PR of the
otf-toolchain-splitstack (on top of #2742). It implements the "Pipeline, not combinators" decision recorded in ADR 0027, and lands theOTFCompileWorkflow→CompilePipelinerename that ADR deferred to this point.The combinator framework from ADR 0011 had grown to a dozen abstractions to express function composition. Only
CachedStepwas a deep module; the rest were shallow wrappers overCallable[[S], T], andNamedStepSequence.__call__'s reflection loop wasAny-typed — defeating the static typing ADR 0011 was after in the first place. Net: +500 / −887 lines.Pipelines are dataclasses with an explicit
__call__backend.Transformskeeps its input-dependent step selection: thematchthat lived instep_ordernow lives in__call__, where the order is literally readable top to bottom. Thestep_ordermethod is deleted.backend.CompilePipeline(exrecipes.OTFCompileWorkflow) spells out translation → bindings → compilation.stage_hookfrom refactor[next]: add stage observability and Toolchain.translate #2742. This is the part worth reviewing closely: names, order, count and artifact values are unchanged, and the two instrumentation tests that assert the exact stage sequences (test_hooks.py::test_stage_hookandtest_stage_dump.py'sEXPECTED_STAGES) pass unmodified — that is the identity proof.Steps are plain callables
workflow.Step[S, T]is justCallable[[S], T]. Customization stays composition-time viadataclasses.replace, per ADR 0011's own rule. Deleted:Workflow, both mixins,NamedStepSequence,MultiWorkflow,StepSequence,make_step,.chain, the threeotf.toolchainadapters, and the fiveadapted_*_factorywrappers that existed only to wrap a function into an adapter.CachedStep's body is character-for-character unchanged — it loses only the mixin bases (and with them.replace/.chain, see breaking changes) and gets three retyped annotations.otf.recipesandotf.toolchainare deleted, with no re-exports left behind.Because steps no longer have to be adapter objects, the seven ffront factories collapse to returning either the bare function or a
CachedSteparound it, and the three per-step callers indecorator.pylose their wrap/unwrap dance.What ADR 0011's requirements become
__call__(order literally visible)__call__, checked end-to-end — unlike theAny-typed reflection loopdataclasses.replaceon frozen pipelinesStep[S, T]is aCallable; every existing step already satisfies itTransformskeeps its input-dependent selection)Cache keys: nothing rotates
Unlike the naming PR, no persistent key changes. Verified empirically rather than assumed:
fingerprintingtags a dataclass with its fully-qualified name plus its fields and never touches__bases__/__mro__(two otherwise-identical classes, one with Protocol bases, fingerprint equal), and neitherCompilePipelinenorTransformsis reachable from a persistent cache's fingerprint graph — the persistentCachedStepwraps the bare translator directly. Some in-memory step fingerprints move (unwrapped steps), which is invisible: those dicts are per-process and never persisted.Breaking changes for downstream
Please read this list rather than skimming it — the first two are the ones most likely to bite.
Transformssteps change signature.func_to_foast,func_to_past,past_lintandfoast_to_itirgo from pair-in/pair-out to bare-stage-in/bare-stage-out. This matters becausedataclasses.replace(DEFAULT_TRANSFORMS, past_lint=…)is the sanctioned customization mechanism andHackTheToolchain.mdshipped exactly that recipe, so a step written against the current release fails withAttributeError: 'PASTProgramDef' object has no attribute 'definition'on first call..replace()and.chain()disappear from classes this PR otherwise leaves alone —CachedStep,GTFNTranslationStep,CPPCompiler,DaCeTranslator,DaCeCompiler, and both pipelines. They came from the deleted mixins. Note ADR 0012 documentsworkflow.replace(run_gtfn.workflow, <name>=<instance>)as the substep-configuration idiom, so this is a live pattern; the replacement isdataclasses.replace.Transforms.step_ordernow raisesTypeError— the method is retained purely to fail loudly, since__call__no longer consults it and a silent override would have quietly re-enabled skipped steps.stages.TranslationStep/stages.CompilationStepchange fromProtocolclasses toCallabletype aliases, so they can no longer be subclassed or used withisinstance.Workflowis gone — annotate withStep[S, T]. It was aProtocol, soisinstance/subclass uses break loudly, which is intended.gt4py.next.otf.recipesandgt4py.next.otf.toolchainno longer exist:OTFCompileWorkflowis nowgt4py.next.backend.CompilePipeline, and the pair type lives ingt4py.next.otf.workflow.roundtrip.foast_to_gtir_stepsilently changes signature (pair → bareFOASTOperatorDef). No in-repo users.linter_factory(adapter=...)raisesTypeError; the parameter was accepted and ignored before.ItirShim.foast_to_itiris now data-only; anyone constructing anItirShimwith a pair-typed step breaks.Docs
Both executed notebooks are rewritten.
WorkflowPatterns.mdwas largely a tour of the deleted framework; it now coversStep,CachedStep,dataclasses.replace, and observing stages viastage_hook/GT4PY_DUMP_STAGES.HackTheToolchain.md's "skip a step" recipe becomes adataclasses.replacewith an identity step instead of astep_orderoverride. Three cells in these notebooks referenced names that no longer exist (DEFAULT_PROG_TRANSFORMS,LinterFactory,.steps.inner[0]) and only "passed" CI because IPython's??reports a lookup failure without raising — those are fixed, but note nbmake does not guard against that class of regression.Requirements
Transforms/CompilePipelinetests assert step order, hook emission, passthrough,dataclasses.replacecustomization, and error ordering. The two stage-sequence oracles are unmodified.)https://claude.ai/code/session_01R8zRtFMhdJ8c96XJYCXkRk