Skip to main content

Module canonical

Module canonical 

Source
Expand description

Expression canonicalization for improved cache hit rates.

Puts TLExpr into a canonical structural form so that semantically equivalent expressions (e.g., AND(a,b) vs AND(b,a)) have identical fingerprints. This is purely structural normalization — not constant folding or algebraic simplification (those exist in separate passes).

Three canonicalization rules:

  1. Double negation elimination: NOT(NOT(x)) → x
  2. Nested same-op flattening: AND(AND(a,b), c) → AND(a, AND(b,c)) sorted
  3. Commutative sorting: AND/OR operands sorted by canonical_order_key

Structs§

CanonicalStats
Statistics from canonicalization.
Canonicalizer
Expression canonicalizer with configurable rules.

Functions§

canonical_order_key
Compute a canonical ordering key for sorting commutative children.
canonicalize
Convenience function: canonicalize and return the result.