summaryrefslogtreecommitdiff
path: root/testsuite/tests/stranal
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2020-10-07 13:56:08 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-05 14:32:51 -0400
commitcd1b016f9cec5d206a6f23a97418d900d1801175 (patch)
tree608a0a4b29bec868e1ad7163b846b84e1ba7621a /testsuite/tests/stranal
parentb4c0cc3636046b6ae1b9a39534b60779885c97d5 (diff)
downloadhaskell-cd1b016f9cec5d206a6f23a97418d900d1801175.tar.gz
CprAnal: Activate Sum CPR for local bindings
We've had Sum CPR (#5075) for top-level bindings for a couple of years now. That begs the question why we didn't also activate it for local bindings, and the reasons for that are described in `Note [CPR for sum types]`. Only that it didn't make sense! The Note said that Sum CPR would destroy let-no-escapes, but that should be a non-issue since we have syntactic join points in Core now and we don't WW for them (`Note [Don't w/w join points for CPR]`). So I simply activated CPR for all bindings of sum type, thus fixing #5075 and \#16570. NoFib approves: ``` -------------------------------------------------------------------------------- Program Allocs Instrs -------------------------------------------------------------------------------- comp_lab_zift -0.0% +0.7% fluid +1.7% +0.7% reptile +0.1% +0.1% -------------------------------------------------------------------------------- Min -0.0% -0.2% Max +1.7% +0.7% Geometric Mean +0.0% +0.0% ``` There were quite a few metric decreases on the order of 1-4%, but T6048 seems to regress significantly, by 26.1%. WW'ing for a `Just` constructor and the nested data type meant additional Simplifier iterations and a 30% increase in term sizes as well as a 200-300% in type sizes due to unboxed 9-tuples. There's not much we can do about it, I'm afraid: We're just doing much more work there. Metric Decrease: T12425 T18698a T18698b T20049 T9020 WWRec Metric Increase: T6048
Diffstat (limited to 'testsuite/tests/stranal')
-rw-r--r--testsuite/tests/stranal/sigs/T5075.hs34
-rw-r--r--testsuite/tests/stranal/sigs/T5075.stderr12
2 files changed, 36 insertions, 10 deletions
diff --git a/testsuite/tests/stranal/sigs/T5075.hs b/testsuite/tests/stranal/sigs/T5075.hs
index c35409aa67..15b1357446 100644
--- a/testsuite/tests/stranal/sigs/T5075.hs
+++ b/testsuite/tests/stranal/sigs/T5075.hs
@@ -1,11 +1,31 @@
--- | This module currently asserts that we trim CPR for local bindings
--- returning a sum. We can hopefully give @loop@ a CPR signature some day, but
--- we first have to fix #5075/#16570.
+-- | This module currently asserts that we give functions that always return
+-- the same constructor of a sum type the CPR property.
module T5075 where
-- Omission of the type signature is deliberate, otherwise we won't get a join
-- point (this is up to the desugarer, not sure why).
--- loop :: (Ord a, Num a) => a -> Either a b
-loop x = case x < 10 of
- True -> Left x
- False -> loop (x*2)
+-- f :: (Ord a, Num a) => a -> Either a b
+f x = case x < 10 of
+ True -> Left x
+ False -> f (x*2)
+
+-- Similarly a join point. Should WW nonetheless
+g :: Int -> Int -> Maybe Int
+g x y = go x
+ where
+ go x = case x < y of
+ True -> Just x
+ False -> go (x*2)
+
+-- Here, go is not a join point, but still should be WW'd for Just.
+-- Unfortunately, CPR can't see that (+?) returns Just, so h won't get the CPR
+-- property. It probably could by only considering the @Just@ case of the
+-- inlined (+?).
+h :: Int -> Maybe Int
+h x = go x +? go (x+1)
+ where
+ Just x +? Just y = Just (x + y)
+ _ +? _ = Nothing
+ go z
+ | z > 10 = Just (x + z)
+ | otherwise = go (z*2)
diff --git a/testsuite/tests/stranal/sigs/T5075.stderr b/testsuite/tests/stranal/sigs/T5075.stderr
index e17d5e7c5c..c9625db721 100644
--- a/testsuite/tests/stranal/sigs/T5075.stderr
+++ b/testsuite/tests/stranal/sigs/T5075.stderr
@@ -1,18 +1,24 @@
==================== Strictness signatures ====================
T5075.$trModule:
-T5075.loop: <SP(A,A,SCS(C1(L)),A,A,A,A,A)><LP(A,A,LCL(C1(L)),A,A,A,L)><L>
+T5075.f: <SP(A,A,SCS(C1(L)),A,A,A,A,A)><LP(A,A,LCL(C1(L)),A,A,A,L)><L>
+T5075.g: <1P(L)><SP(L)>
+T5075.h: <SP(L)>
==================== Cpr signatures ====================
T5075.$trModule:
-T5075.loop:
+T5075.f: 1
+T5075.g: 2(1)
+T5075.h:
==================== Strictness signatures ====================
T5075.$trModule:
-T5075.loop: <1P(A,A,SCS(C1(L)),A,A,A,A,A)><LP(A,A,LCL(C1(L)),A,A,A,L)><L>
+T5075.f: <1P(A,A,SCS(C1(L)),A,A,A,A,A)><LP(A,A,LCL(C1(L)),A,A,A,L)><L>
+T5075.g: <1P(L)><SP(L)>
+T5075.h: <1P(L)>