diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2022-06-07 11:31:22 +0200 |
---|---|---|
committer | Sebastian Graf <sebastian.graf@kit.edu> | 2022-06-20 09:43:32 +0200 |
commit | 49fb2f9b16ca987648d2ac57eecf1892d49852ec (patch) | |
tree | 5bad0a2814b084d1811ca89ce0e6d70ae837dcbf /testsuite | |
parent | b570da84b7aad5ca3f90f2d1c1a690c927e99fe9 (diff) | |
download | haskell-49fb2f9b16ca987648d2ac57eecf1892d49852ec.tar.gz |
Simplify: Take care with eta reduction in recursive RHSs (#21652)
Similar to the fix to #20836 in CorePrep, we now track the set of enclosing
recursive binders in the SimplEnv and SimpleOptEnv.
See Note [Eta reduction in recursive RHSs] for details.
I also updated Note [Arity robustness] with the insights Simon and I had in a
call discussing the issue.
Fixes #21652.
Unfortunately, we get a 5% ghc/alloc regression in T16577. That is due to
additional eta reduction in GHC.Read.choose1 and the resulting ANF-isation
of a large list literal at the top-level that didn't happen before (presumably
because it was too interesting to float to the top-level). There's not much we
can do about that.
Metric Increase:
T16577
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/arityanal/should_compile/Arity03.stderr | 7 | ||||
-rw-r--r-- | testsuite/tests/arityanal/should_run/Makefile | 3 | ||||
-rw-r--r-- | testsuite/tests/arityanal/should_run/T21652.hs | 10 | ||||
-rw-r--r-- | testsuite/tests/arityanal/should_run/T21652.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/arityanal/should_run/all.T | 2 | ||||
-rw-r--r-- | testsuite/tests/deSugar/should_compile/T19969.stderr | 14 |
6 files changed, 24 insertions, 13 deletions
diff --git a/testsuite/tests/arityanal/should_compile/Arity03.stderr b/testsuite/tests/arityanal/should_compile/Arity03.stderr index f41fc1552c..652fcde173 100644 --- a/testsuite/tests/arityanal/should_compile/Arity03.stderr +++ b/testsuite/tests/arityanal/should_compile/Arity03.stderr @@ -26,12 +26,7 @@ fac = \ (x :: Int) -> case x of { GHC.Types.I# ww -> case F3.$wfac ww of ww1 { _ -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} f3 :: Int -> Int -[GblId, - Arity=1, - Str=<1!P(1L)>, - Cpr=1, - Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=True) - Tmpl= fac}] +[GblId, Arity=1, Str=<1!P(1L)>, Cpr=1, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=True)}] f3 = fac diff --git a/testsuite/tests/arityanal/should_run/Makefile b/testsuite/tests/arityanal/should_run/Makefile new file mode 100644 index 0000000000..9101fbd40a --- /dev/null +++ b/testsuite/tests/arityanal/should_run/Makefile @@ -0,0 +1,3 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk diff --git a/testsuite/tests/arityanal/should_run/T21652.hs b/testsuite/tests/arityanal/should_run/T21652.hs new file mode 100644 index 0000000000..16fda0aeaa --- /dev/null +++ b/testsuite/tests/arityanal/should_run/T21652.hs @@ -0,0 +1,10 @@ +import GHC.Exts + +f, g :: a -> a +f = g +g x = f x +{-# NOINLINE f #-} +{-# NOINLINE g #-} + +-- should print done, not <<loop>> +main = lazy g `seq` putStrLn "done" diff --git a/testsuite/tests/arityanal/should_run/T21652.stdout b/testsuite/tests/arityanal/should_run/T21652.stdout new file mode 100644 index 0000000000..19f86f493a --- /dev/null +++ b/testsuite/tests/arityanal/should_run/T21652.stdout @@ -0,0 +1 @@ +done diff --git a/testsuite/tests/arityanal/should_run/all.T b/testsuite/tests/arityanal/should_run/all.T new file mode 100644 index 0000000000..a6b06fbb15 --- /dev/null +++ b/testsuite/tests/arityanal/should_run/all.T @@ -0,0 +1,2 @@ +# Regression tests +test('T21652', [ only_ways(['optasm']) ], compile_and_run, ['']) diff --git a/testsuite/tests/deSugar/should_compile/T19969.stderr b/testsuite/tests/deSugar/should_compile/T19969.stderr index 5e23785472..3ded6f27a4 100644 --- a/testsuite/tests/deSugar/should_compile/T19969.stderr +++ b/testsuite/tests/deSugar/should_compile/T19969.stderr @@ -1,7 +1,7 @@ ==================== Tidy Core ==================== Result size of Tidy Core - = {terms: 12, types: 18, coercions: 0, joins: 0/0} + = {terms: 8, types: 14, coercions: 0, joins: 0/0} Rec { -- RHS size: {terms: 3, types: 2, coercions: 0, joins: 0/0} @@ -10,7 +10,7 @@ f [Occ=LoopBreaker] :: [Int] -> [Int] f = \ (x :: [Int]) -> f x end Rec } --- RHS size: {terms: 3, types: 2, coercions: 0, joins: 0/0} +-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} g [InlPrag=INLINE (sat-args=1)] :: [Int] -> [Int] [GblId, Arity=1, @@ -19,10 +19,10 @@ g [InlPrag=INLINE (sat-args=1)] :: [Int] -> [Int] Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=1,unsat_ok=False,boring_ok=True) - Tmpl= \ (x [Occ=Once1] :: [Int]) -> f x}] -g = \ (x :: [Int]) -> f x + Tmpl= f}] +g = f --- RHS size: {terms: 3, types: 2, coercions: 0, joins: 0/0} +-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} h [InlPrag=INLINE (sat-args=1)] :: [Int] -> [Int] [GblId, Arity=1, @@ -31,8 +31,8 @@ h [InlPrag=INLINE (sat-args=1)] :: [Int] -> [Int] Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=1,unsat_ok=False,boring_ok=True) - Tmpl= \ (x [Occ=Once1] :: [Int]) -> f x}] -h = \ (x :: [Int]) -> f x + Tmpl= f}] +h = f |