summaryrefslogtreecommitdiff
path: root/compiler/specialise
diff options
context:
space:
mode:
authorklebinger.andreas@gmx.at <klebinger.andreas@gmx.at>2018-08-21 12:10:38 -0400
committerBen Gamari <ben@smart-cactus.org>2018-08-21 18:52:42 -0400
commit09c1d5afba655a2427a448a9933bebe7d13b696b (patch)
treed23083a9e99afe785f632e89f0186af8b191aee2 /compiler/specialise
parent02518f9d99c2d038384263f9e039efcb09bc96ff (diff)
downloadhaskell-09c1d5afba655a2427a448a9933bebe7d13b696b.tar.gz
Replace most occurences of foldl with foldl'.
This patch adds foldl' to GhcPrelude and changes must occurences of foldl to foldl'. This leads to better performance especially for quick builds where GHC does not perform strictness analysis. It does change strictness behaviour when we use foldl' to turn a argument list into function applications. But this is only a drawback if code looks ONLY at the last argument but not at the first. And as the benchmarks show leads to fewer allocations in practice at O2. Compiler performance for Nofib: O2 Allocations: -1 s.d. ----- -0.0% +1 s.d. ----- -0.0% Average ----- -0.0% O2 Compile Time: -1 s.d. ----- -2.8% +1 s.d. ----- +1.3% Average ----- -0.8% O0 Allocations: -1 s.d. ----- -0.2% +1 s.d. ----- -0.1% Average ----- -0.2% Test Plan: ci Reviewers: goldfire, bgamari, simonmar, tdammers, monoidal Reviewed By: bgamari, monoidal Subscribers: tdammers, rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4929
Diffstat (limited to 'compiler/specialise')
-rw-r--r--compiler/specialise/Rules.hs4
-rw-r--r--compiler/specialise/Specialise.hs2
2 files changed, 3 insertions, 3 deletions
diff --git a/compiler/specialise/Rules.hs b/compiler/specialise/Rules.hs
index 3380d02f99..4a4abf768b 100644
--- a/compiler/specialise/Rules.hs
+++ b/compiler/specialise/Rules.hs
@@ -350,7 +350,7 @@ mkRuleBase rules = extendRuleBaseList emptyRuleBase rules
extendRuleBaseList :: RuleBase -> [CoreRule] -> RuleBase
extendRuleBaseList rule_base new_guys
- = foldl extendRuleBase rule_base new_guys
+ = foldl' extendRuleBase rule_base new_guys
unionRuleBase :: RuleBase -> RuleBase -> RuleBase
unionRuleBase rb1 rb2 = plusNameEnv_C (++) rb1 rb2
@@ -907,7 +907,7 @@ match_alts renv subst ((c1,vs1,r1):alts1) ((c2,vs2,r2):alts2)
= do { subst1 <- match renv' subst r1 r2
; match_alts renv subst1 alts1 alts2 }
where
- renv' = foldl mb renv (vs1 `zip` vs2)
+ renv' = foldl' mb renv (vs1 `zip` vs2)
mb renv (v1,v2) = rnMatchBndr2 renv subst v1 v2
match_alts _ _ _ _
diff --git a/compiler/specialise/Specialise.hs b/compiler/specialise/Specialise.hs
index 13a7cb7474..6f775dfdcb 100644
--- a/compiler/specialise/Specialise.hs
+++ b/compiler/specialise/Specialise.hs
@@ -2096,7 +2096,7 @@ mkDB bind = (bind, bind_fvs bind)
-- | Identify the free variables of a 'CoreBind'
bind_fvs :: CoreBind -> VarSet
bind_fvs (NonRec bndr rhs) = pair_fvs (bndr,rhs)
-bind_fvs (Rec prs) = foldl delVarSet rhs_fvs bndrs
+bind_fvs (Rec prs) = foldl' delVarSet rhs_fvs bndrs
where
bndrs = map fst prs
rhs_fvs = unionVarSets (map pair_fvs prs)