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
inlinetopleveltop = everywhere ("inlinetoplevel", inlinetoplevel)
needsInline :: CoreExpr -> Bool
--- Any function that just evaluates to another function, can be inlined
---needsInline (Var f) = True
-needsInline _ = False
+needsInline expr = case splitNormalized expr of
+ -- Inline any function that only has a single definition, it is probably
+ -- simple enough. This might inline some stuff that it shouldn't though it
+ -- will never inline user-defined functions (inlinetoplevel only tries
+ -- system names) and inlining should never break things.
+ (args, [bind], res) -> True
+ _ -> False
--------------------------------
-- Scrutinee simplification
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