[commit: ghc] wip/nested-cpr: Loop breakers are not allowed to have a Converges DmdResult (aca5a26)
git at git.haskell.org
git at git.haskell.org
Thu Nov 28 15:52:40 UTC 2013
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/nested-cpr
Link : http://ghc.haskell.org/trac/ghc/changeset/aca5a26de71b10db88ea329725806f9c79a1589f/ghc
>---------------------------------------------------------------
commit aca5a26de71b10db88ea329725806f9c79a1589f
Author: Joachim Breitner <mail at joachim-breitner.de>
Date: Tue Nov 26 10:18:35 2013 +0000
Loop breakers are not allowed to have a Converges DmdResult
>---------------------------------------------------------------
aca5a26de71b10db88ea329725806f9c79a1589f
compiler/basicTypes/Demand.lhs | 18 +++++++++++-------
compiler/stranal/DmdAnal.lhs | 5 ++++-
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/compiler/basicTypes/Demand.lhs b/compiler/basicTypes/Demand.lhs
index 3851da9..be6058d 100644
--- a/compiler/basicTypes/Demand.lhs
+++ b/compiler/basicTypes/Demand.lhs
@@ -30,6 +30,7 @@ module Demand (
trimCPRInfo, returnsCPR, returnsCPR_maybe,
StrictSig(..), mkStrictSig, topSig, botSig, cprProdSig,
isTopSig, splitStrictSig, increaseStrictSigArity,
+ sigMayConverge,
seqDemand, seqDemandList, seqDmdType, seqStrictSig,
@@ -812,15 +813,11 @@ botRes = Diverges
maxCPRDepth :: Int
maxCPRDepth = 3
--- With nested CPR, DmdResult can be arbitrarily deep; consider
--- data Rec1 = Foo Rec2 Rec2
--- data Rec2 = Bar Rec1 Rec1
---
--- x = Foo y y
--- y = Bar x x
+-- With nested CPR, DmdResult can be arbitrarily deep; consider e.g. the
+-- DmdResult of repeat
--
-- So we need to forget information at a certain depth. We do that at all points
--- where we are constructing new RetCon constructors.
+-- where we are building RetCon constructors.
cutDmdResult :: Int -> DmdResult -> DmdResult
cutDmdResult 0 _ = topRes
cutDmdResult _ Diverges = Diverges
@@ -831,6 +828,10 @@ cutCPRResult :: Int -> CPRResult -> CPRResult
cutCPRResult _ NoCPR = NoCPR
cutCPRResult n (RetCon tag rs) = RetCon tag (map (cutDmdResult (n-1)) rs)
+-- Forget that something might converge for sure
+divergeDmdResult :: DmdResult -> DmdResult
+divergeDmdResult r = r `lubDmdResult` botRes
+
cprConRes :: ConTag -> [DmdType] -> CPRResult
cprConRes tag arg_tys
| opt_CprOff = NoCPR
@@ -1345,6 +1346,9 @@ botSig = StrictSig botDmdType
cprProdSig :: Arity -> StrictSig
cprProdSig arity = StrictSig (cprProdDmdType arity)
+sigMayConverge :: StrictSig -> StrictSig
+sigMayConverge (StrictSig (DmdType env ds res)) = (StrictSig (DmdType env ds (divergeDmdResult res)))
+
argsOneShots :: StrictSig -> Arity -> [[Bool]]
argsOneShots (StrictSig (DmdType _ arg_ds _)) n_val_args
| arg_ds `lengthExceeds` n_val_args
diff --git a/compiler/stranal/DmdAnal.lhs b/compiler/stranal/DmdAnal.lhs
index a9b2071..59018ac 100644
--- a/compiler/stranal/DmdAnal.lhs
+++ b/compiler/stranal/DmdAnal.lhs
@@ -1094,7 +1094,10 @@ updSigEnv env sigs = env { ae_sigs = sigs }
extendAnalEnv :: TopLevelFlag -> AnalEnv -> Id -> StrictSig -> AnalEnv
extendAnalEnv top_lvl env var sig
- = env { ae_sigs = extendSigEnv top_lvl (ae_sigs env) var sig }
+ = env { ae_sigs = extendSigEnv top_lvl (ae_sigs env) var sig' }
+ where
+ sig' | isWeakLoopBreaker (idOccInfo var) = sigMayConverge sig
+ | otherwise = sig
extendSigEnv :: TopLevelFlag -> SigEnv -> Id -> StrictSig -> SigEnv
extendSigEnv top_lvl sigs var sig = extendVarEnv sigs var (sig, top_lvl)
More information about the ghc-commits
mailing list