Skip to content

Commit

Permalink
Make pure.
Browse files Browse the repository at this point in the history
  • Loading branch information
thealmarty committed May 30, 2023
1 parent 3a54b4c commit b065041
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion plutus-core/plutus-ir/src/PlutusIR/Compiler.hs
Expand Up @@ -127,7 +127,7 @@ availablePasses =
ver <- view ccBuiltinVer
Inline.inline hints ver t
)
, Pass "commuteConst" (onOption coDoSimplifiercommuteConst) CommuteConst.commuteConst
, Pass "commuteConst" (onOption coDoSimplifiercommuteConst) (pure . CommuteConst.commuteConst)
]

-- | Actual simplifier
Expand Down
26 changes: 12 additions & 14 deletions plutus-core/plutus-ir/src/PlutusIR/Transform/CommuteConst.hs
Expand Up @@ -33,25 +33,23 @@ the one that will benefit the most. Plutonomy only commutes `EqualsInteger`.
-}

commuteConstDefault ::
forall m tyname name uni a.
( PLC.MonadQuote m
) => Term tyname name uni PLC.DefaultFun a ->
m (Term tyname name uni PLC.DefaultFun a)
forall tyname name uni a.
Term tyname name uni PLC.DefaultFun a ->
Term tyname name uni PLC.DefaultFun a
commuteConstDefault (Apply ann (Builtin annB PLC.EqualsInteger) (Apply ann1 x y@(Constant{}))) =
pure $ Apply ann (Builtin annB PLC.EqualsInteger) (Apply ann1 y x)
Apply ann (Builtin annB PLC.EqualsInteger) (Apply ann1 y x)
commuteConstDefault (Apply ann (Builtin annB PLC.EqualsByteString) (Apply ann1 x y@(Constant{}))) =
pure $ Apply ann (Builtin annB PLC.EqualsByteString) (Apply ann1 y x)
Apply ann (Builtin annB PLC.EqualsByteString) (Apply ann1 y x)
commuteConstDefault (Apply ann (Builtin annB PLC.EqualsString) (Apply ann1 x y@(Constant{}))) =
pure $ Apply ann (Builtin annB PLC.EqualsString) (Apply ann1 y x)
Apply ann (Builtin annB PLC.EqualsString) (Apply ann1 y x)
commuteConstDefault (Apply ann (Builtin annB PLC.AddInteger) (Apply ann1 x y@(Constant{}))) =
pure $ Apply ann (Builtin annB PLC.AddInteger) (Apply ann1 y x)
Apply ann (Builtin annB PLC.AddInteger) (Apply ann1 y x)
commuteConstDefault (Apply ann (Builtin annB PLC.MultiplyInteger) (Apply ann1 x y@(Constant{}))) =
pure $ Apply ann (Builtin annB PLC.MultiplyInteger) (Apply ann1 y x)
commuteConstDefault tm = pure tm
Apply ann (Builtin annB PLC.MultiplyInteger) (Apply ann1 y x)
commuteConstDefault tm = tm

commuteConst :: forall m tyname name uni fun a.
( PLC.MonadQuote m, Typeable fun
) => Term tyname name uni fun a -> m (Term tyname name uni fun a)
commuteConst :: forall tyname name uni fun a. Typeable fun =>
Term tyname name uni fun a -> Term tyname name uni fun a
commuteConst = case eqT @fun @PLC.DefaultFun of
Just Refl -> commuteConstDefault
Nothing -> \x -> pure x
Nothing -> id

0 comments on commit b065041

Please sign in to comment.