diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2020-10-06 15:46:16 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-10-17 22:02:13 -0400 |
commit | 6b3eb06af41b7385737fb3a602acdb95a76d2eba (patch) | |
tree | 2ad6799eb937e2e7e3adb2bf6507ead9df17f1b3 /testsuite/tests | |
parent | 7eb46a09e2188e64d226b75361b36ab732b5b372 (diff) | |
download | haskell-6b3eb06af41b7385737fb3a602acdb95a76d2eba.tar.gz |
Arity: Record arity types for non-recursive lets
In #18793, we saw a compelling example which requires us to look at
non-recursive let-bindings during arity analysis and unleash their arity
types at use sites.
After the refactoring in the previous patch, the needed change is quite
simple and very local to `arityType`'s defn for non-recurisve `Let`.
Apart from that, we had to get rid of the second item of
`Note [Dealing with bottoms]`, which was entirely a safety measure and
hindered optimistic fixed-point iteration.
Fixes #18793.
The following metric increases are all caused by this commit and a
result of the fact that we just do more work now:
Metric Increase:
T3294
T12545
T12707
Diffstat (limited to 'testsuite/tests')
4 files changed, 108 insertions, 1 deletions
diff --git a/testsuite/tests/arityanal/should_compile/T18793.hs b/testsuite/tests/arityanal/should_compile/T18793.hs new file mode 100644 index 0000000000..6dfdcf05ee --- /dev/null +++ b/testsuite/tests/arityanal/should_compile/T18793.hs @@ -0,0 +1,12 @@ +module T18793 where + +stuff :: Int -> [Int] +{-# NOINLINE stuff #-} +stuff i = [i,i+1,i+2] + +f :: Int -> Int +f = foldr k id (stuff 1) + where + k :: Int -> (Int -> Int) -> (Int -> Int) + k i acc | i > 42 = acc . negate + | otherwise = acc diff --git a/testsuite/tests/arityanal/should_compile/T18793.stderr b/testsuite/tests/arityanal/should_compile/T18793.stderr new file mode 100644 index 0000000000..72fc5e4e19 --- /dev/null +++ b/testsuite/tests/arityanal/should_compile/T18793.stderr @@ -0,0 +1,94 @@ + +==================== Tidy Core ==================== +Result size of Tidy Core = {terms: 95, types: 79, coercions: 0, joins: 0/0} + +-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} +T18793.$trModule4 :: GHC.Prim.Addr# +[GblId, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 20 0}] +T18793.$trModule4 = "main"# + +-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} +T18793.$trModule3 :: GHC.Types.TrName +[GblId, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] +T18793.$trModule3 = GHC.Types.TrNameS T18793.$trModule4 + +-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} +T18793.$trModule2 :: GHC.Prim.Addr# +[GblId, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 30 0}] +T18793.$trModule2 = "T18793"# + +-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} +T18793.$trModule1 :: GHC.Types.TrName +[GblId, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] +T18793.$trModule1 = GHC.Types.TrNameS T18793.$trModule2 + +-- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} +T18793.$trModule :: GHC.Types.Module +[GblId, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] +T18793.$trModule = GHC.Types.Module T18793.$trModule3 T18793.$trModule1 + +-- RHS size: {terms: 20, types: 13, coercions: 0, joins: 0/0} +T18793.$wstuff [InlPrag=NOINLINE] :: Int -> (# Int, [Int] #) +[GblId, Arity=1, Str=<L,U(U)>, Unf=OtherCon []] +T18793.$wstuff = \ (w :: Int) -> (# w, GHC.Types.: @Int (case w of { GHC.Types.I# x -> GHC.Types.I# (GHC.Prim.+# x 1#) }) (GHC.Types.: @Int (case w of { GHC.Types.I# x -> GHC.Types.I# (GHC.Prim.+# x 2#) }) (GHC.Types.[] @Int)) #) + +-- RHS size: {terms: 8, types: 11, coercions: 0, joins: 0/0} +stuff [InlPrag=NOUSERINLINE[final]] :: Int -> [Int] +[GblId, + Arity=1, + Str=<L,U(U)>, + Cpr=m2, + Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=False) + Tmpl= \ (w [Occ=Once1] :: Int) -> case T18793.$wstuff w of { (# ww1 [Occ=Once1], ww2 [Occ=Once1] #) -> GHC.Types.: @Int ww1 ww2 }}] +stuff = \ (w :: Int) -> case T18793.$wstuff w of { (# ww1, ww2 #) -> GHC.Types.: @Int ww1 ww2 } + +Rec { +-- RHS size: {terms: 23, types: 11, coercions: 0, joins: 0/0} +T18793.$wgo1 [InlPrag=NOUSERINLINE[2], Occ=LoopBreaker] :: [Int] -> GHC.Prim.Int# -> GHC.Prim.Int# +[GblId, Arity=2, Str=<S,1*U><L,U>, Unf=OtherCon []] +T18793.$wgo1 + = \ (w :: [Int]) (ww :: GHC.Prim.Int#) -> + case w of { + [] -> ww; + : y ys -> + case y of { GHC.Types.I# x -> + case GHC.Prim.># x 42# of { + __DEFAULT -> T18793.$wgo1 ys ww; + 1# -> T18793.$wgo1 ys (GHC.Prim.negateInt# ww) + } + } + } +end Rec } + +-- RHS size: {terms: 12, types: 6, coercions: 0, joins: 0/0} +T18793.f_go1 [InlPrag=NOUSERINLINE[2]] :: [Int] -> Int -> Int +[GblId, + Arity=2, + Str=<S,1*U><S,1*U(U)>, + Cpr=m1, + Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=False) + Tmpl= \ (w [Occ=Once1] :: [Int]) (w1 [Occ=Once1!] :: Int) -> case w1 of { GHC.Types.I# ww1 [Occ=Once1] -> case T18793.$wgo1 w ww1 of ww2 [Occ=Once1] { __DEFAULT -> GHC.Types.I# ww2 } }}] +T18793.f_go1 = \ (w :: [Int]) (w1 :: Int) -> case w1 of { GHC.Types.I# ww1 -> case T18793.$wgo1 w ww1 of ww2 { __DEFAULT -> GHC.Types.I# ww2 } } + +-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} +T18793.f2 :: Int +[GblId, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 10}] +T18793.f2 = GHC.Types.I# 1# + +-- RHS size: {terms: 7, types: 10, coercions: 0, joins: 0/0} +T18793.f1 :: [Int] +[GblId, Unf=Unf{Src=<vanilla>, TopLvl=True, Value=False, ConLike=False, WorkFree=False, Expandable=False, Guidance=IF_ARGS [] 40 10}] +T18793.f1 = case T18793.$wstuff T18793.f2 of { (# ww1, ww2 #) -> GHC.Types.: @Int ww1 ww2 } + +-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} +f :: Int -> Int +[GblId, + Arity=1, + Str=<S,1*U(U)>, + Cpr=m1, + Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=False) + Tmpl= \ (eta [Occ=Once1] :: Int) -> T18793.f_go1 T18793.f1 eta}] +f = T18793.f_go1 T18793.f1 + + + diff --git a/testsuite/tests/arityanal/should_compile/all.T b/testsuite/tests/arityanal/should_compile/all.T new file mode 100644 index 0000000000..ed1047ba00 --- /dev/null +++ b/testsuite/tests/arityanal/should_compile/all.T @@ -0,0 +1 @@ +test('T18793', [ only_ways(['optasm']), grep_errmsg('Arity=') ], compile, ['-ddump-simpl -dppr-cols=99999 -dsuppress-uniques']) diff --git a/testsuite/tests/stranal/should_compile/T13031.stdout b/testsuite/tests/stranal/should_compile/T13031.stdout index efdbb60fe9..c42eecb616 100644 --- a/testsuite/tests/stranal/should_compile/T13031.stdout +++ b/testsuite/tests/stranal/should_compile/T13031.stdout @@ -1,2 +1,2 @@ hello -[GblId, Arity=1, Unf=OtherCon []] +[GblId, Arity=3, Str=<L,U><L,U><L,U>b, Cpr=b, Unf=OtherCon []] |