{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
module PlutusIR.Transform.ThunkRecursions (thunkRecursions) where
import PlutusPrelude
import PlutusIR
isFunctionType :: Type tyname uni a -> Bool
isFunctionType :: Type tyname uni a -> Bool
isFunctionType = \case
TyFun {} -> Bool
True
Type tyname uni a
_ -> Bool
False
thunkBinding :: Binding tyname name uni fun a -> Binding tyname name uni fun a
thunkBinding :: Binding tyname name uni fun a -> Binding tyname name uni fun a
thunkBinding = \case
TermBind a
x Strictness
Strict d :: VarDecl tyname name uni fun a
d@(VarDecl a
_ name
_ Type tyname uni a
ty) Term tyname name uni fun a
rhs | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Type tyname uni a -> Bool
forall tyname (uni :: * -> *) a. Type tyname uni a -> Bool
isFunctionType Type tyname uni a
ty -> a
-> Strictness
-> VarDecl tyname name uni fun a
-> Term tyname name uni fun a
-> Binding tyname name uni fun a
forall tyname name (uni :: * -> *) fun a.
a
-> Strictness
-> VarDecl tyname name uni fun a
-> Term tyname name uni fun a
-> Binding tyname name uni fun a
TermBind a
x Strictness
NonStrict VarDecl tyname name uni fun a
d Term tyname name uni fun a
rhs
Binding tyname name uni fun a
b -> Binding tyname name uni fun a
b
thunkRecursions :: Term tyname name uni fun a -> Term tyname name uni fun a
thunkRecursions :: Term tyname name uni fun a -> Term tyname name uni fun a
thunkRecursions = \case
t :: Term tyname name uni fun a
t@(Let a
_ Recursivity
Rec NonEmpty (Binding tyname name uni fun a)
_ Term tyname name uni fun a
_) -> Term tyname name uni fun a
t
Term tyname name uni fun a
-> (Term tyname name uni fun a -> Term tyname name uni fun a)
-> Term tyname name uni fun a
forall a b. a -> (a -> b) -> b
& ASetter
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Term tyname name uni fun a)
-> (Term tyname name uni fun a -> Term tyname name uni fun a)
-> Term tyname name uni fun a
-> Term tyname name uni fun a
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Term tyname name uni fun a)
forall tyname name (uni :: * -> *) fun a.
Traversal'
(Term tyname name uni fun a) (Term tyname name uni fun a)
termSubterms Term tyname name uni fun a -> Term tyname name uni fun a
forall tyname name (uni :: * -> *) fun a.
Term tyname name uni fun a -> Term tyname name uni fun a
thunkRecursions
Term tyname name uni fun a
-> (Term tyname name uni fun a -> Term tyname name uni fun a)
-> Term tyname name uni fun a
forall a b. a -> (a -> b) -> b
& ASetter
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Binding tyname name uni fun a)
(Binding tyname name uni fun a)
-> (Binding tyname name uni fun a -> Binding tyname name uni fun a)
-> Term tyname name uni fun a
-> Term tyname name uni fun a
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Binding tyname name uni fun a)
(Binding tyname name uni fun a)
forall tyname name (uni :: * -> *) fun a.
Traversal'
(Term tyname name uni fun a) (Binding tyname name uni fun a)
termBindings Binding tyname name uni fun a -> Binding tyname name uni fun a
forall tyname name (uni :: * -> *) fun a.
Binding tyname name uni fun a -> Binding tyname name uni fun a
thunkBinding
Term tyname name uni fun a
t -> Term tyname name uni fun a
t Term tyname name uni fun a
-> (Term tyname name uni fun a -> Term tyname name uni fun a)
-> Term tyname name uni fun a
forall a b. a -> (a -> b) -> b
&
ASetter
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Term tyname name uni fun a)
-> (Term tyname name uni fun a -> Term tyname name uni fun a)
-> Term tyname name uni fun a
-> Term tyname name uni fun a
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Term tyname name uni fun a)
(Term tyname name uni fun a)
forall tyname name (uni :: * -> *) fun a.
Traversal'
(Term tyname name uni fun a) (Term tyname name uni fun a)
termSubterms Term tyname name uni fun a -> Term tyname name uni fun a
forall tyname name (uni :: * -> *) fun a.
Term tyname name uni fun a -> Term tyname name uni fun a
thunkRecursions