import CoreSyn
import TcIface ( loadImportedRules )
import HscTypes ( HscEnv(..), ModGuts(..), ExternalPackageState(..),
- ModDetails(..), HomeModInfo(..), hscEPS )
+ ModDetails(..), HomeModInfo(..), HomePackageTable, Dependencies( dep_mods ),
+ hscEPS, hptRules )
import CSE ( cseProgram )
import Rules ( RuleBase, ruleBaseIds, emptyRuleBase,
extendRuleBaseList, pprRuleBase, ruleCheckProgram )
-import Module ( moduleEnvElts )
+import Module ( elemModuleEnv, lookupModuleEnv )
import PprCore ( pprCoreBindings, pprCoreExpr, pprIdRules )
import OccurAnal ( occurAnalyseBinds, occurAnalyseGlobalExpr )
import CoreUtils ( coreBindsSize )
import Simplify ( simplTopBinds, simplExpr )
-import SimplUtils ( simplBinders )
+import SimplEnv ( SimplEnv, simplBinders, mkSimplEnv, setInScopeSet )
import SimplMonad
import ErrUtils ( dumpIfSet, dumpIfSet_dyn, showPass )
import CoreLint ( endPass )
import IO ( hPutStr, stderr )
import Outputable
import List ( partition )
-import Maybes ( orElse )
+import Maybes ( orElse, fromJust )
\end{code}
%************************************************************************
; us <- mkSplitUniqSupply 's'
- ; let env = emptySimplEnv SimplGently []
- (expr', _counts) = initSmpl dflags us (simplExprGently env expr)
+ ; let (expr', _counts) = initSmpl dflags us $
+ simplExprGently gentleSimplEnv expr
; dumpIfSet_dyn dflags Opt_D_dump_simpl "Simplified expression"
(pprCoreExpr expr')
; return expr'
}
+gentleSimplEnv :: SimplEnv
+gentleSimplEnv = mkSimplEnv SimplGently
+ (isAmongSimpl [])
+ emptyRuleBase
+
doCorePasses :: HscEnv
-> UniqSupply -- uniques
-> SimplCount -- simplifier stats
-- (b) Rules are now just orphan rules
prepareRules hsc_env@(HscEnv { hsc_dflags = dflags, hsc_HPT = hpt })
- guts@(ModGuts { mg_binds = binds, mg_rules = local_rules, mg_module = this_mod })
+ guts@(ModGuts { mg_binds = binds, mg_deps = deps, mg_rules = local_rules })
us
= do { eps <- hscEPS hsc_env
; let -- Simplify the local rules; boringly, we need to make an in-scope set
-- from the local binders, to avoid warnings from Simplify.simplVar
local_ids = mkInScopeSet (mkVarSet (bindersOfBinds binds))
- env = setInScopeSet (emptySimplEnv SimplGently []) local_ids
+ env = setInScopeSet gentleSimplEnv local_ids
(better_rules,_) = initSmpl dflags us (mapSmpl (simplRule env) local_rules)
+ home_pkg_rules = hptRules hsc_env (dep_mods deps)
- (rules_for_locals, orphan_rules) = partition is_local_rule better_rules
- is_local_rule (id,_) = idIsFrom this_mod id
+ (orphan_rules, rules_for_locals) = partition isOrphanRule better_rules
-- Get the rules for locally-defined Ids out of the RuleBase
-- If we miss any rules for Ids defined here, then we end up
-- giving the local decl a new Unique (because the in-scope-set is (hackily) the
-- Example: class Foo a where
-- op :: a -> a
-- {-# RULES "op" op x = x #-}
- --
- -- NB we can't use isLocalId, because isLocalId isn't true of class methods.
-- NB: we assume that the imported rules dont include
-- rules for Ids in this module; if there is, the above bad things may happen
pkg_rule_base = eps_rule_base eps
- hpt_rule_base = foldl add_rules pkg_rule_base (moduleEnvElts hpt)
+ hpt_rule_base = extendRuleBaseList pkg_rule_base home_pkg_rules
imp_rule_base = extendRuleBaseList hpt_rule_base orphan_rules
-- Update the binders in the local bindings with the lcoal rules
text "Imported rules", pprRuleBase imp_rule_base])
#ifdef DEBUG
- ; let bad_rules = filter (idIsFrom this_mod) (varSetElems (ruleBaseIds imp_rule_base))
+ ; let bad_rules = filter (idIsFrom (mg_module guts))
+ (varSetElems (ruleBaseIds imp_rule_base))
; WARN( not (null bad_rules), ppr bad_rules ) return ()
#endif
; return (imp_rule_base, guts { mg_binds = binds_w_rules, mg_rules = orphan_rules })
}
- where
- add_rules rule_base mod_info = extendRuleBaseList rule_base (md_rules (hm_details mod_info))
updateBinders :: RuleBase -> [CoreBind] -> [CoreBind]
updateBinders rule_base binds
This doesn't match unless you do eta reduction on the build argument.
\begin{code}
-simplRule env rule@(id, BuiltinRule _ _)
+simplRule env rule@(IdCoreRule id _ (BuiltinRule _ _))
= returnSmpl rule
-simplRule env rule@(id, Rule act name bndrs args rhs)
+simplRule env (IdCoreRule id is_orph (Rule act name bndrs args rhs))
= simplBinders env bndrs `thenSmpl` \ (env, bndrs') ->
mapSmpl (simplExprGently env) args `thenSmpl` \ args' ->
simplExprGently env rhs `thenSmpl` \ rhs' ->
- returnSmpl (id, Rule act name bndrs' args' rhs')
+ returnSmpl (IdCoreRule id is_orph (Rule act name bndrs' args' rhs'))
-- It's important that simplExprGently does eta reduction.
-- For example, in a rule like:
SimplGently -> "gentle"
SimplPhase n -> show n
- simpl_env = emptySimplEnv mode switches
- sw_chkr = getSwitchChecker simpl_env
+ sw_chkr = isAmongSimpl switches
max_iterations = intSwitchSet sw_chkr MaxSimplifierIterations `orElse` 2
do_iteration us rule_base iteration_no counts guts
-- miss the rules for Ids hidden inside imported inlinings
new_rules <- loadImportedRules hsc_env guts ;
let { rule_base' = extendRuleBaseList rule_base new_rules
- ; in_scope = mkInScopeSet (ruleBaseIds rule_base')
- ; simpl_env' = setInScopeSet simpl_env in_scope } ;
+ ; simpl_env = mkSimplEnv mode sw_chkr rule_base' } ;
-- The new rule base Ids are used to initialise
-- the in-scope set. That way, the simplifier will change any
-- occurrences of the imported id to the one in the imported_rule_ids
-- case t of {(_,counts') -> if counts'=0 then ... }
-- So the conditional didn't force counts', because the
-- selection got duplicated. Sigh!
- case initSmpl dflags us1 (simplTopBinds simpl_env' tagged_binds) of {
+ case initSmpl dflags us1 (_scc_ "SimplTopBinds" simplTopBinds simpl_env tagged_binds) of {
(binds', counts') -> do {
let { guts' = guts { mg_binds = binds' }