From 3a432fad8639dcaf623f6d6def93dcdd6cfc8fda Mon Sep 17 00:00:00 2001 From: Justus Adam Date: Thu, 21 Feb 2019 13:03:15 +0100 Subject: [PATCH] [#32] Added a check for empty and unused ctrl operators --- core/src/Ohua/ALang/Passes/Control.hs | 29 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/core/src/Ohua/ALang/Passes/Control.hs b/core/src/Ohua/ALang/Passes/Control.hs index 6248480..8894ce2 100644 --- a/core/src/Ohua/ALang/Passes/Control.hs +++ b/core/src/Ohua/ALang/Passes/Control.hs @@ -177,15 +177,20 @@ liftIntoCtrlCtxt :: (Monad m, MonadGenBnd m) => Binding -> Expression -> m Expression liftIntoCtrlCtxt ctrlIn e = do (lam', actuals) <- lambdaLifting e - let (originalFormals, _) = lambdaArgsAndBody e - let (allFormals, e) = lambdaArgsAndBody lam' - ctrlOut <- generateBindingWith "ctrl" - let formals = reverse $ take (length actuals) $ reverse allFormals - let actuals' = [Var ctrlIn] ++ actuals - let ie = mkDestructured formals ctrlOut e - return $ - mkLambda originalFormals $ - Let - ctrlOut - (fromListToApply (FunRef "ohua.lang/ctrl" Nothing) actuals') - ie + if null actuals + then do + dAssertM $ lam' == e + pure lam' + else do + let (originalFormals, _) = lambdaArgsAndBody e + let (allFormals, e) = lambdaArgsAndBody lam' + ctrlOut <- generateBindingWith "ctrl" + let formals = reverse $ take (length actuals) $ reverse allFormals + let actuals' = [Var ctrlIn] ++ actuals + let ie = mkDestructured formals ctrlOut e + return $ + mkLambda originalFormals $ + Let + ctrlOut + (fromListToApply (FunRef "ohua.lang/ctrl" Nothing) actuals') + ie