qat.experimental.passes.invariant module
Proof of concept for opt-in invariants in experimental xDSL pass pipelines.
The runner controls check timing. Caller-supplied policies define phase activation and verification without adding invariant logic to each transformation.
- class InvariantPassPipeline(passes, invariant, callback=None)
Bases:
OrderedPassPipelineCheck successful pass outputs once a caller-defined invariant becomes active.
An active entry is checked before any pass, even for an empty pipeline. Otherwise, checks start at the successful output of an establishing pass and continue through every later output, including a sole or final pass. Activation resets for each
apply()call, allowing the same pipeline and policy to be reused.Callbacks are non-mutating observers and run only between passes, after any required check. Represent IR-changing callbacks as passes so their output can be checked.
Nested pipelines are opaque: the outer runner checks their output, not their inner boundaries. Inner consumers need their own runner and entry or activation contract.
Store the execution configuration and validate declared pass ordering.
- Parameters:
passes¶ (
tuple[ModulePass,...]) – Pass instances in their execution order.invariant¶ (
InvariantPolicy) – Policy supplying the entry contract, establishing-pass predicate and read-only verifier.callback¶ (
Callable[[ModulePass,ModuleOp,ModulePass],None] |None) – Optional non-mutating observer receiving the completed pass, current module and following pass.
- Raises:
xdsl.utils.exceptions.VerifyException – If declared pass ordering constraints are violated.
- apply(ctx, op)
Transform the module in place under the configured invariant contract.
Pass, policy and callback exceptions propagate unchanged and stop execution. Failed transformations do not trigger output verification, and module mutations are not rolled back.
-
invariant:
InvariantPolicy
- class InvariantPolicy(*args, **kwargs)
Bases:
ProtocolDefine an invariant and the successful pass that makes it mandatory.
Pipeline composition supplies the entry contract, activation predicate and verifier. The verifier must not modify IR. The runner owns per-execution activation, so policies must not retain compilation-local state on themselves, passes or the xDSL context.
- property initially_active: bool
Declare whether the input must satisfy the invariant before any pass runs.
- Returns:
Whether to verify the entry, including for an empty pipeline.
- is_established_by(pass_)
Decide whether a successful pass starts the required invariant phase.
Called only while inactive. A true result requests verification of this pass’s output before a callback or the next pass can observe it.
- Parameters:
pass_¶ – The pass that returned successfully.
- Return type:
bool- Returns:
Whether this pass establishes the invariant’s required phase.
- verify(ctx, op, checked_stage)
Check the current module without modifying it.
Returning normally accepts the module. Raise an implementation-specific exception to reject it. The runner propagates that exception unchanged.
- Parameters:
ctx¶ (
Context) – The same context supplied to the pipeline and its passes.op¶ (
ModuleOp) – Current module, either at entry or after a successful pass.checked_stage¶ (
str|None) – Producer pass name for diagnostics, orNonefor entry. The checked producer is not necessarily the origin of a defect.
- Return type:
None