Skip to main content

vyre_driver/registry/
mutation.rs

1//! IR mutation classification.
2//!
3//! Every optimizer pass declares a `MutationClass`  -  a frozen tag that says
4//! *what kind of change this pass is allowed to make*. The conformance
5//! harness uses the class to decide how strictly the result must match the
6//! reference interpreter:
7//!
8//! - `Cosmetic`: re-names a local, collapses aliases. Output must match the
9//!   reference **byte-for-byte** on every witness input.
10//! - `Structural`: reshapes the IR (CSE, DCE, node flattening) without
11//!   changing observable semantics. Output must match byte-for-byte.
12//! - `Semantic`: may change IR observable semantics under a declared
13//!   precondition (e.g. fast-math reassociation assumes no NaNs). The
14//!   conform gate must verify the precondition holds on the witness set.
15//! - `Lowering`: backend-specific emission. Output is allowed to differ in
16//!   shape but must satisfy every `AlgebraicLaw` declared on the op.
17
18/// Frozen classification of IR-mutating passes.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20#[non_exhaustive]
21pub enum MutationClass {
22    /// Renames and alias collapse only. Byte-exact output required.
23    Cosmetic,
24    /// Reshape without semantic change (CSE, DCE, flatten, inline). Byte-exact.
25    Structural,
26    /// Semantic change under a declared precondition. Requires witness proof.
27    Semantic,
28    /// Backend lowering. Output checked against declared algebraic laws, not
29    /// against byte-for-byte reference output.
30    Lowering,
31}
32
33impl MutationClass {
34    /// `true` when the conform gate must verify byte-for-byte parity with the
35    /// reference interpreter after this class of mutation.
36    #[must_use]
37    pub const fn requires_byte_parity(self) -> bool {
38        matches!(self, Self::Cosmetic | Self::Structural)
39    }
40
41    /// `true` when the conform gate verifies declared `AlgebraicLaw`s rather
42    /// than byte-for-byte equivalence.
43    #[must_use]
44    pub const fn uses_law_proof(self) -> bool {
45        matches!(self, Self::Lowering)
46    }
47}