From 3f604aecb0825aa68463da50137adbc74acfe8de Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 3 Jul 2009 18:35:02 +0200 Subject: [PATCH] Extract only representable arguments. Previously, anything but types and functions was extracted. This definition is slightly more general, but it should not matter for the programs we work with. --- Normalize.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Normalize.hs b/Normalize.hs index 9336921..9a74152 100644 --- a/Normalize.hs +++ b/Normalize.hs @@ -291,19 +291,22 @@ caseremovetop = everywhere ("caseremove", caseremove) appsimpl, appsimpltop :: Transform -- Don't simplify arguments that are already simple. appsimpl expr@(App f (Var v)) = return expr --- Simplify all non-applicable (to prevent loops with inlinefun) arguments, --- except for type arguments (since a let can't bind type vars, only a lambda --- can). Do this by introducing a new Let that binds the argument and passing --- the new binder in the application. -appsimpl (App f expr) | (not $ is_applicable expr) && (not $ CoreSyn.isTypeArg expr) = do - id <- mkInternalVar "arg" (CoreUtils.exprType expr) - change $ Let (Rec [(id, expr)]) (App f (Var id)) +-- Simplify all representable arguments. Do this by introducing a new Let +-- that binds the argument and passing the new binder in the application. +appsimpl expr@(App f arg) = do + -- Check runtime representability + repr <- isRepr arg + if repr + then do -- Extract representable arguments + id <- mkInternalVar "arg" (CoreUtils.exprType arg) + change $ Let (Rec [(id, arg)]) (App f (Var id)) + else -- Leave non-representable arguments unchanged + return expr -- Leave all other expressions unchanged appsimpl expr = return expr -- Perform this transform everywhere appsimpltop = everywhere ("appsimpl", appsimpl) - -------------------------------- -- Type argument propagation -------------------------------- -- 2.30.2