summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorsimonpj <unknown>2001-01-12 11:36:24 +0000
committersimonpj <unknown>2001-01-12 11:36:24 +0000
commit679560cdce96a854db3dbab5380da72ea56f5b85 (patch)
tree69ff47848d57548441f4dc026b43bd01fdf23514 /ghc
parent26b8a5b3feab9d556c92f495a6775acf8cf9f3ec (diff)
downloadhaskell-679560cdce96a854db3dbab5380da72ea56f5b85.tar.gz
[project @ 2001-01-12 11:36:24 by simonpj]
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.
Diffstat (limited to 'ghc')
-rw-r--r--ghc/compiler/simplCore/SimplCore.lhs39
1 files changed, 27 insertions, 12 deletions
diff --git a/ghc/compiler/simplCore/SimplCore.lhs b/ghc/compiler/simplCore/SimplCore.lhs
index af45946dfe..d03671e89a 100644
--- a/ghc/compiler/simplCore/SimplCore.lhs
+++ b/ghc/compiler/simplCore/SimplCore.lhs
@@ -24,7 +24,7 @@ import Rules ( RuleBase, emptyRuleBase, ruleBaseFVs, ruleBaseIds,
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 )
@@ -99,6 +99,8 @@ simplifyExpr :: DynFlags -- includes spec of what core-to-core passes to do
-> 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"
@@ -106,9 +108,9 @@ simplifyExpr dflags pcs hst expr
; us <- mkSplitUniqSupply 's'
; let (expr', _counts) = initSmpl dflags sw_chkr us emptyVarSet black_list_all
- (simplExpr expr)
+ (simplExprGently expr)
- ; dumpIfSet_dyn dflags Opt_D_dump_simpl "Simplfied expression"
+ ; dumpIfSet_dyn dflags Opt_D_dump_simpl "Simplified expression"
(pprCoreExpr expr')
; return expr'
@@ -284,20 +286,33 @@ simplRule rule@(id, BuiltinRule _)
= 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')
-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:
-- augment g (build h)
--- turns into
+-- we do not want to get
-- 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
-- (\a. h a a)
- = 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)
\end{code}