import ErrUtils
import CmdLineOpts
import Outputable
+import PprCore
\end{code}
-- ---------------------------------------------------------------------------
-- f (g x) ===> ([v = g x], f v)
coreSatExprFloat (Var v)
- = fiddleCCall v `thenUs` \ v ->
- maybeSaturate v (Var v) 0 (idType v) `thenUs` \ app ->
+ = maybeSaturate v (Var v) 0 (idType v) `thenUs` \ app ->
returnUs ([], app)
coreSatExprFloat (Lit lit)
returnUs (App fun' arg', hd, res_ty, fs ++ floats, ss_rest)
collect_args (Var v) depth
- = fiddleCCall v `thenUs` \ v ->
- returnUs (Var v, (Var v, depth), idType v, [], stricts)
+ = returnUs (Var v, (Var v, depth), idType v, [], stricts)
where
stricts = case idStrictness v of
StrictnessInfo demands _
saturate_it = getUs `thenUs` \ us ->
returnUs (etaExpand excess_arity us expr ty)
-fiddleCCall id
- = case idFlavour id of
- PrimOpId (CCallOp ccall) ->
- -- Make a guaranteed unique name for a dynamic ccall.
- getUniqueUs `thenUs` \ uniq ->
- returnUs (modifyIdInfo (`setFlavourInfo`
- PrimOpId (CCallOp (setCCallUnique ccall uniq))) id)
- other_flavour ->
- returnUs id
-
-- ---------------------------------------------------------------------------
-- Eliminate Lam as a non-rhs (STG doesn't have such a thing)
-- ---------------------------------------------------------------------------
(bndrs, body) = collectBinders expr
eta expr@(App _ _)
- | n_remaining >= 0 &&
+ | ok_to_eta_reduce f &&
+ n_remaining >= 0 &&
and (zipWith ok bndrs last_args) &&
not (any (`elemVarSet` fvs_remaining) bndrs)
= Just remaining_expr
ok bndr (Var arg) = bndr == arg
ok bndr other = False
+ -- we can't eta reduce something which must be saturated.
+ ok_to_eta_reduce (Var f)
+ = case idFlavour f of
+ PrimOpId op -> False
+ DataConId dc -> False
+ other -> True
+ ok_to_eta_reduce _ = False --safe. ToDo: generalise
+
eta (Let bind@(NonRec b r) body)
| not (any (`elemVarSet` fvs) bndrs)
= case eta body of