From: Matthijs Kooijman Date: Fri, 14 Aug 2009 13:38:03 +0000 (+0200) Subject: Limit flattenLets to non-recursive lets only. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=de2b45772572a90429ffe41a86a7ba08e7de6d4b;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Limit flattenLets to non-recursive lets only. flattenLets is currently used for splitNormalized only, which should be non-recursive lets only. To use it in other places to filter lets, we should only flatten non-recursive lets, so we can create new non-recursive lets afterwards. --- diff --git "a/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" "b/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" index 21c5e14..3945cce 100644 --- "a/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" +++ "b/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" @@ -298,19 +298,17 @@ hasStateType expr = case getType expr of Just ty -> isStateType ty --- | Flattens nested lets into a single list of bindings. The expression --- passed does not have to be a let expression, if it isn't an empty list of --- bindings is returned. +-- | Flattens nested non-recursive lets into a single list of bindings. The +-- expression passed does not have to be a let expression, if it isn't an +-- empty list of bindings is returned. flattenLets :: CoreSyn.CoreExpr -- ^ The expression to flatten. -> ([Binding], CoreSyn.CoreExpr) -- ^ The bindings and resulting expression. -flattenLets (CoreSyn.Let binds expr) = - (bindings ++ bindings', expr') +flattenLets (CoreSyn.Let (CoreSyn.NonRec bndr expr) res) = + ((bndr, expr):bindings, res') where -- Recursively flatten the contained expression - (bindings', expr') =flattenLets expr - -- Flatten our own bindings to remove the Rec / NonRec constructors - bindings = CoreSyn.flattenBinds [binds] + (bindings, res') = flattenLets res flattenLets expr = ([], expr) -- | A class of things that (optionally) have a core Type. The type is