plutus-core-1.36.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusIR.Transform.RewriteRules.CommuteFnWithConst

Description

Commute such that constants are the first arguments. Consider:

  1. equalsInteger 1 x
  2. equalsInteger x 1

We have unary application, so these are two partial applications:

  1. (equalsInteger 1) x
  2. (equalsInteger x) 1

With (1), we can share the `equalsInteger 1` node, and it will be the same across any place where we do this.

With (2), both the nodes here include x, which is a variable that will likely be different in other invocations of equalsInteger. So the second one is harder to share, which is worse for CSE.

So commuting equalsInteger so that it has the constant first both a) makes various occurrences of equalsInteger more likely to look similar, and b) gives us a maximally-shareable node for CSE.

This applies to any commutative builtin function that takes constants as arguments, although we might expect that equalsInteger is the one that will benefit the most. Plutonomy only commutes EqualsInteger in their commEquals.

Documentation

commuteFnWithConst ∷ t ~ Term tyname name uni DefaultFun a ⇒ t → t Source #