Amazingly, SimplCore.simplifyExpr didn't call the occurrence
analyser, so expressions typed in at the prompt were being
simplified very weedily. Ditto the LHS and RHS of RULES.
So SimplCore.simplExprGently now does the business. It runs
the simplifier twice because one pass leaves tons of crud.
This doesn't fix any bugs but it is cleaner.
import Module ( moduleEnvElts )
import CoreUnfold
import PprCore ( pprCoreBindings, pprIdCoreRule, pprCoreExpr )
import Module ( moduleEnvElts )
import CoreUnfold
import PprCore ( pprCoreBindings, pprIdCoreRule, pprCoreExpr )
-import OccurAnal ( occurAnalyseBinds )
+import OccurAnal ( occurAnalyseBinds, occurAnalyseGlobalExpr )
import CoreUtils ( etaReduce, coreBindsSize )
import Simplify ( simplTopBinds, simplExpr )
import SimplUtils ( simplBinders )
import CoreUtils ( etaReduce, coreBindsSize )
import Simplify ( simplTopBinds, simplExpr )
import SimplUtils ( simplBinders )
-> HomeSymbolTable
-> CoreExpr
-> IO CoreExpr
-> HomeSymbolTable
-> CoreExpr
-> IO CoreExpr
+-- simplifyExpr is called by the driver to simplify an
+-- expression typed in at the interactive prompt
simplifyExpr dflags pcs hst expr
= do {
; showPass dflags "Simplify"
simplifyExpr dflags pcs hst expr
= do {
; showPass dflags "Simplify"
; us <- mkSplitUniqSupply 's'
; let (expr', _counts) = initSmpl dflags sw_chkr us emptyVarSet black_list_all
; us <- mkSplitUniqSupply 's'
; let (expr', _counts) = initSmpl dflags sw_chkr us emptyVarSet black_list_all
- ; dumpIfSet_dyn dflags Opt_D_dump_simpl "Simplfied expression"
+ ; dumpIfSet_dyn dflags Opt_D_dump_simpl "Simplified expression"
(pprCoreExpr expr')
; return expr'
(pprCoreExpr expr')
; return expr'
= returnSmpl rule
simplRule rule@(id, Rule name bndrs args rhs)
= simplBinders bndrs $ \ bndrs' ->
= returnSmpl rule
simplRule rule@(id, Rule name bndrs args rhs)
= simplBinders bndrs $ \ bndrs' ->
- mapSmpl simpl_arg args `thenSmpl` \ args' ->
- simplExpr rhs `thenSmpl` \ rhs' ->
+ mapSmpl simplExprGently args `thenSmpl` \ args' ->
+ simplExprGently rhs `thenSmpl` \ rhs' ->
returnSmpl (id, Rule name bndrs' args' rhs')
returnSmpl (id, Rule name bndrs' args' rhs')
-simpl_arg e
--- I've seen rules in which a LHS like
+-- It's important that simplExprGently does eta reduction.
+-- For example, in a rule like:
+-- we do not want to get
-- augment (\a. g a) (build h)
-- augment (\a. g a) (build h)
--- So it's a help to eta-reduce the args as we simplify them.
--- Otherwise we don't match when given an argument like
+-- otherwise we don't match when given an argument like
- = simplExpr e `thenSmpl` \ e' ->
- returnSmpl (etaReduce e')
+--
+-- The simplifier does indeed do eta reduction (it's in
+-- Simplify.completeLam) but only if -O is on.
+\end{code}
+
+\begin{code}
+simplExprGently :: CoreExpr -> SimplM CoreExpr
+-- Simplifies an expression
+-- does occurrence analysis, then simplification
+-- and repeats (twice currently) because one pass
+-- alone leaves tons of crud.
+-- Used (a) for user expressions typed in at the interactive prompt
+-- (b) the LHS and RHS of a RULE
+simplExprGently expr
+ = simplExpr (occurAnalyseGlobalExpr expr) `thenSmpl` \ expr1 ->
+ simplExpr (occurAnalyseGlobalExpr expr1)