Commit 679560cd authored by simonpj's avatar simonpj
Browse files

[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.
parent 26b8a5b3
......@@ -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.
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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment