summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2021-05-14 12:24:48 +0200
committerZubin Duggal <zubin.duggal@gmail.com>2021-09-21 22:28:27 +0530
commit6b64aa7c48d607052e79e3927a4f896b33803086 (patch)
tree0056242bc57efa5498a01ad16f8734d9f83b4066
parent55407bf2a451d73e9648a0a5c1b0e4dd7b14e9db (diff)
downloadhaskell-6b64aa7c48d607052e79e3927a4f896b33803086.tar.gz
CPR: Detect constructed products in `runRW#` apps (#19822)
In #19822, we realised that the Simplifier's new habit of floating cases into `runRW#` continuations inhibits CPR analysis from giving key functions of `text` the CPR property, such as `singleton`. This patch fixes that by anticipating part of !5667 (Nested CPR) to give `runRW#` the proper CPR transformer it now deserves: Namely, `runRW# (\s -> e)` should have the CPR property iff `e` has it. The details are in `Note [Simplification of runRW#]` in GHC.CoreToStg.Prep. The output of T18086 changed a bit: `panic` (which calls `runRW#`) now has `botCpr`. As outlined in Note [Bottom CPR iff Dead-Ending Divergence], that's OK. Fixes #19822. Metric Decrease: T9872d (cherry picked from commit e87b8e108303634af8a7247037d50ab10456c189)
-rw-r--r--compiler/GHC/Core/Opt/CprAnal.hs7
-rw-r--r--testsuite/tests/cpranal/sigs/T19822.stderr2
2 files changed, 6 insertions, 3 deletions
diff --git a/compiler/GHC/Core/Opt/CprAnal.hs b/compiler/GHC/Core/Opt/CprAnal.hs
index a9902634c2..cdaf4014bb 100644
--- a/compiler/GHC/Core/Opt/CprAnal.hs
+++ b/compiler/GHC/Core/Opt/CprAnal.hs
@@ -239,9 +239,12 @@ cprTransform env id args
sig
where
sig
- -- Top-level binding, local let-binding or case binder
+ -- Top-level binding, local let-binding, lambda arg or case binder
| Just sig <- lookupSigEnv env id
- = getCprSig sig
+ = applyCprTy (getCprSig sig) (length args)
+ -- CPR transformers for special Ids
+ | Just cpr_ty <- cprTransformSpecial id args
+ = cpr_ty
-- See Note [CPR for data structures]
| Just rhs <- cprDataStructureUnfolding_maybe id
= fst $ cprAnal env rhs
diff --git a/testsuite/tests/cpranal/sigs/T19822.stderr b/testsuite/tests/cpranal/sigs/T19822.stderr
index 5f1522fd00..8e4636d322 100644
--- a/testsuite/tests/cpranal/sigs/T19822.stderr
+++ b/testsuite/tests/cpranal/sigs/T19822.stderr
@@ -1,5 +1,5 @@
==================== Cpr signatures ====================
-T19822.singleton: m1
+T19822.singleton: 1