Skip to content

Commit

Permalink
wi
Browse files Browse the repository at this point in the history
  • Loading branch information
ak3n committed Oct 14, 2021
1 parent b45d38d commit 6921fbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
20 changes: 9 additions & 11 deletions plutus-core/plutus-ir/src/PlutusIR/Compiler.hs
Expand Up @@ -83,15 +83,13 @@ logDebug :: Compiling m e uni fun a => String -> m ()
logDebug = whenM isDebug . traceM

applyPass :: (Compiling m e uni fun a, b ~ Provenance a) => Pass uni fun -> Term TyName Name uni fun b -> m (Maybe (Term TyName Name uni fun b))
applyPass pass term = do
c <- runIf (_shouldRun pass) $ do
let passName = _name pass
logVerbose $ " !!! " ++ passName
logDebug $ " !!! Before " ++ passName ++ "\n" ++ show (pretty term)
term' <- _pass pass term
logDebug $ " !!! After " ++ passName ++ "\n" ++ show (pretty term')
pure term'
c >=> through check
applyPass pass = runIf (_shouldRun pass) $ through check <=< \term -> do
let passName = _name pass
logVerbose $ " !!! " ++ passName
logDebug $ " !!! Before " ++ passName ++ "\n" ++ show (pretty term)
term' <- _pass pass term
logDebug $ " !!! After " ++ passName ++ "\n" ++ show (pretty term')
pure term'

availablePasses :: [Pass uni fun]
availablePasses =
Expand All @@ -103,8 +101,8 @@ availablePasses =
-- | Actual simplifier
simplify
:: forall m e uni fun a b. (Compiling m e uni fun a, b ~ Provenance a)
=> Term TyName Name uni fun b -> m (Term TyName Name uni fun b)
simplify = foldl' (>=>) pure (map applyPass availablePasses)
=> Term TyName Name uni fun b -> m (Maybe (Term TyName Name uni fun b))
simplify t = foldl' (>=>) (pure) (map applyPass availablePasses)

-- | Perform some simplification of a 'Term'.
simplifyTerm
Expand Down
8 changes: 4 additions & 4 deletions plutus-core/plutus-ir/src/PlutusIR/Compiler/Types.hs
Expand Up @@ -80,13 +80,13 @@ withEnclosing f = local (over ccEnclosing f)
runIf
:: MonadReader (CompilationCtx uni fun a) m
=> m Bool
-> (b -> m (Maybe b))
-> (b -> m (Maybe b))
-> (b -> m b)
-> (b -> m b)
runIf condition pass arg = do
doPass <- condition
if doPass then pass arg else pure $ Just arg
if doPass then pass arg else pure arg

runIfOpts :: MonadReader (CompilationCtx uni fun a) m => (b -> m (Maybe b)) -> (b -> m (Maybe b))
runIfOpts :: MonadReader (CompilationCtx uni fun a) m => (b -> m b) -> (b -> m b)
runIfOpts = runIf $ view (ccOpts . coOptimize)

type PLCTerm uni fun a = PLC.Term PLC.TyName PLC.Name uni fun (Provenance a)
Expand Down

0 comments on commit 6921fbf

Please sign in to comment.