Make isRepr work on TypedThings instead of CoreExpr.
[matthijs/master-project/cλash.git] / cλash / CLasH / Normalize.hs
index d66a1885be7062ea207561d4b17762b07f551033..38ee353ac4225fe49dc3b8e85c7c248de7f66f6e 100644 (file)
@@ -323,7 +323,7 @@ inlinenonreptop = everywhere ("inlinenonrep", inlinebind ((Monad.liftM not) . is
 inlinetoplevel, inlinetopleveltop :: Transform
 -- Any system name is candidate for inlining. Never inline user-defined
 -- functions, to preserver structure.
-inlinetoplevel expr@(Var f) | (Name.isSystemName . Id.idName) f = do
+inlinetoplevel expr@(Var f) | not $ isUserDefined f = do
   -- See if this is a top level binding for which we have a body
   body_maybe <- Trans.lift $ getGlobalBind f
   case body_maybe of
@@ -427,7 +427,7 @@ casesimpl expr@(Case scrut b ty alts) = do
       -- binding containing a case expression.
       dobndr :: CoreBndr -> Int -> TransformMonad (CoreBndr, Maybe (CoreBndr, CoreExpr))
       dobndr b i = do
-        repr <- isRepr (Var b)
+        repr <- isRepr b
         -- Is b wild (e.g., not a free var of expr. Since b is only in scope
         -- in expr, this means that b is unused if expr does not use it.)
         let wild = not (VarSet.elemVarSet b free_vars)
@@ -651,7 +651,10 @@ simplrestop expr@(Lam _ _) = return expr
 simplrestop expr@(Let _ _) = return expr
 simplrestop expr = do
   local_var <- Trans.lift $ is_local_var expr
-  if local_var
+  -- Don't extract values that are not representable, to prevent loops with
+  -- inlinenonrep
+  repr <- isRepr expr
+  if local_var || not repr
     then
       return expr
     else do